lcdmemc.c

来自「瑞泰创新的GX-ARM9-2410EP教学实验系统UCOS移植源代码,包含GUI」· C语言 代码 · 共 1,152 行 · 第 1/3 页

C
1,152
字号

#if (!LCD_SUPPORT_COMTRANS && !LCD_SUPPORT_SEGTRANS)
  #if   (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((x), (y), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((x), (y), (c))
    #define GETPIXEL(x, y)         GetPixel            ((x), (y))
    #define XORPIXEL(x, y)         XorPixel            ((x), (y))
  #elif (!LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((y), (x), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((y), (x), (c))
    #define GETPIXEL(x, y)         GetPixel            ((y), (x))
    #define XORPIXEL(x, y)         XorPixel            ((y), (x))
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((x), (LCD_YSIZE-1-(y)), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((x), (LCD_YSIZE-1-(y)), (c))
    #define GETPIXEL(x, y)         GetPixel            ((x), (LCD_YSIZE-1-(y)))
    #define XORPIXEL(x, y)         XorPixel            ((x), (LCD_YSIZE-1-(y)))
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((LCD_YSIZE-1-(y)), (x), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((LCD_YSIZE-1-(y)), (x), (c))
    #define GETPIXEL(x, y)         GetPixel            ((LCD_YSIZE-1-(y)), (x))
    #define XORPIXEL(x, y)         XorPixel            ((LCD_YSIZE-1-(y)), (x))
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((LCD_XSIZE-1-(x)), (y), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((LCD_XSIZE-1-(x)), (y), (c))
    #define GETPIXEL(x, y)         GetPixel            ((LCD_XSIZE-1-(x)), (y))
    #define XORPIXEL(x, y)         XorPixel            ((LCD_XSIZE-1-(x)), (y))
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((y), (LCD_XSIZE-1-(x)), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((y), (LCD_XSIZE-1-(x)), (c))
    #define GETPIXEL(x, y)         GetPixel            ((y), (LCD_XSIZE-1-(x)))
    #define XORPIXEL(x, y)         XorPixel            ((y), (LCD_XSIZE-1-(x)))
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)      SETPIXELPHYS        ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)), (c))
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS        ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)), (c))
    #define GETPIXEL(x, y)         GetPixel            ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)))
    #define XORPIXEL(x, y)         XorPixel            ((LCD_XSIZE-1-(x)), (LCD_YSIZE-1-(y)))
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #error This combination of mirroring/swapping not yet supported
  #endif
#elif (LCD_SUPPORT_COMTRANS && !LCD_SUPPORT_SEGTRANS)
  #if (!LCD_SWAP_XY)
    #define SETPIXEL(x, y, c)      SetPixelPhys(x,LCD__aLine2Com0[y], c)
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS(x,LCD__aLine2Com0[y], c)
    #define GETPIXEL(x, y)     LCD_L0_GetPixelIndex(x,LCD__aLine2Com0[y])
    #define XORPIXEL(x, y)      XorPixel(x,LCD__aLine2Com0[y])
  #else
    #define SETPIXEL(x, y, c)      SetPixelPhys(y,LCD__aLine2Com0[x], c)
    #define SETPIXELFAST(x, y, c)  SETPIXELPHYS(y,LCD__aLine2Com0[x], c)
    #define GETPIXEL(x, y)     LCD_L0_GetPixelIndex(y,LCD__aLine2Com0[x])
    #define XORPIXEL(x, y)      XorPixel(y,LCD__aLine2Com0[x])
  #endif
#else
  #error This combination of switches not yet supported
#endif

#define XY2OFF(x,y) (y*LCD_BYTESPERLINE+x)

#define OFF2PTR(Off) &LCD_VRam[0][Off]



/*
        *********************************************************
        *                                                       *
        *       Internal set pixel routines                     *
        *                                                       *
        *********************************************************
*/

#define SETPIXELPHYS(x,y,c)                       			\
{                                                 					\
   U16 LCD_VRAMTYPE* p = OFF2PTR(XY2OFF(x,y));     \
    *p = c;										\
}


static void SetPixelPhys(int x, int y, LCD_PIXELINDEX c) {
  SETPIXELPHYS(x,y,c);
}


/*
        *********************************************************
        *                                                       *
        *       Next pixel routines, optimized for 3bpp
        *                                                       *
        *********************************************************
*/

static int CurPosX;
static U16 LCD_VRAMTYPE* pCurPos;

static void SetPosXY(int x, int y) {
  CurPosX = x;
  pCurPos = OFF2PTR(XY2OFF(x,y));
}

static void SetNextPixel(LCD_PIXELINDEX c) {
	*pCurPos = c;
	pCurPos++;
	CurPosX++;
}


unsigned int GetPixel(int x, int y) {
  U16 LCD_VRAMTYPE* p = OFF2PTR(XY2OFF(x,y));
  return (*p); 
}

unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  return GETPIXEL(x, y);
}

static void XorPixel   (int x, int y) {
  LCD_PIXELINDEX Index = GetPixel(x,y);
  Index = LCD_NUM_COLORS-1-Index;
  SetPixelPhys(x,y,Index);
}

void LCD_L0_XorPixel   (int x, int y) {
  XORPIXEL(x,y);
}

void LCD_L0_SetPixelIndex   (int x, int y, int ColorIndex) {
  SETPIXELFAST(x,y,ColorIndex);
}



/*
        *********************************************************
        *                                                       *
        *          LCD_DrawHLine optimized                      *
        *                                                       *
        *          Normal display, 3 Bpp                        *
        *                                                       *
        *********************************************************
*/


void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
	if (x0>x1) return;  /* Check if nothing to draw */
  	if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
   		 while (x0 <= x1) {
      			XORPIXEL(x0, y);
      			x0++;
    		}
  	} else {
    		U16 LCD_VRAMTYPE* p = OFF2PTR(XY2OFF(x0,y));
   		 int i,j;
    		i = x1-x0+1;
    		for (j=1; j<=i;j++){
			*p = COLOR;
			p++;
    		}
  	}
}



/*
        *********************************************************
        *                                                       *
        *          LCD_DrawVLine                                *
        *                                                       *
        *          Unoptimized                                  *
        *                                                       *
        *********************************************************
*/

void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (y0 <= y1) {
      XORPIXEL(x, y0);
      y0++;
    }
  } else {
    while (y0 <= y1) {
      SETPIXEL(x, y0, COLOR);
      y0++;
    }
  }
}

void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  for (; y0 <= y1; y0++) {
    LCD_L0_DrawHLine(x0,y0, x1);
  }
}


/*
  ***************************************************************
  *                                                             *
  *            Internal bitmap routines                         *
  *                                                             *
  ***************************************************************

*/


/*
    *********************************************
    *                                           *
    *      Draw Bitmap 1 BPP                    *
    *                                           *
    *********************************************
*/

static void  DrawBitLine1BPP(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);
/*
// Jump to right entry point
*/
  pixels = *p;
  x+=Diff;
  
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
  case 0:          /* Write mode */
  	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;
  }
}


/*
    *********************************************
    *                                           *
    *      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;
/*
// Jump to right entry point
*/
  pixels = *p;
	if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) {
	  case 0:
	    goto WriteTBit0;
	  case 1:
	    goto WriteTBit1;
	  case 2:
	    goto WriteTBit2;
	  default:
	    goto WriteTBit3;
  	} else switch (Diff&3) {
	  case 0:
	    goto WriteBit0;
	  case 1:
	    goto WriteBit1;
	  case 2:
	    goto WriteBit2;
	  default:
	    goto WriteBit3;
	}
/*
        Write without transparency
*/
WriteBit0:
  SETPIXEL(x+0, y, *(pTrans+(pixels>>6)));
  if (!--xsize)
    return;
WriteBit1:
  SETPIXEL(x+1, y, *(pTrans+(3&(pixels>>4))));
  if (!--xsize)
    return;
WriteBit2:
  SETPIXEL(x+2, y, *(pTrans+(3&(pixels>>2))));
  if (!--xsize)
    return;
WriteBit3:
  SETPIXEL(x+3, y, *(pTrans+(3&(pixels))));
  if (!--xsize)
    return;
  pixels = *(++p);
  x+=4;
  goto WriteBit0;
/*
        Write with transparency
*/
WriteTBit0:
  if (pixels&(3<<6))
    SETPIXEL(x+0, y, *(pTrans+(pixels>>6)));
  if (!--xsize)
    return;
WriteTBit1:
  if (pixels&(3<<4))
    SETPIXEL(x+1, y, *(pTrans+(3&(pixels>>4))));
  if (!--xsize)
    return;
WriteTBit2:
  if (pixels&(3<<2))
    SETPIXEL(x+2, y, *(pTrans+(3&(pixels>>2))));
  if (!--xsize)
    return;
WriteTBit3:
  if (pixels&(3<<0))
    SETPIXEL(x+3, y, *(pTrans+(3&(pixels))));
  if (!--xsize)
    return;
  pixels = *(++p);
  x+=4;
  goto WriteTBit0;



}
#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;
/*
// Jump to right entry point
*/
  pixels = *p;
  if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) {
    if ((Diff&1) ==0)
      goto WriteTBit0;
    goto WriteTBit1;
  } else {
    if ((Diff&1) ==0)
      goto WriteBit0;
    goto WriteBit1;
  }
/*
        Write without transparency
*/
WriteBit0:
  SETPIXEL(x+0, y, *(pTrans+(pixels>>4)));
  if (!--xsize)
    return;
WriteBit1:
  SETPIXEL(x+1, y, *(pTrans+(pixels&0xf)));
  if (!--xsize)
    return;
  x+=2;

⌨️ 快捷键说明

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