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

📄 uigraph.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 3 页
字号:

	#include <pr2k.h>
	#include <uiwnd.h>
	#include <math.h>
#include <uiGui_Cfg.h>


#include <lcddrv.h>

//#include <graphlib.h>
#include <uigraph.h>
#include <uiUtility.h>

#define IMAGE_HEADER_LEN  12

// unsigned char *_glib_img_buf=0;
unsigned char *gScreenBuffer=0;
//unsigned char *pattern_image_buf=0;
unsigned char *gImageBuffer=0;
//int Double_LCDBuffer_Check=0;
//unsigned char _GraphMode=BMP_4BIT_STYLE;
unsigned char gGraphMode=BMP_4BIT_STYLE;

//BOOL gEnableCursor = FALSE;

short guiGetScreenWidth(void)
{
	return GUI_SCREEN_WIDTH;
}

short guiGetScreenHeight(void)
{
	return GUI_SCREEN_HEIGHT;
}

#if 0
int displayInvertRange(int x1,int y1,int x2,int y2)
{
	return STATUS_OK;
}

int displayInvertRange(int x1,int y1,int x2,int y2)
{
	unsigned short i;
	unsigned char mask;
	unsigned char tmp_image;
	int bytePos;
	int bitPos;
	int bitCount; 	// Bit and byte position in the display memory
	int tempBytePos;
	unsigned char *image = (unsigned char *) GUI_SCREEN_BASE;	
	int width_bytes;
		
	if (x2<=x1)
		return STATUS_ERR;
	if (y2<=y1)
		return STATUS_ERR;
#ifdef GRAY_SCALE_4
	bytePos = (((y1 * GUI_SCREEN_WIDTH + x1) << 1) >> 3);
	bitPos = ((x1 << 1) & 0x0007);
	mask = (0xFF >> bitPos);
	bitCount = ((x2 - x1 + 1) << 1);
	width_bytes=(MAX_WIDTH >> 2);
#else
	bytePos = ((y1 * GUI_SCREEN_WIDTH + x1) >> 3);
	bitPos = (x1 & 0x0007);
	mask = (0xFF >> bitPos);
	bitCount = (x2 - x1 + 1);
	width_bytes=(GUI_SCREEN_WIDTH >> 3);
#endif

	// handle the first imcomplete byte
	if (bitPos != 0)
	{
		if (bitCount >= 8 - bitPos)
		{
			// the bits starting from bitPos to the end of the byte will be filled
			bitCount -= (8 - bitPos);
		}
		else
		{
			// the n bits starting from bitPos will be filled and there are no more bits to fill
			mask = mask & (0xFF << (8 - bitPos - bitCount));
			bitCount = 0;
		}

		// fill in the same location in every line from y1 to y2
		tempBytePos = bytePos;
		for (i = 0; i <= (y2 - y1); i++)
		{
			// clear the region to be filled
			tmp_image=~image[tempBytePos];
			image[tempBytePos] &= ~mask;			
			// fill in the pixels
			image[tempBytePos] |= (tmp_image & mask);
			// go to next line
			tempBytePos += width_bytes;
		}
		
		if (bitCount == 0)
			return STATUS_ERR;
		else
			bytePos++;	// next byte in LCD image buffer
	}

	// handle intermediate bytes
	// a whole byte in LCD image buffer is filled in every loop
	while (bitCount >= 8)
	{
		tempBytePos = bytePos;		

		for (i = 0; i <= (y2 - y1); i++)
		{
			// the region to be filled is byte-aligned
			tmp_image=~image[tempBytePos];
			image[tempBytePos] =tmp_image;
			// go to next line
			tempBytePos += width_bytes;
		}
		bytePos++;	// next byte in LCD image buffer
		bitCount -= 8;	// fills 8 bits in each loop
	}

	// handle the last imcomplete bytes
	if (bitCount > 0)
	{
		tempBytePos = bytePos;
		mask = (0xFF << (8 - bitCount));

		for (i = 0; i <= (y2 - y1); i++)
		{
			tmp_image=~image[tempBytePos];
			image[tempBytePos] &= ~mask;
			image[tempBytePos] |= (tmp_image & mask);
			tempBytePos += width_bytes;	// next byte in LCD image buffer
		}
	}
	return STATUS_OK;
}
#endif

DLL_EXP(void) guiClearScreen(void)
{
	displayClear();
}

DLL_EXP(void) guiGetScreen(unsigned char *pScreen)
{

	guiGetImage(0, 0, 0, GUI_SCREEN_WIDTH-1, GUI_SCREEN_HEIGHT-1, pScreen);
}

#ifndef __WIN32__
void guiPutScreen(int x, int y, int width, int height, const unsigned char *pStore)
{

	guiPutImage(0, 0, 0, GUI_SCREEN_WIDTH-1, GUI_SCREEN_HEIGHT-1, pStore);
}
#endif


int _guiGetOverlapRect(TRect *rect, int *left, int *top, int *right, int *bottom)
{
	int iRet;
	int x1, y1, x2, y2;	
	
	if((*left>*right)||(*top>*bottom))
		return STATUS_ERR;

	if((rect->left>*right)||(rect->right<*left)||(rect->top>*bottom)||(rect->bottom<*top))
		return STATUS_ERR;

	x1 = max(rect->left, *left);
	y1 = max(rect->top, *top);
	x2 = min(rect->right, *right);
	y2 = min(rect->bottom, *bottom);

	*left  = x1;         *top    = y1;
	*right = x2;         *bottom = y2;
	
	return STATUS_OK;
}

// x, y is physical coordinate, style is GUI_SOLID
int _guiDrawHLineInView(TRect *rect, int x1, int x2, int y, int color)
{
	int left, right;

	color &= 0x000000ff;

	if(x1>x2)
	{
		left = x2;
		right = x1;
	}
	else
	{
		left = x1;
		right = x2;
	}
	
	if ((y<rect->top)||(y>rect->bottom))
		return STATUS_ERR;

	if((right<rect->left)||(left>rect->right))
		return STATUS_ERR;

	left  = max(rect->left, left);
	right = min(rect->right, right);
	displayDrawHLine(left, right, y, color, GUI_SOLID);
	return STATUS_OK;
}


// x, y is physical coordinate, style is GUI_SOLID
int _guiDrawVLineInView(TRect *rect, int x, int y1, int y2, int color)
{
	int top, bottom;

	color &= 0x000000ff;

	if(y1>y2)
	{
		top = y2;
		bottom = y1;
	}
	else
	{
		top = y1;
		bottom = y2;
	}

	if ((x<rect->left)||(x>rect->right))
		return STATUS_ERR;

	if((y2<rect->top)||(y1>rect->bottom))
		return STATUS_ERR;

	top    = max(rect->top, top);
	bottom = min(rect->bottom, bottom);
	displayDrawVLine(x, top, bottom, color); 
	return STATUS_OK;
}

void _guiDrawPixelInView(TRect *rect, int x, int y, int color)
{

	color &= 0x000000ff;
	if((x>=rect->left)&&(x<=rect->right)&&(y>=rect->top)&&(y<=rect->bottom))
		displayDrawPixel(x, y, color);
}

DLL_EXP(void) guiDrawPixel(HNDL handle, int x, int y, int color)
{
	TRect ViewRect;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int iRet;
	
	color &= 0x000000ff;

	iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);

	if(iRet!=STATUS_OK)
		return;

	_guiConvertXY(handle, &x, &y);

	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;
	_guiDrawPixelInView(&ViewRect, x, y, color);

}

// Left -> right
// iStyle:GUI_SOLID, GUI_HATCH
DLL_EXP(void) guiDrawLine (HNDL handle, int logic_x1, int logic_y1, int logic_x2, int logic_y2, int color, int style )
{
	TRect ViewRect;
	int x, y, step, iRet, i;
	//int x1, y1, x2, y2;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int x1, y1, x2, y2;

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

	guiEnterWCS();

	ViewRect.left  = ViewLeft;   ViewRect.top    = ViewTop;
	ViewRect.right = ViewRight;  ViewRect.bottom = ViewBottom;
	
	if(logic_x2>=logic_x1)
	{
		x1 = logic_x1;    y1 = logic_y1;
		x2 = logic_x2;    y2 = logic_y2;
	}
	else
	{
		x1 = logic_x2;    y1 = logic_y2;
		x2 = logic_x1;    y2 = logic_y1;		
	}

	_guiConvertXY(handle, &x1, &y1);
	_guiConvertXY(handle, &x2, &y2);

	if((style!=GUI_SOLID)&&(style!=GUI_HATCH))
		style = GUI_SOLID;

	if(x1==x2)
	{
		//displayDrawVLine(x1, y1, y2, color);
		if(style==GUI_HATCH)
		{
			for(i=y1; i<=y2; i+=2)
				_guiDrawPixelInView(&ViewRect, x1, i, color);
		}
		else
		{
			_guiDrawVLineInView(&ViewRect, x1, y1, y2, color);
			_guiDrawPixelInView(&ViewRect, x1, y2, color);
		}
		guiExitWCS();
		return;
	}
	
	
	if(y1==y2)
	{
		if(style==GUI_HATCH)
		{
			for(i=x1; i<=x2; i+=2)
				_guiDrawPixelInView(&ViewRect, i, y1, color);
		}
		else
		{
			
			//displayDrawHLine(x1, x2, y1, color, style);
			_guiDrawHLineInView(&ViewRect, x1, x2, y1, color);
		}

		guiExitWCS();
		return;
	}
	
	if(style==GUI_HATCH)
		step = 2;
	else
		step = 1;

	
	if(abs(x2-x1)>abs(y2-y1))
	{
		for(x=x1; x<=x2; x+=step)
		{				
			//y = y1+(x-x1)*(y2-y1)/(x2-x1);
			y = y1+((x-x1)*(y2-y1)+((x2-x1)/2)*(y2-y1)/abs(y2-y1))/(x2-x1); // 四舍五入
			
																			/*if((x-x1)*(y2-y1)%(x2-x1)*2>(x2-x1))
																			y++;
			*/
			_guiDrawPixelInView(&ViewRect, x, y, color);
		}
	}
	else
	{
		if(y2>y1)
		{
			for(y=y1; y<=y2; y+=step)
			{
				
				x = x1+((y-y1)*(x2-x1)+(y2-y1)/2)/(y2-y1);
				//displayDrawPixel(x, y, color);
				_guiDrawPixelInView(&ViewRect, x, y, color);
			}
		}
		else
		{
			for(y=y2; y<=y1; y+=step)
			{
				
				x = x1+((y-y1)*(x2-x1)+(y2-y1)/2)/(y2-y1);

				_guiDrawPixelInView(&ViewRect, x, y, color);
			}			
		}		
	}

	guiExitWCS();
	return;
}


DLL_EXP(void) guiInvertImage(BYTE *pImage )
{
	int i, iSize;
	unsigned char *pImageData;
	unsigned char ch;

	iSize = guiGetImageSizeFromImage(pImage);
	pImageData = pImage + IMAGE_HEADER_LEN;

	for(i=0; i<iSize; i++)
	{
		ch = *(pImageData+i);
		ch = ~ch;
		*(pImageData+i) = ch;
	}
}

// pImage include Image Header
DLL_EXP(void) guiGetImage(HNDL handle, int left, int top, int right, int bottom, BYTE *pImage )
{
	//struct imageInfo ImageHeader;	
	unsigned char  *pTemp;
	int idx, idy, iRet;
	TRect ViewRect;
	int ViewLeft, ViewTop, ViewRight, ViewBottom;
	int x1, y1, x2, y2;

	
	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_ERR)
	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();
	displaySaveImage(x1, y1, x2, y2, pTemp);
	guiExitWCS();
	*(pImage+4) = gGraphMode;
	return;

}

/************************************************************************
* pSrc    : buffer of source image                                      *
* pDest   : buffer of destination image                                 *
* function: 
* remark  : Rect of Dest  must be smaller than that of Src              *
*************************************************************************/
/*DLL_EXP(void) guiCutImage(int x1, int y1, int x2, int y2, const BYTE *pSrc, BYTE *pDest )
{

	unsigned char *pSrcPos, *pDestPos;
	int iSrcWidth, iSrcHeight, iDestWidth, iDestHeight;
	int i, iSrcByteCnt, iDestByteCnt;

	iSrcWidth   = guiGetImageWidth(pSrc);
	iSrcHeight  = guiGetImageHeight(pSrc);

⌨️ 快捷键说明

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