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

📄 guidev_1.c

📁 MCB2300_ucgui_LCD320240.rar LPC2368的uc/gui的移植
💻 C
📖 第 1 页 / 共 2 页
字号:
			/* Write mode */
			do
			{
				(*pDev->pAPIList->pfSetPixelIndex) (x++, y, * (pTrans + *pSrc));
				pSrc++;
			}
			while (--xsize);
			break;
		case LCD_DRAWMODE_TRANS:
			do
			{
				if (*pSrc)
				{
					(*pDev->pAPIList->pfSetPixelIndex) (x, y, * (pTrans + *pSrc));
				}
				x++;
				pSrc++;
			}
			while (--xsize);
			break;
	}
}

/*********************************************************************
*
*   	_DrawBitLine8BPP_DDB
*/
static void _DrawBitLine8BPP_DDB(GUI_USAGE *pUsage, int x, int y, const U8 GUI_UNI_PTR *pSrc, int xsize, GUI_MEMDEV *pDev, PIXELINDEX *pDest)
{
	GUI_USE_PARA(pUsage);
	GUI_USE_PARA(pDest);
	switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
	{
		case 0:
			/* Write mode */
			do
			{
				(*pDev->pAPIList->pfSetPixelIndex) (x++, y, * pSrc);
				pSrc++;
			}
			while (--xsize);
			break;
		case LCD_DRAWMODE_TRANS:
			do
			{
				if (*pSrc)
				{
					(*pDev->pAPIList->pfSetPixelIndex) (x, y, * pSrc);
				}
				x++;
				pSrc++;
			}
			while (--xsize);
			break;
	}
}

/*********************************************************************
*
*   	_DrawBitmap
*/
static void _DrawBitmap(int x0, int y0, int xsize, int ysize, int BitsPerPixel, int BytesPerLine, const U8 GUI_UNI_PTR *pData, int Diff, const LCD_PIXELINDEX *pTrans)
{
	int i;
	GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
	GUI_USAGE*  pUsage = (pDev->hUsage) ? GUI_USAGE_H2P(pDev->hUsage) : 0;
	unsigned	BytesPerLineDest;
	PIXELINDEX* pDest;
	BytesPerLineDest = pDev->BytesPerLine;
	x0 += Diff;
	/* Mark all affected pixels dirty unless transparency is set */
	if (pUsage)
	{
		if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) == 0)
		{
			GUI_USAGE_AddRect(pUsage, x0, y0, xsize, ysize);
		}
	}
	pDest = _XY2PTR_BITOFFSET(x0, y0, 0);
#if BITSPERPIXEL == 16
	/* handle 16 bpp bitmaps in high color modes, but only without palette */
	if (BitsPerPixel == 16)
	{
		for (i = 0; i < ysize; i++)
		{
			_DrawBitLine16BPP_DDB(pUsage, x0, i + y0, (const U16 *) pData, xsize, pDev, pDest);
			pData += BytesPerLine;
			pDest = (PIXELINDEX *) ((U8 *) pDest + BytesPerLineDest);
		}
		return;
	}
#endif
	/* Handle 8 bpp bitmaps seperately as we have different routine bitmaps with or without palette */
	if (BitsPerPixel == 8)
	{
		for (i = 0; i < ysize; i++)
		{
			if (pTrans)
			{
				_DrawBitLine8BPP(pUsage, x0, i + y0, pData, xsize, pTrans, pDev, pDest);
			}
			else
			{
				_DrawBitLine8BPP_DDB(pUsage, x0, i + y0, pData, xsize, pDev, pDest);
			}
			pData += BytesPerLine;
			pDest = (PIXELINDEX *) ((U8 *) pDest + BytesPerLineDest);
		}
		return;
	}
	/* Use aID for bitmaps without palette */
	if (!pTrans)
	{
		pTrans = aID;
	}
	for (i = 0; i < ysize; i++)
	{
		switch (BitsPerPixel)
		{
			case 1:
				_DrawBitLine1BPP(pUsage, x0, i + y0, pData, Diff, xsize, pTrans, pDev, pDest);
				break;
			case 2:
				_DrawBitLine2BPP(pUsage, x0, i + y0, pData, Diff, xsize, pTrans, pDev, pDest);
				break;
			case 4:
				_DrawBitLine4BPP(pUsage, x0, i + y0, pData, Diff, xsize, pTrans, pDev, pDest);
				break;
		}
		pData += BytesPerLine;
		pDest = (PIXELINDEX *) ((U8 *) pDest + BytesPerLineDest);
	}
}

/*********************************************************************
*
*   	_FillRect
*/
static void _FillRect(int x0, int y0, int x1, int y1)
{
	GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
	U8* pData;
	int Bit, Len;
	int RemPixels;
	Len = x1 - x0 + 1;
	/* Mark rectangle as modified */
	if (pDev->hUsage)
	{
		GUI_USAGE_AddRect(GUI_USAGE_H2P(pDev->hUsage), x0, y0, Len, y1 - y0 + 1);
	}
	/* Do the drawing */
	for (; y0 <= y1; y0++)
	{
		pData = _XY2PTR_BITOFFSET(x0, y0, &Bit);
		RemPixels = Len;
		if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
		{
			if (Bit < 7)
			{
				while ((Bit >= 0) && RemPixels--)
				{
					*pData ^= 1 << (Bit--);
				}
				pData++;
			}
			if (RemPixels > 0)
			{
				int NumBytes = RemPixels >> 3;
				if (NumBytes > 0)
				{
					RemPixels -= NumBytes << 3;
					do
					{
						*pData ^= *pData;
						pData++;
					}
					while (--NumBytes);
				}
				Bit = 7;
				while (RemPixels--)
				{
					*pData ^= 1 << (Bit--);
				}
			}
		}
		else
		{
			/* Fill */
			int Color, FillByte;
			Color = (LCD_COLORINDEX & 1);
			FillByte = (-Color) & 0xFF;
			if (Bit < 7)
			{
				while ((Bit >= 0) && RemPixels--)
				{
					*pData &= ~(1 << Bit);
					*pData |= Color << (Bit--);
				}
				pData++;
			}
			if (RemPixels > 0)
			{
				int NumBytes = RemPixels >> 3;
				if (NumBytes > 0)
				{
					GUI_MEMSET(pData, FillByte, NumBytes);
					pData += NumBytes;
					RemPixels -= NumBytes << 3;
				}
				Bit = 7;
				while (RemPixels--)
				{
					*pData &= ~(1 << Bit);
					*pData |= Color << (Bit--);
				}
			}
		}
	}
}

/*********************************************************************
*
*   	_DrawHLine
*/
static void _DrawHLine(int x0, int y, int x1)
{
	_FillRect(x0, y, x1, y);
}

/*********************************************************************
*
*   	_DrawVLine
*/
static void _DrawVLine(int x, int y0, int y1)
{
	GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
	GUI_USAGE_h hUsage = pDev->hUsage; 
	GUI_USAGE*  pUsage = hUsage ? GUI_USAGE_H2P(hUsage) : NULL;
	U8* pData;
	int Bit, Mask;
	pData = _XY2PTR_BITOFFSET(x, y0, &Bit);
	Mask = (1 << Bit);
	if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
	{
		do
		{
			*pData ^= Mask;
			if (pUsage)
			{
				GUI_USAGE_AddPixel(pUsage, x, y0);
			}
			pData += pDev->BytesPerLine;
		}
		while (++y0 <= y1);
	}
	else
	{
		int Pixel;
		Pixel = (LCD_COLORINDEX & 1) << Bit;
		do
		{
			*pData &= ~Mask;
			*pData |= Pixel;
			if (pUsage)
			{
				GUI_USAGE_AddPixel(pUsage, x, y0);
			}
			pData += pDev->BytesPerLine;
		}
		while (++y0 <= y1);
	}
}

/*********************************************************************
*
*   	_SetPixelIndex
*/
static void _SetPixelIndex(int x, int y, int Index)
{
	GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
	U8* pData;
	int Bit;
	pData = _XY2PTR_BITOFFSET(x, y, &Bit);
	*pData &= ~(1 << Bit);
	*pData |= (Index & 1) << Bit;
	if (pDev->hUsage)
	{
		GUI_USAGE_AddPixel(GUI_USAGE_H2P(pDev->hUsage), x, y);
	}
}

/*********************************************************************
*
*   	_XorPixel
*/
static void _XorPixel(int x, int y)
{
	GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
	U8* pData;
	int Bit;
	pData = _XY2PTR_BITOFFSET(x, y, &Bit);
	*pData ^= (1 << Bit);
	if (pDev->hUsage)
	{
		GUI_USAGE_AddPixel(GUI_USAGE_H2P(pDev->hUsage), x, y);
	}
}

/*********************************************************************
*
*   	_GetPixelIndex
*/
static unsigned int _GetPixelIndex(int x, int y)
{
	U8* pData;
	int Bit;
	pData = _XY2PTR_BITOFFSET(x, y, &Bit);
	return (*pData >> Bit) & 1;
}

/*********************************************************************
*
*   	Device structure
*
**********************************************************************
*/

const tLCDDEV_APIList API_LIST = {
GUI_MEMDEV__Color2Index,
GUI_MEMDEV__Index2Color,
GUI_MEMDEV__GetIndexMask,
(tLCDDEV_DrawBitmap *) _DrawBitmap,
_DrawHLine,
_DrawVLine,
_FillRect,
_GetPixelIndex,
GUI_MEMDEV__GetRect,
_SetPixelIndex,
_XorPixel,
NULL, 			  /* pfSetLUTEntry   */
NULL, 			  /* pfFillPolygon   */
NULL, 			  /* pfFillPolygonAA */
NULL, 			  /* MemDevAPI  	 */
BITSPERPIXEL  	  /* BitsPerPixel    */
};

#else

void GUIDEV1_C(void)
{
}

#endif /* GUI_SUPPORT_MEMDEV */

/*************************** end of file ****************************/

⌨️ 快捷键说明

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