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

📄 lcdpage1bpp.c

📁 UCOS2+UCGUI移植到KEIL C51的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        }
        pData += BytesPerLine;
        PixelMask <<= 1;
        if (!PixelMask || !ysize) {
          _VRam[Page][x] = Data;
          if (ysize) {
            PixelMask = 1;
            Data = _VRam[++Page][x];
          }
        }
      }
      break;
    case LCD_DRAWMODE_XOR:
      while(ysize--) {
        if (*pData & DataMask) {
          Data ^= PixelMask;
        }
        pData += BytesPerLine;
        PixelMask <<= 1;
        if (!PixelMask || !ysize) {
          _VRam[Page][x] = Data;
          if (ysize) {
            PixelMask = 1;
            Data = _VRam[++Page][x];
          }
        }
      }
      break;
	}
}

/*********************************************
*
*       Draw Bitmap 1 BPP (not optimized)
*
**********************************************
*/

#else

static void _DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
  LCD_PIXELINDEX Index0 = *(pTrans+0);
  LCD_PIXELINDEX Index1 = *(pTrans+1);
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      do {
        LCD_L0_SetPixelIndex(x++, y, (*p & (0x80 >> Diff)) ? Index1 : Index0);
			  if (++Diff == 8) {
          Diff = 0;
				  p++;
			  }
		  } while (--xsize);
      break;
    case LCD_DRAWMODE_TRANS:
      do {
  		  if (*p & (0x80 >> Diff))
          LCD_L0_SetPixelIndex(x, y, Index1);
        x++;
			  if (++Diff == 8) {
          Diff = 0;
				  p++;
			  }
		  } while (--xsize);
      break;
    case LCD_DRAWMODE_XOR:;
      do {
  		  if (*p & (0x80 >> Diff)) {
          int Pixel = LCD_L0_GetPixelIndex(x, y);
          LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - 1 - Pixel);
        }
        x++;
			  if (++Diff == 8) {
          Diff = 0;
				  p++;
			  }
		  } while (--xsize);
      break;
	}
}

#endif

/*********************************************
*
*       Draw Bitmap 2 BPP
*
**********************************************
*/

#if (LCD_MAX_LOG_COLORS > 2)
static void _DrawBitLine2BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels = *p;
  int CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      do {
        int Shift = (3 - CurrentPixel) << 1;
        int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
        LCD_L0_SetPixelIndex(x++, y, PixelIndex);
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
		  } while (--xsize);
      break;
    case LCD_DRAWMODE_TRANS:
      do {
        int Shift = (3 - CurrentPixel) << 1;
        int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        if (Index) {
          LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
          LCD_L0_SetPixelIndex(x, y, PixelIndex);
        }
        x++;
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
		  } while (--xsize);
      break;
  }
}
#endif

/*********************************************
*
*       Draw Bitmap 4 BPP
*
**********************************************
*/

#if (LCD_MAX_LOG_COLORS > 4)
static void _DrawBitLine4BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels = *p;
  int CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      do {
        int Shift = (1 - CurrentPixel) << 2;
        int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
        LCD_L0_SetPixelIndex(x++, y, PixelIndex);
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
		  } while (--xsize);
      break;
    case LCD_DRAWMODE_TRANS:
      do {
        int Shift = (1 - CurrentPixel) << 2;
        int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        if (Index) {
          LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
          LCD_L0_SetPixelIndex(x, y, PixelIndex);
        }
        x++;
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
		  } while (--xsize);
      break;
  }
}
#endif

/*********************************************
*
*       Draw Bitmap 8 BPP (optimized)
*
**********************************************
*/

#if (LCD_MAX_LOG_COLORS > 16)

#if LCD_OPTIMIZE \
  && !LCD_SWAP_XY \
  && !LCD_MIRROR_X \
  && !LCD_MIRROR_Y

static void _DrawBitLine8BPP(int x, int y, U8 const * pData, int ysize, const LCD_PIXELINDEX * pTrans, int BytesPerLine) {
  U8 PixelMask = 1 << (y & 7);
  int Page = y >> 3;
  U8 Data = _VRam[Page][x];
  if (!pTrans)
    pTrans = _ConversionTable;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      while(ysize--) {
        if (*(pTrans + *pData)) {
          Data |= PixelMask;
        } else {
          Data &= ~PixelMask;
        }
        pData += BytesPerLine;
        PixelMask <<= 1;
        if (!PixelMask || !ysize) {
          _VRam[Page][x] = Data;
          if (ysize) {
            PixelMask = 1;
            Data = _VRam[++Page][x];
          }
        }
      }
      break;
    case LCD_DRAWMODE_TRANS:
      while(ysize--) {
        LCD_PIXELINDEX Pixel = *pData;
        if (Pixel) {
          if (*(pTrans + Pixel)) {
            Data |= PixelMask;
          } else {
            Data &= ~PixelMask;
          }
        }
        pData += BytesPerLine;
        PixelMask <<= 1;
        if (!PixelMask || !ysize) {
          _VRam[Page][x] = Data;
          if (ysize) {
            PixelMask = 1;
            Data = _VRam[++Page][x];
          }
        }
      }
      break;
	}
}

/*********************************************
*
*       Draw Bitmap 8 BPP (not optimized)
*
**********************************************
*/

#else

static void _DrawBitLine8BPP(int x, int y, U8 const * p, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixel;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      if (pTrans) {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
        }
      } else {
        for (; xsize > 0; xsize--, x++, p++) {
          LCD_L0_SetPixelIndex(x, y, *p);
        }
      }
      break;
    case LCD_DRAWMODE_TRANS:
      if (pTrans) {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          if (Pixel) {
            LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
          }
        }
      } else {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          if (Pixel) {
            LCD_L0_SetPixelIndex(x, y, Pixel);
          }
        }
      }
      break;
  }
}
#endif

#endif

/*********************************************
*
*       Draw Bitmap 16 BPP
*
**********************************************
*/

#if (LCD_BITSPERPIXEL > 8)
static void _DrawBitLine16BPP(int x, int y, U16 const * p, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixel;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
    case 0:
      if (pTrans) {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
        }
      } else {
        for (; xsize > 0; xsize--, x++, p++) {
          LCD_L0_SetPixelIndex(x, y, *p);
        }
      }
      break;
    case LCD_DRAWMODE_TRANS:
      if (pTrans) {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          if (Pixel) {
            LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
          }
        }
      } else {
        for (; xsize > 0; xsize--, x++, p++) {
          Pixel = *p;
          if (Pixel) {
            LCD_L0_SetPixelIndex(x, y, Pixel);
          }
        }
      }
      break;
  }
}
#endif

/*********************************************************************
*
*       Exported functions
*
**********************************************************************
*/

/*********************************************
*
*       LCD_L0_SetPixelIndex
*
**********************************************
*/

void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
  /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  #if LCD_SWAP_XY | LCD_MIRROR_X | LCD_MIRROR_Y
    int xPhys = LOG2PHYS_X(x, y);
    int yPhys = LOG2PHYS_Y(x, y);
  #else
    #define xPhys x
    #define yPhys y
  #endif
  /* Write into hardware */
  {
    U8 Data = GET_BYTE(yPhys >> 3, xPhys);
    U8 AndMask = ~(1 << (yPhys & 7));
    U8 OrMask  = PixelIndex << (yPhys & 7);
    Data &= AndMask;
    Data |= OrMask;
    SET_PAGE_IF_NEEDED(yPhys >> 3);
    SET_OFFSET_IF_NEEDED(xPhys);
    WRITE_DATA1(Data);
  }
}

/*********************************************
*
*       LCD_L0_GetPixelIndex
*
**********************************************
*/

unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
    int xPhys = LOG2PHYS_X(x, y);
    int yPhys = LOG2PHYS_Y(x, y);
  #else
    #define xPhys x
    #define yPhys y
  #endif
  /* Read from hardware */
  {
    U8 Data = GET_BYTE(yPhys >> 3, xPhys);
    return (Data & (1 << (yPhys & 7))) ? 1 : 0;
  }
}

/*********************************************
*
*       LCD_L0_XorPixel
*
**********************************************
*/

void LCD_L0_XorPixel(int x, int y) {
  LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
  LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
}

/*********************************************
*
*       LCD_L0_DrawHLine (optimized)
*
**********************************************
*/

#if LCD_OPTIMIZE \
  && !LCD_SWAP_XY \
  && !LCD_MIRROR_X \
  && !LCD_MIRROR_Y

void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
  #if LCD_CACHE
    U8 Mask = 1 << (y & 7);
    int Page = y >> 3;
    U8 * pData = &_VRam[Page][x0];
    int NumberOfBytes = x1 - x0 + 1;
    SET_PAGE_IF_NEEDED(Page);
    SET_OFFSET_IF_NEEDED(x0);
    for (; x0 <= x1; x0++) {
      if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
        _VRam[Page][x0] ^= Mask;
      } else {
        if (LCD_COLORINDEX) {
          _VRam[Page][x0] |= Mask;
        } else {
          _VRam[Page][x0] &= ~Mask;
        }
      }
    }
    WRITE_DATAM(pData, NumberOfBytes);
  #else
    U8 Mask = 1 << (y & 7);
    SET_PAGE_IF_NEEDED(y >> 3);
    SET_OFFSET_IF_NEEDED(x0);
    for (; x0 <= x1; x0++) {
      U8 Data = GET_CURRENT_BYTE();
      if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
        WRITE_DATA1(Data ^ Mask);
      } else {
        WRITE_DATA1((LCD_COLORINDEX) ? Data | Mask : Data & ~Mask);
      }
    }
  #endif

⌨️ 快捷键说明

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