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

📄 lcd13xx.c

📁 在ucos上实现了图形用户接口GUI;值得一看
💻 C
📖 第 1 页 / 共 5 页
字号:

/*
	*********************************************************
	*                                                       *
	*          LCD_FillRect Optimized                       *
	*                                                       *
	*          16 bit bus, Using BITBLT                     *
	*                                                       *
	*********************************************************
*/
/*
#if (LCD_USE_BITBLT)           \
    && (!LCD_SWAP_XY)          \
    && (LCD_BUSWIDTH==16)      \
    && (!defined (LCD_LUT_COM))   \
    && (!defined (LCD_LUT_SEG))   \
    && ((LCD_CONTROLLER == 1356)||(LCD_CONTROLLER == 13806))
*/

void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  int oldcolor,i,x,y;
  LCD_PIXELINDEX Index;

  oldcolor=getcolor ();
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR){
    for (x=x0;x<=x1;x++)
	  for (y=y0;y<=y1;y++){
	Index = GetPixelIndex(x,y);
	_SetPixel(x,y,LCD_NUM_COLORS-1-Index);
	 }
  }
  else {
    setcolor (LCD_BKCOLORINDEX);
    for (i=x0;i<=x1;i++)
      line (i,y0,i,y1);
  }
  setcolor (oldcolor);
/*
  #if LCD_MIRROR_X
    #define X0 (LCD_XSIZE-1-(x1))
    #define X1 (LCD_XSIZE-1-(x0))
  #else
    #define X0 x0
    #define X1 x1
  #endif
  #if LCD_MIRROR_Y
    #define Y0 (LCD_YSIZE-1-(y1))
    #define Y1 (LCD_YSIZE-1-(y0))
  #else
    #define Y0 y0
    #define Y1 y1
  #endif
  if ((x0>x1) | (y0>y1)) return;
  LCD_FillRectBB(X0,Y0,X1,Y1);
  #undef X0
  #undef X1
  #undef Y0
  #undef Y1
*/
}

//#else








/*
	*********************************************************
	*                                                       *
	*          LCD_FillRect                                 *
	*                                                       *
	*********************************************************
*/
/*
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
#if !LCD_SWAP_XY
  for (; y0 <= y1; y0++) {
    LCD_L0_DrawHLine(x0,y0, x1);
  }
#else
  for (; x0 <= x1; x0++) {
    LCD_L0_DrawVLine(x0,y0, y1);
  }
#endif
}

#endif
*/







/********************************************************
*
*          Draw Bitmap 1 BPP Optimzed
*
*          8 bit bus, 1 bpp
*
*********************************************************
*/
#if (LCD_OPTIMIZE)             \
      && (!LCD_SWAP_XY)          \
      && (!LCD_MIRROR_Y)         \
      && (!LCD_MIRROR_X)         \
      && (LCD_BUSWIDTH==8)       \
      && (!defined (LCD_LUT_COM))   \
      && (!defined (LCD_LUT_SEG))   \
      && (LCD_BITSPERPIXEL == 1)

static void  DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
// only normal mode optimized
  if (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR))
    goto DrawBitLine1BPP_NoOpt;
  {
    LCD_PIXELINDEX Index0 = *(pTrans+0);
    LCD_PIXELINDEX Index1 = *(pTrans+1);
    x+=Diff;
  // Check if filling will do ...
    if (Index0==Index1) {
      LCD_PIXELINDEX ColorIndexOld= COLOR;  // Save forground color
      COLOR = Index0;              // Set foreground color
      LCD_L0_DrawHLine(x,y,x+xsize-1);
      COLOR = ColorIndexOld;
      return;
    }
    {
  // O.K., we have to draw ...
      tOff Off  = XY2OFF(x,y);
      int x1 = x+xsize-1;
      U8 Mask =    0xff   >> (x &7);
      U8 EndMask = 0xff80 >> (x1&7);
      U8 Data;
      U16 XorData = Index1 ? 0 : 0xffff;
      U16 PixelData;
      int NumBytes = (x1>>3) - (x>>3);
      if (NumBytes) {
  // Write first byte (Needs to be masked)
	READ_MEM(Off,Data);
	Data &= (~Mask);
	PixelData   = (*(p+1) | ((*p)<<8)) ^ XorData;
	PixelData >>= (8+(x&7)-(Diff&7));
	Data |= PixelData&Mask;
	WRITE_MEM(Off,Data);
	{ int DiffOld = Diff;
	  Diff+= 8-(x&7);
	  if ((DiffOld&~7) != (Diff&~7))
	    p++;
	}
	x=0;
	Off++; NumBytes--;
  // Write full byte
	for (; NumBytes; NumBytes--, Off++) {
	  PixelData   = (*(p+1) | ((*p)<<8))^XorData;
	  PixelData >>= (8-(Diff&7));
	  p++;
	  WRITE_MEM(Off, PixelData);
	}
	Mask = 0xff;
      }
      PixelData   = (*(p+1) | ((*p)<<8))^XorData;
      PixelData >>= (8+(x&7)-(Diff&7));
      Mask &= EndMask;
      READ_MEM(Off,Data);
      Data &= (~Mask);
      Data |= PixelData&Mask;
      WRITE_MEM(Off,Data);
    }
    return;
  }
// no optimization
DrawBitLine1BPP_NoOpt:
  {
    LCD_PIXELINDEX pixels;
    LCD_PIXELINDEX Index0 = *(pTrans+0);
    LCD_PIXELINDEX Index1 = *(pTrans+1);
  //
  // Jump to right entry point

    pixels = *p;
    switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
    case LCD_DRAWMODE_TRANS:
      switch (Diff&7) {
      case 0:
	goto WriteTBit0;
      case 1:
	goto WriteTBit1;
      case 2:
	goto WriteTBit2;
      case 3:
	goto WriteTBit3;
      case 4:
	goto WriteTBit4;
      case 5:
	goto WriteTBit5;
      case 6:
	goto WriteTBit6;
      case 7:
	goto WriteTBit7;
      }
      break;
    case LCD_DRAWMODE_XOR:
      switch (Diff&7) {
      case 0:
	goto WriteXBit0;
      case 1:
	goto WriteXBit1;
      case 2:
	goto WriteXBit2;
      case 3:
	goto WriteXBit3;
      case 4:
	goto WriteXBit4;
      case 5:
	goto WriteXBit5;
      case 6:
	goto WriteXBit6;
      case 7:
	goto WriteXBit7;
      }
    }
  //
  //        Write with transparency
  //
    WriteTBit0:
      if (pixels&(1<<7)) SETPIXEL(x+0, y, Index1);
      if (!--xsize)
	return;
    WriteTBit1:
      if (pixels&(1<<6)) SETPIXEL(x+1, y, Index1);
      if (!--xsize)
	return;
    WriteTBit2:
      if (pixels&(1<<5)) SETPIXEL(x+2, y, Index1);
      if (!--xsize)
	return;
    WriteTBit3:
      if (pixels&(1<<4)) SETPIXEL(x+3, y, Index1);
      if (!--xsize)
	return;
    WriteTBit4:
      if (pixels&(1<<3)) SETPIXEL(x+4, y, Index1);
      if (!--xsize)
	return;
    WriteTBit5:
      if (pixels&(1<<2)) SETPIXEL(x+5, y, Index1);
      if (!--xsize)
	return;
    WriteTBit6:
      if (pixels&(1<<1)) SETPIXEL(x+6, y, Index1);
      if (!--xsize)
	return;
    WriteTBit7:
      if (pixels&(1<<0)) SETPIXEL(x+7, y, Index1);
      if (!--xsize)
	return;
      x+=8;
      pixels = *(++p);
      goto WriteTBit0;
  //
  //	  Write XOR mode
  //
    WriteXBit0:
      if (pixels&(1<<7))
	XORPIXEL(x+0, y);
      if (!--xsize)
	return;
    WriteXBit1:
      if (pixels&(1<<6))
	XORPIXEL(x+1, y);
      if (!--xsize)
	return;
    WriteXBit2:
      if (pixels&(1<<5))
	XORPIXEL(x+2, y);
      if (!--xsize)
	return;
    WriteXBit3:
      if (pixels&(1<<4))
	XORPIXEL(x+3, y);
      if (!--xsize)
	return;
    WriteXBit4:
      if (pixels&(1<<3))
	XORPIXEL(x+4, y);
      if (!--xsize)
	return;
    WriteXBit5:
      if (pixels&(1<<2))
	XORPIXEL(x+5, y);
      if (!--xsize)
	return;
    WriteXBit6:
      if (pixels&(1<<1))
	XORPIXEL(x+6, y);
      if (!--xsize)
	return;
    WriteXBit7:
      if (pixels&(1<<0))
	XORPIXEL(x+7, y);
      if (!--xsize)
	return;
      x+=8;
      pixels = *(++p);
      goto WriteXBit0;
  }
}







/********************************************************
*
*          Draw Bitmap 1 BPP Optimzed
*
*          16 bit bus, 4 bpp mode, SWAP_XY
*
*********************************************************
*/
#elif (LCD_OPTIMIZE)               \
    && (LCD_SWAP_XY)             \
    && (!defined (LCD_LUT_COM))  \
    && (!defined (LCD_LUT_SEG))  \
    && (LCD_BITSPERPIXEL == 4)   \
    && (LCD_BUSWIDTH==16)

static const U8 ShiftNibble[] = {
  12, 8, 4, 0
};

static void DrawBitLine1BPP_Swap(
  int x,
  int y,
  U8 const * pData,
  int ysize,
  const U8 * pTrans,
  int BytesPerLine,
  U8 Pos)
{
  int y0 = x;
  #if LCD_MIRROR_Y || LCD_MIRROR_X
    int x0 = LCD_YSIZE - y - 1;
  #else
    int x0 = y;
  #endif
  tOff Off = XY2OFF(x0,y0);
  U16 Buffer, Data;
  U8 Index, Pixel;
  U8 BufferValid = 0;
  U8 ShiftPos = 7 - (Pos & 7);
  U16 DataMask = 0x80 >> (7 -ShiftPos);
  #if LCD_MIRROR_Y || LCD_MIRROR_X
    for (; ysize; ysize--, pData += BytesPerLine, x0--) {
  #else
    for (; ysize; ysize--, pData += BytesPerLine, x0++) {
  #endif
    U8 Shift = ShiftNibble[x0 & 3];
    Pixel = (*pData & DataMask) >> ShiftPos;
    if (!BufferValid) {
      READ_MEM(Off,Buffer);
      BufferValid = 1;
    }
    switch (GUI_Context.DrawMode) {
    case LCD_DRAWMODE_NORMAL:
    case LCD_DRAWMODE_REV:
      Buffer &= ~(0xF << Shift);
      Index = *(pTrans + Pixel);
      Data = Index << Shift;
      Buffer |= Data;
      break;
    case LCD_DRAWMODE_XOR:
      if (Pixel)
	Buffer ^= (0xF << Shift);
      break;
    case LCD_DRAWMODE_TRANS:
      if (Pixel) {
	Buffer &= ~(0xF << Shift);
	Index = *(pTrans + Pixel);
	Data = Index << Shift;
	Buffer |= Data;
      }
      break;
    }
    #if LCD_MIRROR_Y || LCD_MIRROR_X
      if (!(x0 & 3)) {
	BufferValid = 0;
	WRITE_MEM(Off--, Buffer);
      }
    #else
      if ((x0 & 3) == 3) {
	BufferValid = 0;
	WRITE_MEM(Off++, Buffer);
      }
    #endif
  }
  if (BufferValid)
    WRITE_MEM(Off, Buffer);
}

/********************************************************
*
*          Draw Bitmap 1 BPP Optimzed
*
*          16 bit bus, 8 bpp mode
*
*********************************************************
*/
#elif (LCD_OPTIMIZE)             \
      && (!LCD_SWAP_XY)          \
      && (!LCD_MIRROR_X)         \
      && (LCD_BUSWIDTH==16)       \
      && (!defined (LCD_LUT_SEG))   \
      && (LCD_BITSPERPIXEL == 8)

static void  DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
  U8 Pixels = *p;
  U8 RemPixels;
  x+= Diff;
  RemPixels = 8-Diff;
  Pixels <<= Diff;
  // Handle transparent bitmaps
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    do {
      if (RemPixels==0) {
	Pixels = *(++p);
	RemPixels =8;
      }
      if (Pixels & 0x80) {
	XORPIXEL(x, y);
      }
      RemPixels--;
      Pixels <<=1;
      x++;
    } while (--xsize);
  }
  else if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) {
    do {
      if (RemPixels==0) {
	Pixels = *(++p);
	RemPixels =8;
      }
      if (Pixels & 0x80) {
	SETPIXEL(x, y, *(pTrans+1));
      }
      RemPixels--;
      Pixels <<=1;
      x++;
    } while (--xsize);
  }
  else {
    do {
      if (RemPixels==0) {
	Pixels = *(++p);
	RemPixels =8;
      }
      if (Pixels & 0x80) {
	SETPIXEL(x, y, *(pTrans+1));
      }
      RemPixels--;
      Pixels <<=1;
      x++;
    } while (--xsize);


⌨️ 快捷键说明

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