⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guidev.c

📁 ucgui在ARM44B0目标板上的移植代码支持16级灰度
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************************                                                uC/GUI*                        Universal graphic software for embedded applications**                       (c) Copyright 2002, Micrium Inc., Weston, FL*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH**              礐/GUI is protected by international copyright laws. Knowledge of the*              source code may not be used to write a similar product. This file may*              only be used in accordance with a license and should not be redistributed*              in any way. We appreciate your understanding and fairness.*----------------------------------------------------------------------File        : GUIDev.CPurpose     : Implementation of memory devices---------------------------END-OF-HEADER------------------------------*/#include <string.h>#include "GUI_Private.H"#include "GUIDebug.h"/* Memory device capabilities are compiled only if support for them is enabled.*/ #if GUI_SUPPORT_MEMDEV/*        *********************************************************        *                                                       *        *                Macros                                 *        *                                                       *        **********************************************************/#define POS_AUTO -4095   /* Position value for auto-pos *//*  ********************************************************************  *  *                  ID translation table  *  ********************************************************************This table contains 0, 1, 2, ... and serves as translation table for DDBs*/#define INTS(Base)  Base+0,Base+1,Base+2,Base+3,Base+4,Base+5,   \                    Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \                    Base+12,Base+13,Base+14,Base+15static const LCD_PIXELINDEX aID[] = {  INTS(0)};/*        *********************************************************        *                                                       *        *           internal routines                           *        *                                                       *				*     (not part of interface table)                     *        *                                                       *        **********************************************************/LCD_PIXELINDEX* GUI_MEMDEV_XY2PTR(int x,int y) {  GUI_MEMDEV* pDev = GUI_MEMDEV_h2p(GUI_Context.hDevData);  U8 *pData = (U8*)(pDev+1);  #if GUI_DEBUG_LEVEL >= GUI_DEBUG_LEVEL_CHECK_ALL    if ((x >= pDev->x0+pDev->XSize) | (x<pDev->x0) | (y >= pDev->y0+pDev->YSize) | (y<pDev->y0)) {      GUI_DEBUG_ERROROUT2("GUI_MEMDEV_XY2PTR: parameters out of bounds",x,y);    }  #endif  pData += (y- pDev->y0) * pDev->BytesPerLine;  return ((LCD_PIXELINDEX*)pData) + x - pDev->x0;}/*        *********************************************************        *                                                       *        *          Draw Bitmap 1 BPP                            *        *                                                       *        **********************************************************/static void  DrawBitLine1BPP(GUI_USAGE* pUsage, int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {  LCD_PIXELINDEX pixels;  LCD_PIXELINDEX Index0 = *(pTrans+0);  LCD_PIXELINDEX Index1 = *(pTrans+1);  LCD_PIXELINDEX* pData;  U8  PixelCnt;  GUI_MEMDEV* pDev = GUI_MEMDEV_h2p(GUI_Context.hDevData);  PixelCnt = 8- (Diff&7);  pixels = (*p) << (Diff&7);  pData = GUI_MEMDEV_XY2PTR(x,y);  GUI_DEBUG_ERROROUT3_IF( x < pDev->x0, "GUIDEV.c: DrawBitLine1BPP, Act= %d, Border= %d, Clip= %d"                    ,x,pDev->x0, GUI_Context.ClipRect.x0);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {  case 0:    /* Write mode */  PixelLoopWrite:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      *pData++ = (pixels&0x80) ? Index1 : Index0;      pixels<<=1;    } while (--PixelCnt);    if (xsize) {      PixelCnt=8;      pixels = *(++p);      goto PixelLoopWrite;    }    break;  case LCD_DRAWMODE_TRANS:  PixelLoopTrans:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      if ((pixels&0x80)) {        if (pUsage)          GUI_USAGE_AddPixel(pUsage, x,y);        *pData = Index1;      }      x++;      pData++;      pixels<<=1;    } while (--PixelCnt);    if (xsize) {      PixelCnt=8;      pixels = *(++p);      goto PixelLoopTrans;    }    break;  case LCD_DRAWMODE_XOR:;  PixelLoopXor:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      if ((pixels&0x80))        *pData = pDev->NumColors - 1 - *pData;      pData++;      pixels<<=1;    } while (--PixelCnt);    if (xsize) {      PixelCnt=8;      pixels = *(++p);      goto PixelLoopXor;    }    break;  }}/*        *********************************************************        *                                                       *        *          Draw Bitmap 2 BPP                            *        *                                                       *        **********************************************************/static void  DrawBitLine2BPP(GUI_USAGE* pUsage, int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {  U8 pixels;  U8  PixelCnt;  LCD_PIXELINDEX* pData;  PixelCnt = 4- (Diff&3);  pixels = (*p) << ((Diff&3)<<1);  pData = GUI_MEMDEV_XY2PTR(x,y);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {  case 0:    /* Write mode */  PixelLoopWrite:    if (PixelCnt>xsize) {      PixelCnt =xsize;    }    xsize -= PixelCnt;    do {      *pData++ = *(pTrans + (pixels>>6));      pixels<<=2;    } while (--PixelCnt);    if (xsize) {      PixelCnt=4;      pixels = *(++p);      goto PixelLoopWrite;    }    break;  case LCD_DRAWMODE_TRANS:  PixelLoopTrans:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      if (pixels&0xc0) {        *pData = *(pTrans + (pixels>>6));        GUI_USAGE_AddPixel(pUsage, x,y);      }      pData++;      pixels<<=2;    } while (--PixelCnt);    if (xsize) {      PixelCnt=4;      pixels = *(++p);      goto PixelLoopTrans;    }    break;  case LCD_DRAWMODE_XOR:;  PixelLoopXor:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      if ((pixels&0xc0))        *pData ^= 255;      pData++;      pixels<<=2;    } while (--PixelCnt);    if (xsize) {      PixelCnt=4;      pixels = *(++p);      goto PixelLoopXor;    }    break;  }}/*        *********************************************************        *                                                       *        *          Draw Bitmap 4 BPP                            *        *                                                       *        **********************************************************/static void  DrawBitLine4BPP(GUI_USAGE* pUsage, int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {  U8 pixels;  LCD_PIXELINDEX* pData;  U8  PixelCnt;  PixelCnt = 2- (Diff&1);  pixels = (*p) << ((Diff&1)<<2);  pData = GUI_MEMDEV_XY2PTR(x,y);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {/*          * Write mode **/  case 0:    /* Draw incomplete bytes to the left of center area */    if (Diff) {      *pData = *(pTrans + (pixels >>4));      pData++;      xsize--;      pixels = *++p;    }    /* Draw center area (2 pixels in one byte) */    if (xsize >= 2) {      int i = xsize>>1;      xsize &= 1;      do {        *pData     = *(pTrans + (pixels>>4));   /* Draw 1. (left) pixel */        *(pData+1) = *(pTrans + (pixels&15));   /* Draw 2. (right) pixel */        pData +=2;        pixels = *++p;      } while (--i);    }    /* Draw incomplete bytes to the right of center area */    if (xsize) {      *pData = * (pTrans + (pixels >> 4));    }    break;/*          * Transparent draw mode **/  case LCD_DRAWMODE_TRANS:    /* Draw incomplete bytes to the left of center area */    if (Diff) {      if (pixels&0xF0) {        *pData = *(pTrans + (pixels>>4));        if (pUsage)          GUI_USAGE_AddPixel(pUsage, x,y);      }      pData++;      x++;      xsize--;      pixels = *++p;    }    /* Draw center area (2 pixels in one byte) */    while (xsize >= 2) {      /* Draw 1. (left) pixel */      if (pixels&0xF0) {        *pData = *(pTrans + (pixels>>4));        if (pUsage)          GUI_USAGE_AddPixel(pUsage, x,y);      }      /* Draw 2. (right) pixel */      if (pixels &= 15) {        *(pData+1) = *(pTrans + pixels);        if (pUsage)          GUI_USAGE_AddPixel(pUsage, x+1,y);      }      pData +=2;      x+=2;      xsize-=2;      pixels = *++p;    }    /* Draw incomplete bytes to the right of center area */    if (xsize) {      if (pixels >>= 4) {        *pData = *(pTrans + pixels);        if (pUsage)          GUI_USAGE_AddPixel(pUsage, x,y);      }    }    break;  case LCD_DRAWMODE_XOR:;  PixelLoopXor:    if (PixelCnt>xsize)      PixelCnt =xsize;    xsize -= PixelCnt;    do {      if ((pixels&0xc0))        *pData ^= 255;      pData++;      pixels<<=4;    } while (--PixelCnt);    if (xsize) {      PixelCnt=2;      pixels = *(++p);      goto PixelLoopXor;    }    break;  }}/*        *********************************************************        *                                                       *        *          Draw Bitmap 8 BPP Trans                      *        *                                                       *        **********************************************************/static void  DrawBitLine8BPP(GUI_USAGE* pUsage, int x, int y, U8 const*pSrc, int xsize, const LCD_PIXELINDEX*pTrans) {  LCD_PIXELINDEX* pDest;  pDest = GUI_MEMDEV_XY2PTR(x,y);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {  case 0:    /* Write mode */    do {      *pDest = *(pTrans + *pSrc);      pDest++;      pSrc++;    } while (--xsize);    break;  case LCD_DRAWMODE_TRANS:    do {      if (*pSrc) {        *pDest = *(pTrans + *pSrc);        GUI_USAGE_AddPixel(pUsage, x,y);      }      x++;      pDest++;      pSrc++;    } while (--xsize);    break;  }}/*        *********************************************************        *                                                       *        *          Draw Bitmap 8 BPP No Trans                   *        *                                                       *        **********************************************************/static void  DrawBitLine8BPP_DDB(GUI_USAGE* pUsage, int x, int y, U8 const*pSrc, int xsize) {  LCD_PIXELINDEX* pDest;  pDest = GUI_MEMDEV_XY2PTR(x,y);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {  case 0:    /* Write mode */    #if LCD_BITSPERPIXEL <=8      memcpy(pDest, pSrc, xsize);    #else      *pDest = *pSrc;      while (--xsize) {        *++pDest = *++pSrc;      }    #endif    break;  case LCD_DRAWMODE_TRANS:    do {      if (*pSrc) {        *pDest = *pSrc;        GUI_USAGE_AddPixel(pUsage, x,y);      }      x++;      pDest++;      pSrc++;    } while (--xsize);    break;  }}/**********************************************************          Draw Bitmap 16 BPP DDB***********************************************************/#if LCD_BITSPERPIXEL >8static void  DrawBitLine16BPP_DDB(GUI_USAGE* pUsage, int x, int y, const U16 *pSrc, int xsize) {  LCD_PIXELINDEX* pDest;  pDest = GUI_MEMDEV_XY2PTR(x,y);  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {  case 0:    /* Write mode */    memcpy(pDest, pSrc, xsize*2);    break;  case LCD_DRAWMODE_TRANS:    do {      if (*pSrc) {        *pDest = *pSrc;        GUI_USAGE_AddPixel(pUsage, x,y);      }      x++;      pDest++;      pSrc++;    } while (--xsize);    break;  }}#endif/*        *********************************************************        *                                                       *        *         Universal draw Bitmap routine                 *        *                                                       *        **********************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -