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

📄 uigraph.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	iDestWidth  = x2-x1+1;
	iDestHeight = y2-y1+1;

	if(iSrcWidth<iDestWidth)
		return;

	if(iSrcHeight<iDestHeight)
		return;

	iSrcByteCnt  = (((iSrcWidth-1) >> 2) + 1);
	iDestByteCnt = (((iDestWidth-1) >> 2) + 1);
	
	*(pDest+1) = (BYTE)iDestWidth;
	*(pDest+3) = (BYTE)iDestHeight;
	*(pDest+4) = BMP_4BIT_STYLE;
	for(i=0; i<iDestHeight; i++)
	{
		pSrcPos  = (BYTE *)pSrc+12+i*iSrcByteCnt;
		pDestPos = pDest+12+i*iDestByteCnt;
		memcpy(pDestPos, pSrcPos, iDestByteCnt);
	}		
}
*/

/************************************************************************
* pSrc    : buffer of source image                                      *
* pDest   : buffer of destination image                                 *
* function: cut form start_col, start_row to end_col, end_row of        *
*         source image to destination buffer                            *
*************************************************************************/
DLL_EXP(void) guiCutImage(int start_col, int start_row, int end_col, int end_row, const BYTE *pSrc, BYTE *pDest )
{
	unsigned char *pSrcPos, *pDestPos;
	int iSrcWidth, iSrcHeight, iDestWidth, iDestHeight;
	int i, j, k, iSrcByteCnt, iDestByteCnt, Offset;
	short nBit;
	BYTE  ch1, ch2, chAnd, ch ;

	iSrcWidth   = guiGetImageWidth(pSrc);
	iSrcHeight  = guiGetImageHeight(pSrc);
	
	if((start_row>end_row)||(start_row>end_row))
		return;

	if(start_col>iSrcWidth-1)
		return;

	if(start_row>iSrcHeight-1)
		return;

	if(end_col>iSrcWidth-1)
		end_col = iSrcWidth-1;

	if(end_row>iSrcHeight-1)
		end_row = iSrcHeight-1;

	iDestWidth  = end_col - start_col + 1;
	iDestHeight = end_row - start_row + 1;

	/*if(iSrcWidth<iDestWidth)
	{
		end_col = start_col+iSrcWidth-1;
		iSrcWidth = iDestWidth;
		//return;
	}

	if(iSrcHeight<iDestHeight)
	{
		end_row = start_row+iSrcHeight-1;
		iSrcHeight = iDestHeight;
		//return;
	}*/

	iSrcByteCnt  = (((iSrcWidth-1) >> 2) + 1);
	iDestByteCnt = (((iDestWidth-1) >> 2) + 1);

		
	*(pDest+1) = (BYTE)iDestWidth;
	*(pDest+3) = (BYTE)iDestHeight;
	*(pDest+4) = BMP_4BIT_STYLE;

	//start_col += 7;

	Offset = start_col >> 2;
	nBit= 2*(start_col%4);
	if (!nBit)
	{
		for(i=start_row; i<end_row+1; i++)
		{
			pSrcPos  = (BYTE *)pSrc+12+i*iSrcByteCnt+Offset;
			pDestPos = pDest+12+(i-start_row)*iDestByteCnt;
			memcpy(pDestPos, pSrcPos, iDestByteCnt);
		}
	}
	else
	{
		for(i=start_row; i<end_row+1; i++)
		{
			pSrcPos  = (BYTE *)pSrc+12+i*iSrcByteCnt+Offset;
			pDestPos = pDest+12+(i-start_row)*iDestByteCnt;
			//memcpy(pDestPos, pSrcPos, iDestByteCnt);
			for(j=0; j<iDestByteCnt; j++)
			{
				ch = *(pSrcPos+j);
				ch1 = ch<<nBit;				
				
				ch = *(pSrcPos+j+1);				
				ch2 = 1;
				for(k=0; k<nBit; k++)
					ch2 = 2*ch2;
				ch2--;

				chAnd = ch2<<(8-nBit);
				
				ch2 = ch&chAnd;
				ch2 = ch2>>(8-nBit);
				*(pDestPos+j) = ch1|ch2;
				
			}
		}	
	}
}


DLL_EXP(void) guiPutImage(HNDL handle, int left, int top, int right, int bottom, const BYTE *pImage)
{
	unsigned char *pDisplay;
	unsigned char byMode;
	int iRectWidth, iRectHeight, nWidth, nHeight;
	int iSize, iRet;
	TRect ViewRect;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int overlap_x1, overlap_y1, overlap_x2, overlap_y2;
	int start_col, start_row, end_col, end_row;
	int x1, y1, x2, y2;

	iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);
	//if(!iRet)
	if(iRet!=STATUS_OK)
		return;
	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;

	x1 = left;    y1 = top;
	x2 = right;   y2 = bottom;
	
	_guiConvertXY(handle, &x1, &y1);
	_guiConvertXY(handle, &x2, &y2);

	pDisplay = gScreenBuffer;

	iSize = guiGetImageSizeFromImage(pImage);
	memcpy(pDisplay, pImage, iSize);

	if((x1>x2)||(y1>y2))
		return;

	if((x2<ViewLeft)||(x1>ViewRight)||(y2<ViewTop)||(y1>ViewBottom))
		return ;

	guiEnterWCS();

	iRectWidth = x2-x1+1;
	iRectHeight = y2-y1+1;
	
	nWidth  = guiGetImageWidth(pImage);
	nHeight = guiGetImageHeight(pImage);

	if(nWidth<iRectWidth)
	{
		x2  = x1+nWidth-1;
		iRectWidth = x2-x1+1;
	}

	if(nHeight<iRectHeight)
	{
		y2  = y1+nHeight-1;
		iRectHeight = y2-y1+1;
	}

	/*if(iRectWidth<nWidth)
	{
		guiCutImage(0, 0, iRectWidth-1, iRectHeight-1, pImage, pDisplay);
		nHeight = guiGetImageHeight(pDisplay);
		nWidth  = guiGetImageWidth(pDisplay);

	}*/

	overlap_x1 = x1; overlap_y1 = y1; overlap_x2 = x2; overlap_y2 = y2;
	iRet = _guiGetOverlapRect(&ViewRect, &overlap_x1, &overlap_y1, &overlap_x2, &overlap_y2);
	if(iRet!=STATUS_OK)
	{
		guiExitWCS();
		return;
	}

	start_col = overlap_x1 - x1;    start_row = overlap_y1 - y1;
	end_col   = overlap_x2 - x1;    end_row   = overlap_y2 - y1;
	guiCutImage(start_col, start_row, end_col, end_row,  pImage, pDisplay);
	//nHeight = guiGetImageHeight(pDisplay);
	//nWidth  = guiGetImageWidth(pDisplay);
	
	if(pImage[4])
		byMode = pImage[4];
	else
		byMode = pImage[11];
	
	
#ifndef __WIN32__
	pDisplay = pDisplay+12;
#endif
	//displayRestoreImage(x1, y1, x2, y2, pDisplay);
	displayRestoreImage(overlap_x1, overlap_y1, overlap_x2, overlap_y2, pDisplay);
	guiExitWCS();
	return;
}


/*DLL_EXP(void) guiPutImageEx(HNDL handle, int x1, int y1, int x2, int y2, int offset_x, 
							int offset_y, const BYTE *pImage)
{
	unsigned char *pDisplay;
	int idx, idy, idw, idh;
	WORD nWidth, nHeight;

	if((x1>x2)||(y1>y2))
		return;

	nHeight = guiGetImageHeight(pImage);

	nWidth = guiGetImageWidth(pImage);

	idw = nWidth-offset_x;
	idx = x2-x1+1;
	if(idw<idx) 
		x2 = nWidth+x1-offset_x-1;

	idh = nHeight-offset_y;
	idy = y2-y1+1;
	if(idh<idy)
		y2 = nHeight+y1-offset_y-1;

	pDisplay = gScreenBuffer;

	guiCutImage(offset_x, offset_y, x2-x1+offset_x, y2-y1+offset_y, pImage, pDisplay);

	guiPutImage(handle, x1,y1, x2, y2, pDisplay);
}
*/

// style: GUI_SOLID, GUI_HATCH 
DLL_EXP(void) guiDrawRect (HNDL handle, int left, int top, int right, int bottom, int iColor, int iStyle)
{

	guiEnterWCS();

	iColor &= 0x000000ff;
	guiDrawLine(handle, left, top, right, top, iColor, iStyle);
	guiDrawLine(handle, left, bottom, right, bottom, iColor, iStyle);
	guiDrawLine(handle, left, top, left, bottom, iColor, iStyle);
	guiDrawLine(handle, right, top, right, bottom, iColor, iStyle);	
	
	guiExitWCS();
	return;
}

// may fill image
DLL_EXP(void) guiFillRect(HNDL handle, int left, int top, int right, int bottom, int iColor, int iStyle)
{
	TRect ViewRect;
	int i, j, iRet;
	int iWidth, iHeight;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int x1, y1, x2, y2;


	//int iRet;
	iColor &= 0x000000ff;
	iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);
	//if(!iRet)
	if(iRet!=STATUS_OK)
		return;
	
	guiEnterWCS();

	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;
	
	x1 = left;    y1 = top;
	x2 = right;    y2 = bottom;
	
	_guiConvertXY(handle, &x1, &y1);
	_guiConvertXY(handle, &x2, &y2);
		
	if(iStyle!=GUI_IMAGE)
	{	//for(i=y; i<y+height; i++)
		for(i=y1; i<=y2; i++)
		{
			if(iStyle==GUI_HATCH)
			{
				//for(j=x; j<x+width; j++)
				for(j=x1; j<=x2; j++)
				{
					if(!(i%2))
					{
						if(!(j%2))
							//displayDrawPixel(j, i, iColor);
							_guiDrawPixelInView(&ViewRect, j, i, iColor);
					}
					else
					{
						if(j%2)
							//displayDrawPixel(j, i, iColor);
							_guiDrawPixelInView(&ViewRect, j, i, iColor);
						
					}
				}
			}
			else
			{
				//guiDrawHLine(x, x+width-1, i, iColor, iStyle);
				_guiDrawHLineInView(&ViewRect, x1, x2, i, iColor);
			}
		}	
	}	
	else
	{
		int i, j, iWidthCnt, iHghCnt;
		int OffsetX, OffsetY;
		int width, height;

		if(!gImageBuffer)
		{
			guiExitWCS();
			return;
		}

		//gImageBuffer = iconExit;       // for test!
		width = right-left+1;
		height = bottom-top+1;

		iWidth = guiGetImageWidth(gImageBuffer);
		iHeight = guiGetImageHeight(gImageBuffer);
		
		iWidthCnt = width/iWidth;
		iHghCnt   = height/iHeight;
		
		OffsetY = 0;
		OffsetX = 0;
		for(i=0; i<iHghCnt; i++)
		{
			OffsetX = 0;
			for(j=0; j<iWidthCnt; j++)
			{
				x1 = left + OffsetX;
				y1 = top + OffsetY;
				x2 = x1+iWidth -1;
				y2 = y1+iHeight-1;
				guiPutImage(handle, x1, y1, x2, y2, gImageBuffer);
				OffsetX += iWidth;
			}
			
			if(width%iWidth)
			{
				x1 = left + OffsetX;
				y1 = top + OffsetY;
				x2 = x1+width%iWidth-1;
				y2 = y1+iHeight-1;
				guiPutImage(handle, x1, y1, x2, y2, gImageBuffer);
			}
			OffsetY += iHeight;
		}

		OffsetX = 0;
		if(height%iHeight)
		{
			for(j=0; j<width/iWidth; j++)
			{
				x1 = left+OffsetX;
				y1 = top+OffsetY;
				x2 = x1+iWidth-1;
				y2 = y1+height%iHeight-1;
				guiPutImage(handle, x1, y1, x2, y2, gImageBuffer);
				OffsetX += iWidth;
			}

			if(width%iWidth)
			{
				x1 = left+OffsetX;
				y1 = top+OffsetY;
				x2 = x1+width%iWidth-1;
				y2 = y1+height%iHeight-1;
				guiPutImage(handle, x1, y1, x2, y2, gImageBuffer);
			}

		}

	}

	guiExitWCS();
	return;

}

/* call before call guiFillRect() , set pointer of image to be filled */
void guiSetPattern(const BYTE *pattern_img)
{
	gImageBuffer = (BYTE *)pattern_img;
}

DLL_EXP(void) guiInvertRect (HNDL handle,  int left, int top, int right, int bottom)
{
	unsigned char  *pImage, *pTemp;
	int idx, idy, iRet;
	TRect ViewRect;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int x1, y1, x2, y2;

	pImage = gScreenBuffer;	

	iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);
	if(iRet!=STATUS_OK)
		return;

	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;

	x1 = left;    y1 = top;
	x2 = right;   y2 = bottom;
	
	_guiConvertXY(handle, &x1, &y1);
	_guiConvertXY(handle, &x2, &y2);

	iRet = _guiGetOverlapRect(&ViewRect, &x1, &y1, &x2, &y2);

	if(iRet!=STATUS_OK)
		return;			
	
	/*idx = x2 - x1;
	idy = y2 - y1;

	*pImage     = 0;
	*(pImage+1) = (unsigned char)idx+1;
	*(pImage+2) = 0;
	*(pImage+3) = (unsigned char)idy+1;
	*/

	//*(pImage+4) = gGraphMode;

#ifdef __WIN32__
	pTemp = pImage;
#else
	pTemp = pImage+12;
#endif


	guiEnterWCS();

#ifdef __WIN32__
	displaySaveImage(x1, y1, x2, y2, pTemp);
	*(pTemp+4) = gGraphMode;
	guiInvertImage(pTemp);
	displayRestoreImage(x1, y1, x2, y2, pTemp);
#else
	//displayInvertRange(left, top, right, bottom);
	displayInvertRange(x1, y1, x2, y2);
#endif

	guiExitWCS();
	return;

}


//iStyle: GUI_SOLID, GUI_HATCH	
DLL_EXP(void) guiDrawCircle (HNDL handle, int x0, int y0, int radius, int iColor, int iStyle)
{
	int ix, iy, x1, y1, preX, preDY, step;
	
	iColor &= 0x000000ff;
	if(x0-radius<0)

⌨️ 快捷键说明

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