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

📄 lcd_pixel.h

📁 嵌入式系统
💻 H
📖 第 1 页 / 共 2 页
字号:

/******************************************************************************
@@
@@ [Name]		: LCDWritePixel
@@
@@ [Summary]	: Write pixel data
@@				 
@@ [Argument]	: adrs	: Address in which write pixel data
@@				  hword	: Half word offset of address in which write pixel data
@@				  byte	: Byte offset of address in which write pixel data
@@				  bit	: Bit offset of address in which write pixel data
@@				  color	: Pixel color
@@
@@ [Return]		: None
@@
@@ [Desc]		: Write the corresponding pixel data to bits per pixel and
@@				  endian.
@@
@@ [History]	: Date		Modifier	Comment
@@
@@ [END]
******************************************************************************/
APD_INLINE void LCDWritePixel(unsigned long *adrs,unsigned char hword,unsigned char byte,unsigned char bit,APD_LCD_COLOR color)
{	
    LCDSetPixelByShort(adrs, (unsigned short)color);
    //LCDSetPixelByWord(adrs,color);
}

/******************************************************************************
@@
@@ [Name]		: LCDReadPixel
@@
@@ [Summary]	: Read pixel data
@@				 
@@ [Argument]	: adrs	: Address which read pixel data
@@				  hword	: Half word offset of address which read pixel data
@@				  byte	: Byte offset of address which read pixel data
@@				  bit	: Bit offset of address which read pixel data
@@
@@ [Return]		: Pixel data
@@
@@ [Desc]		: Read the corresponding pixel data to bits per pixel 
@@				  and endian.
@@
@@ [History]	: Date		Modifier	Comment
@@
@@ [END]
******************************************************************************/
APD_INLINE APD_LCD_COLOR LCDReadPixel(
unsigned long *adrs,
unsigned char hword  
//unsigned char byte,
//unsigned char bit
)
{
	APD_LCD_COLOR color = 0;
	color = (APD_LCD_COLOR)*adrs;
	return(color);
}

/******************************************************************************
@@
@@ [Name]		: LCDWriteImage
@@
@@ [Summary]	: Write image data
@@				 
@@ [Argument]	: image	   : Pointer to image data
@@				  dim	   : Pointer to buffer of real size of image data
@@				  dimWrite : Pointer to buffer of size drawn image data
@@				  adrs	   : Address in which write image data
@@				  hword	   : Half word offset of address which write image data
@@				  byte	   : Byte offset of address which write image data
@@				  bit	   : Bit offset of address which write image data
@@
@@ [Return]		: None
@@
@@ [Desc]		: Write image data
@@
@@ [History]	: Date		Modifier	Comment
@@
@@ [END]
******************************************************************************/
APD_INLINE void LCDWriteImage(unsigned char *image,APD_LCD_DIM *dim,APD_LCD_DIM *dimWrite,unsigned long *adrs,unsigned char hword,unsigned char byte,unsigned char bit)
{
/*
   If APD_LCD_BPP is 16BPP, access to memory by a half word unit.
   So if LCD byte endian is little endian, the half word address
   to write pixel data isn't controlled.
   But if it is big endian, the one is controlled in front and behind.
*/

#ifdef APD_LCD_LEBO
	unsigned short x, y;
	unsigned long *xadrs;
	unsigned short *l_img;
	unsigned long size;	
	unsigned short xmod = (unsigned short)(dim->width - dimWrite->width);

	l_img = (unsigned short *)image;
/* Use memcpy when raster operation is APD_LCD_ROP_S(overwrite) */
	if (current_gc.rop == APD_LCD_ROP_S) {
		for (y = 0; y < dimWrite->height; y++) {
			size = dimWrite->width;
			xadrs = adrs;
			/* Measure against 32bit boundary */
			if (hword) {
				memcpy(xadrs, l_img, sizeof(unsigned short));
				l_img++;
				xadrs++;
				size--;
			}
			/* Memcpy by a word unit */
			if (size >> 1) {
				LCDMemcpyWord((unsigned long *)xadrs, (unsigned long *)l_img, size >> 1);
				l_img += size & 0xFFFFFFFE;
				xadrs += size & 0xFFFFFFFE;
				size &= 0x00000001;
			}

			/* Copy the rest data */
			if (size) {
				memcpy(xadrs, l_img, size);
				l_img++;
			}
			adrs += LCD_OFSTPL/2;
			if (xmod)
				l_img += xmod;
		}
	}
/* Generally draw image by a word unit according to raster operation */
/* Copy data to LineData every horizontal 1line data, and caluculate */
	else {
		size = dimWrite->width;

	/* Access to memory by a 16 bit unit if BPP is 16 */
	/* Copy current data in memory to LineData */
	/* Measure against 32bit boundary */
		if (hword) {
			adrs--;
			size++;
		}

		if (size & 0x01)
			size++;

		for (y = 0; y < dimWrite->height; y++) {
			LCDMemcpyWord((unsigned long *)LineData, (unsigned long *)adrs,
						  (unsigned long)(size >> 1));

			if (hword)
				xadrs = (unsigned long *)(LineData + 2);
			else
				xadrs = (unsigned long *)LineData;
			
			for (x = 0; x < dimWrite->width; x++) {
/* Write pixel data in LineData */
				LCDSetPixelByShort(xadrs, l_img[x]);
				xadrs++;
			}

/* Write pixel data in memory */
			LCDMemcpyWord((unsigned long *)adrs, (unsigned long *)LineData,
						  (unsigned long)(size >> 1));
			
/* Update image data and address which write data */
			l_img += dim->width;
			adrs += LCD_OFSTPL/2;
		}
	}
#else
/* Memcopy every horizontal 1 line data when byte endian of LCD controller is
   big endian */	
#ifdef APD_LCD_BEBO
	unsigned short x, y;
	unsigned long *xadrs;
	unsigned short *l_img;
	unsigned long size;	/* Number of pixel */
	unsigned short *padrs;
	
	l_img = (unsigned short *)image;

	size = dimWrite->width;

	/* Access to memory by a 16 bit unit if BPP is 16 */
	/* Copy current data in memory to LineData */
	/* Measure against 32bit boundary */
	if (hword)
		adrs--;
		size++;

	if (size & 0x01)
		size++;

	for (y = 0; y < dimWrite->height; y++) {
		unsigned char	hw_flg;

		hw_flg = hword;

		LCDMemcpyWord((unsigned long *)LineData, (unsigned long *)adrs,
					  (unsigned long)(size >> 1));

		if (hword)
			xadrs = (unsigned long *)(LineData + 2);
		else
			xadrs = (unsigned long *)LineData;
		
		for (x = 0; x < dimWrite->width; x++) {
			padrs = xadrs;
			if (hw_flg)
				padrs--;
			else
				padrs++;
/* Write pixel data in LineData */
			LCDSetPixelByShort(padrs, l_img[x]);
			xadrs++;
			hw_flg ^= 0x01;
		}
/* Write pixel data in memory */
			LCDMemcpyWord((unsigned long *)adrs, (unsigned long *)LineData,
						  (unsigned long)(size >> 1));

/* Update image data and address in which write data */
		l_img += dim->width;
		adrs += LCD_OFSTPL/2;
	}
#endif /* APD_LCD_BEBO */

#endif /* APD_LCD_LEBO */

}

/******************************************************************************
@@
@@ [Name]		: LCDReadImage
@@
@@ [Summary]	: Read image data
@@				 
@@ [Argument]	: image	: Pointer to buffer in which write image data
@@				  dim	: Pointer to size of image data
@@				  adrs	: Address from which read image data
@@				  hword	: Half word offset of address from which read image
@@				  byte	: Byte offset of address from which read image data
@@				  bit	: Bit offset of address from which read image data
@@
@@ [Return]		: image data
@@
@@ [Desc]		: Read image data
@@
@@ [History]	: Date		Modifier	Comment
@@
@@ [END]
******************************************************************************/
void LCDReadImage(unsigned char *image,APD_LCD_DIM *dim,unsigned long *adrs,unsigned char hword,unsigned char byte,unsigned char bit)
{
	unsigned short y;
	unsigned long *xadrs;
	unsigned short *l_img;
	unsigned long size;

	l_img = (unsigned short *)image;
	for (y = 0; y < dim->height; y++)
	 {
		size = dim->width;
		xadrs = adrs;
		
		/* Measure against 32bit boundary */
		if (hword)
		 {
			memcpy(l_img, xadrs, sizeof(unsigned short));
			l_img++;
			xadrs++;
			size--;
		 }

#ifdef APD_LCD_LEBO
		if (size >> 1) 
		 {
			LCDMemcpyWord((unsigned long *)l_img, (unsigned long *)xadrs, size >> 1);
			xadrs += size & 0xFFFFFFFE;
			l_img += size & 0xFFFFFFFE;
			size &= 0x00000001;
		 }

		if (size)
			memcpy(l_img, xadrs, sizeof(unsigned short));
#else
#ifdef APD_LCD_BEBO

		if (size >> 1) {
			unsigned long	r_size = size & 0xFFFFFFFE;
			unsigned long	*org_data;
			unsigned long	i;
LCDMemcpyWord((unsigned long *)LineData, (unsigned long *)xadrs,r_size >> 1);
			org_data = (unsigned long *)LineData;
			for (i = 0; i < (r_size >> 1); i++) {
				*l_img = (unsigned short)((org_data[i] & 0xFFFF0000) >> 16);
				l_img++;
				*l_img = (unsigned short)(org_data[i] & 0x0000FFFF);
				l_img++;
			}

			xadrs += r_size;
			size &= 0x00000001;
		}
		if (size) {
			xadrs++;
			memcpy(l_img, xadrs, sizeof(unsigned short));
		}
#endif	/* APD_LCD_BEBO */
#endif	/* APD_LCD_LEBO */
			
	adrs += LCD_OFSTPL;
	}
}

/******************************************************************************
@@
@@ [Name]		: LCDWriteBMP
@@
@@ [Summary]	: Write Bit Map data
@@				 
@@ [Argument]	: image	   : Pointer to Bit Map data
@@				  dim	   : Pointer to size of Bit Map data
@@				  dimWrite : Pointer to size drawn Bit Map data
@@				  adrs	   : Address in which write Bit Map data
@@				  hword	   : Half word offset of address in which write data
@@				  byte	   : Byte offset of address in which write data
@@				  bit	   : Bit offset of address in which write data
@@
@@ [Return]		: None
@@
@@ [Desc]		: Write Bit Map Data 
@@
@@ [History]	: Date		Modifier	Comment
@@
@@ [END]
******************************************************************************/
APD_INLINE void LCDWriteBMP(unsigned char *image,APD_LCD_DIM *dim,APD_LCD_DIM *dimWrite,unsigned long *adrs,unsigned char hword,unsigned char byte,unsigned char bit)
{
	unsigned short	x, y;
	unsigned long	*xadrs;
	unsigned long	size;
	unsigned char	hw_flg, img_ofst, img_mask, *img_ptr = image;
	/* Width of BMP image each horaizontal line */
	unsigned short	img_width = (unsigned short)((dim->width / BITS_PER_BYTE) +
										 (((dim->width % BITS_PER_BYTE) == 0) ? 0 : 1)) * BITS_PER_BYTE;
	/* Horizontal surplur byte */
	unsigned short	xmod = (unsigned short)((img_width - dimWrite->width) / BITS_PER_BYTE)
					+ ((((img_width - dimWrite->width) % BITS_PER_BYTE) == 0) ? 0 : 1);

	size = dimWrite->width;

/* Copy current data in memory */
/* Measure against 32bit boundary */
	if (hword) {
		adrs--;
		size++;
	}

	if (size & 0x01)
		size++;
	
	for (y = 0; y < dimWrite->height; y++) {
		hw_flg = hword;

/* Copy data in memory to LineData */		
		LCDMemcpyWord((unsigned long *)LineData, (unsigned long *)adrs,
					  (unsigned long)(size >> 1));

		xadrs = (unsigned long *)LineData;
		if (hw_flg)
			xadrs++;
		
/* Initialize monochrome Bit Map */
		img_ofst = 0;
		img_mask = BITMAP_MASK;

		for (x = 0; x < dimWrite->width; x++) {
/* Write pixel data in LineData */
			if (*img_ptr & img_mask) {
				unsigned long *hw_adrs;

				hw_adrs = (unsigned long *)xadrs;

#ifdef APD_LCD_BEBO
				if (hw_flg)
					hw_adrs--;
				else
					hw_adrs++;
#endif	/* APD_LCD_BEBO */
				
				LCDSetPixelByShort(hw_adrs, (unsigned short)current_gc.c);
			}
			hw_flg ^= 0x01;
			xadrs++;

			img_mask >>= BITMAP_BPP;
			if (!img_mask) {
				img_mask = BITMAP_MASK;
				img_ptr++;
			}
		}
/* Write data of LineData in memory */
		LCDMemcpyWord((unsigned long *)adrs, (unsigned long *)LineData,
					  (unsigned long)(size >> 1));
		
		if (img_mask == BITMAP_MASK)
			img_ptr += xmod;
		else
			img_ptr += xmod;

		img_mask = BITMAP_MASK;
		adrs += LCD_OFSTPL;
	}
}
#endif	/* APD_LCD_PIXEL */

⌨️ 快捷键说明

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