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

📄 bitmap.c

📁 广州微嵌科技 "WQ44B0开发板"的显示位图程序源代码。此程序可以显示由uCGUI位图转换工具生成的位图C文件,ADS 1.2编译环境
💻 C
字号:
#include "Bitmap.h"
#include "lcd.h"

/****************************************************************************
【功能说明】把BGR色彩转换成RGB色彩
****************************************************************************/
static unsigned char BGR2RGB( unsigned char x )
{
	x = ( (x&0x38)>>1 ) | (x>>6) | (x<<5);
	return x ;
}

//写一个像素
static void SetPixel(void *PDC, int x, int y, unsigned char c)
{
	//16级灰度
	#ifdef LCDG16
		unsigned int *plcdbu = (unsigned int*)PDC+y*(LCD_XSIZE/8)+(x)/8;
		c = BGR2RGB(c);
		if(x<SCR_XSIZE && y<SCR_YSIZE)
        *plcdbu=( *plcdbu & ~(0xf0000000>>((x)%8)*4) ) | ( (c&0x0f)<<((8-1-((x)%8))*4) );
	#endif
	//256色
	#ifdef LCD256
		unsigned int *plcdbu = (unsigned int*)PDC+y*(LCD_XSIZE/4)+(x)/4;
		c = BGR2RGB(c);
		if(x<SCR_XSIZE && y<SCR_YSIZE)
        *plcdbu = ( *plcdbu & ~(0xff000000>>((x)%4)*8) ) | ( (c&0xff)<<((4-1-((x)%4))*8) );
	#endif
}

/************************* 233 ***************************/
static unsigned char ColorToIndex_233(unsigned int Color)
{
  int r, g, b;
  r = Color & 255;
  g = (Color >> 8 ) & 255;
  b = Color >> 16;
  r = (r * 7 + 127) / 255;
  g = (g * 7 + 127) / 255;
  b = (b + 42) / 85;
  return r + (g << 3) + (b << 6);
}
static unsigned int IndexToColor_233(int Index)
{
  int r, g, b;
  r = (Index & 7) * 255 / 7;
  g = ((Index >> 3) & 7) * 255 / 7;
  b = ((Index >> 6) & 3) * 85;
  return r + (g << 8) + (((unsigned int)b) << 16);
}


/************************* 332 ***************************/
static unsigned char ColorToIndex_332(unsigned int Color) 
{
	int r, g, b;
	r = Color & 255;
	g = (Color >> 8 ) & 255;
	b = Color >> 16;
	r = (r + 42) / 85;
	g = (g * 7 + 127) / 255;
	b = (b * 7 + 127) / 255;
	return r + (g << 2) + (b << 5);
}
static unsigned int IndexToColor_332(int Index) 
{
	unsigned r, g, b;
	r = (Index & 3) * 85;
	g = ((Index >> 2) & 7) * 255 / 7;
	b = ((Index >> 5) & 7) * 255 / 7;
	return r + (g << 8) + (((unsigned int)b) << 16);
}

/************************* 323 ***************************/
static unsigned char ColorToIndex_323(unsigned int Color) 
{
	int r, g, b;
	r = Color & 255;
	g = (Color >> 8 ) & 255;
	b = Color >> 16;
	r = (r * 7 + 127) / 255;
	g = (g + 42) / 85;
	b = (b * 7 + 127) / 255;
	return r + (g << 3) + (b << 5);
}
static unsigned int IndexToColor_323(int Index) 
{
	int r, g, b;
	r = (Index & 7) * 255 / 7;
	g = ((Index >> 3) & 3) * 85;
	b = ((Index >> 5) & 7) * 255 / 7;
	return r + (g << 8) + (((unsigned int)b) << 16);
}



static unsigned char GetIndexTable(const PALETTE *pPal, unsigned char *pTable)
{
	if ( pPal == (PALETTE *)0 )
	{
		return 0;
	}
	if (!pPal->pColor) 
	{
		return 0;
	}
	if (pPal->NumColor > 256) 
	{
		return 0;
	}

	{
		int i;
		int NumColor = pPal->NumColor;
		const unsigned int * pColor = &pPal->pColor[0];
		for (i=0; i< NumColor; i++) 
		{
			*pTable++ = ColorToIndex(*(pColor+i));
		}
	}
	return 1;
}

void DrawBitmap(const BITMAP *pBitmap, unsigned short x0, unsigned short y0)
{
	unsigned char IndexTable[256];
	unsigned short xsize = pBitmap->XSize, ysize = pBitmap->YSize;
	unsigned short x = x0, y = y0;
	const unsigned char *pixel = pBitmap->pData;

	GetIndexTable(pBitmap->pPal,IndexTable);
	
	switch(pBitmap->BitsPerPixel)
	{
		case 8:
			for(;ysize >0; ysize--,y++)
			{
				for (;xsize >0; xsize--,x++,pixel++)
				{
					SetPixel(DC, x, y, *(IndexTable+(*pixel)) );
				}
				x = x0;
				xsize = pBitmap->XSize;
			}
		break;
		
		case 4:
			for(;ysize >0; ysize--,y++)
			{
				for (;xsize >0; xsize=xsize-2,x++,pixel++)
				{
					SetPixel(DC, x++, y, *(IndexTable+((*pixel >> 4)&0x0f)) );
					SetPixel(DC, x, y, *(IndexTable+(*pixel & 0x0f)) );
				}
				x = x0;
				xsize = pBitmap->XSize;
			}
		break;
	}
}

⌨️ 快捷键说明

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