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

📄 gdidrv1b.c

📁 深圳市微逻辑电子有限公司 巨果&#8226 Kingmos&reg 系统核心
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************
Copyright(c) 版权所有,1998-2003微逻辑。保留所有权利。
******************************************************/

/*****************************************************
文件说明:图形设备驱动程序- 1bit / pixel 格式
版本号:2.0.0
开发时期:2000
作者:李林
修改记录:

******************************************************/

#include <eframe.h>
#include <estring.h>
#include <eassert.h>
#include <gwmeobj.h>

//#define COLOR_1BPP
//#ifndef COLOR_1BPP
//#error not define COLOR_1BPP in file eversion.h
///#endif

static COLORREF _PutPixel( _LPPIXELDATA lpPixelData );
static COLORREF _GetPixel( _LPPIXELDATA lpPixelData );
static BOOL _Line( _LPLINEDATA lpData );
static BOOL _BlkBitTransparentBlt( _LPBLKBITBLT lpData );
static BOOL _BlkBitMaskBlt( _LPBLKBITBLT lpData );
static BOOL _BlkBitBlt( _LPBLKBITBLT lpData );
static COLORREF _RealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat );
static COLORREF _UnrealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat );

//申明图形设备驱动程序接口对象
const _DISPLAYDRV _drvDisplay1BPP = {
    _PutPixel,
    _GetPixel,
    _Line,
    _BlkBitTransparentBlt,
    _BlkBitMaskBlt,
    _BlkBitBlt,
    _RealizeColor,
    _UnrealizeColor
};

//申明默认调色板
#define PALETTE_SIZE 2
static const PALETTEENTRY _rgbIdentity[PALETTE_SIZE] =                                               \
{                                                                                       \
    { 0x00, 0x00, 0x00, 0 },    /* 0 Sys Black      gray 0  */                          \
    { 0xff, 0xff, 0xff, 0 },    /* 1 Sys Dk Red  */                                     \
};																	   

//
static const BYTE leftFillMask[8]=
{
    0xff,
    0x7f,
    0x3f,
    0x1f,
    0x0f,
    0x07,
    0x03,
    0x01,
};

static const BYTE rightFillMask[8]=
{
    0xff,
    0x80,
    0xc0,
    0xe0,
    0xf0,
    0xf8,
    0xfc,
    0xfe
};

static const BYTE patternMask[8]=
{
    0x80,
    0x40,
    0x20,
    0x10,
    0x08,
    0x04,
    0x02,
    0x01
};

// *****************************************************************
//声明:static COLORREF _RealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat )
//参数:
//	IN color - RGB 颜色值
//返回值:
//	设备相关的颜色值
//功能描述:
//	由RGB颜色值得到设备相关的颜色值
//引用: 
//	
// *****************************************************************
static COLORREF _RealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat )
{
	if( lpcdwPal )
	{
		return _Gdi_RealizeColor( color, lpcdwPal, uPalNumber, uPalFormat );
	}
	else
	{		
		int like = 0;
		
		BYTE r = (BYTE)color;	//红
		BYTE g = (BYTE)(color >> 8);	//绿
		BYTE b = (BYTE)(color >> 16);	//蓝
		BYTE gray;
		//得到灰度值
		gray = (BYTE) ( (r * 30l + g * 59l + b * 11l) / 100l );
		if( gray < 0x80 )
			return 0; // black
		else
			return 1; // white;
	}
}

// *****************************************************************
//声明:static COLORREF _UnrealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat )
//参数:
//	IN color - 设备相关颜色值
//返回值:
//	设备无关颜色值
//功能描述:
//	由设备相关颜色值得到设备无关的RGB值
//引用: 
//	
// *****************************************************************

static COLORREF _UnrealizeColor( COLORREF color, LPCDWORD lpcdwPal, UINT uPalNumber, UINT uPalFormat )
{
	if( lpcdwPal )
	{
		return _Gdi_UnrealizeColor( color, lpcdwPal, uPalNumber, uPalFormat );
	}
	else
	{
		return *((COLORREF*)&_rgbIdentity[(BYTE)color&0x01]);
	}
}

// *****************************************************************
//声明:static COLORREF _PutPixel( _LPPIXELDATA lpPixelData )
//参数:
//	IN lpPixelData - _PIXELDATA结构指针,包含写点需要的数据
//返回值:
//	该点对应的颜色值
//功能描述:
//	在对应的xy点输出颜色值,并返回之前的值
//引用: 
//	
// *****************************************************************

static COLORREF _PutPixel( _LPPIXELDATA lpPixelData )
{
    LPBYTE lpVideoAdr;
    COLORREF c;
	UINT rop;
	//是否需要真实输出 ?
	if( (rop = lpPixelData->rop) != R2_NOP )
	{	//需要输出
		//得到x bit位置(在一个byte上的)
        BYTE xbit = patternMask[lpPixelData->x & 0x07];
		//得到输出显示面的内存位置
        lpVideoAdr = lpPixelData->lpDestImage->bmBits + lpPixelData->y * lpPixelData->lpDestImage->bmWidthBytes + (lpPixelData->x >> 3);
		//得到当前的颜色值
		c = *lpVideoAdr & xbit;
		//根据操作模式做相关动作
	    switch( rop )
		{
		case R2_COPYPEN:		//拷贝到目标
			if( lpPixelData->color )
				*lpVideoAdr |= xbit;
			else
				*lpVideoAdr &= ~xbit;
			break;
		case R2_XORPEN:			//异或
			if( lpPixelData->color )
				*lpVideoAdr ^= xbit;
			break;
		case R2_NOT:			//非
			*lpVideoAdr ^= xbit;
			break;
		case R2_BLACK:			//黑
			*lpVideoAdr &= ~xbit;//0;
			break;
		case R2_WHITE:			//白
			*lpVideoAdr |= xbit;//0xffff;
			break;
		case R2_MASKPEN:		// dest = dest-pixel-color and pen-color
			if( lpPixelData->color )
			    *lpVideoAdr &= 0xff;
			else
				*lpVideoAdr &= ~xbit;
			break;
		case R2_MERGEPEN:		// dest = dest-pixel-color or pen-color
			if( lpPixelData->color )
			    *lpVideoAdr |= xbit;
			break;
		case R2_MERGENOTPEN:	//
			if( !lpPixelData->color )  //dest |= ~src
			    *lpVideoAdr |= xbit;
			break;
		case R2_NOTCOPYPEN:              // dest = ~src
			if( !lpPixelData->color )
				*lpVideoAdr |= xbit;
			else
				*lpVideoAdr &= ~xbit;
			break;
		case R2_NOTXORPEN:
			if( lpPixelData->color )
			{
				;//*lpVideoAdr = ( *lpVideoAdr ^ xbit ) ^ xbit;
			}
			else
			{
				*lpVideoAdr ^= xbit;
			}
			break;
		}
	}
	else
		c = -1;
    return c;
}

// *****************************************************************
//声明:static COLORREF _GetPixel( _LPPIXELDATA lpPixelData )
//参数:
//	IN lpPixelData - _PIXELDATA结构指针,包含该点需要的数据
//返回值:
//	该点对应的颜色值
//功能描述:
//	得到对应的xy点的颜色值
//引用: 
//	
// *****************************************************************

static COLORREF _GetPixel( _LPPIXELDATA lpPixelData )
{
    LPBYTE lpVideoAdr;
    BYTE xbit = patternMask[lpPixelData->x & 0x07];

    lpVideoAdr = lpPixelData->lpDestImage->bmBits + lpPixelData->y * lpPixelData->lpDestImage->bmWidthBytes + (lpPixelData->x >> 3);
    return (*lpVideoAdr & xbit) ? 1 : 0;
}

// *****************************************************************
//声明:static BOOL __VertialSolidLine( _LPLINEDATA lpLineData, 
//										int x0, 
//										int y0, 
//										int yDir, 
//										unsigned int uLen )
//参数:
//	IN lpLineData - _LINEDATA结构指针,包含画线需要的数据
//	IN x0 - 起点 x 坐标
//	IN y0 - 起点 y 坐标
//	IN yDir - 方向(当 < 0 , 由下向上)
//	IN uLen - 点数
//返回值:
//	返回TRUE
//功能描述:
//	用纯色画垂直线
//引用: 
//	被 line.h 使用
// *****************************************************************

static BOOL __VertialSolidLine( _LPLINEDATA lpLineData, 
							   int x0, 
							   int y0, 
							   int yDir, 
							   unsigned int uLen )
{
    register LPBYTE lpVideoAdr;
    register int sum, widthBytes;
    register BYTE color, xbit;
	//扫描行宽度
    widthBytes = lpLineData->lpDestImage->bmWidthBytes;
	//显存位置
	lpVideoAdr = lpLineData->lpDestImage->bmBits + y0 * widthBytes + (x0 >> 3);

	if( yDir < 0 )
        widthBytes = -widthBytes;
    if( lpLineData->color )
        color = 0xff;
    else
        color = 0;
    //xbit = 0x80 >> (lpLineData->x0 & 0x07);
	xbit = 0x80 >> (x0 & 0x07);
    color &= xbit;

    sum = uLen;//lpLineData->sum;
	//根据操作模式做不同的处理
    if( lpLineData->rop == R2_COPYPEN )
    {
        if( lpLineData->color )
        {
            while( sum-- )
            {
                *lpVideoAdr |= color;
                lpVideoAdr += widthBytes;
            }
        }
        else
        {
            xbit = ~xbit;
            while( sum-- )
            {
                *lpVideoAdr &= xbit;
                lpVideoAdr += widthBytes;
            }
        }
    }
    else if( lpLineData->rop == R2_NOT )
    {
        while( sum-- )
        {
            *lpVideoAdr = *lpVideoAdr ^ xbit;
            lpVideoAdr += widthBytes;
        }
    }
    else if( lpLineData->rop == R2_XORPEN )
    {
        while( sum-- )
        {
            *lpVideoAdr = *lpVideoAdr ^ color;
            lpVideoAdr += widthBytes;
        }
    }
    return TRUE;
}

// *****************************************************************
//声明:static BOOL __VertialPatternLine( _LPLINEDATA lpLineData, 
//										int x0, 
//										int y0, 
//										int yDir, 
//										unsigned int uLen )
//参数:
//	IN lpLineData - _LINEDATA结构指针,包含画线需要的数据
//	IN x0 - 起点 x 坐标
//	IN y0 - 起点 y 坐标
//	IN yDir - 方向(当 < 0 , 由下向上)
//	IN uLen - 点数
//返回值:
//	返回TRUE
//功能描述:
//	带模板画垂直线
//引用: 
//	被 line.h 使用
// *****************************************************************

static BOOL __VertialPatternLine( _LPLINEDATA lpLineData, int x0, int y0, int yDir, unsigned int uLen )
{
    register LPBYTE lpVideoAdr;
    register int sum, widthBytes;
    register WORD clrFore, clrBack;
    register BYTE pattern, xbit, ixbit;

    widthBytes = lpLineData->lpDestImage->bmWidthBytes;
	lpVideoAdr = lpLineData->lpDestImage->bmBits + y0 * widthBytes + (x0 >> 3);

	if( yDir < 0 )
		widthBytes = -widthBytes;

    if( lpLineData->color )
        clrFore = 0xffff;
    else
        clrFore = 0;
    if( lpLineData->clrBack )
        clrBack = 0xffff;
    else
        clrBack = 0;

	xbit = 0x80 >> (x0 & 0x07);
    ixbit = ~xbit;
	//模板
    pattern = lpLineData->pattern;
	sum = uLen;
	//根据操作模式做不同的处理
    if( lpLineData->rop == R2_COPYPEN )
    {
        while( sum-- )
        {
            if( pattern & patternMask[y0&0x07] )
            {
                if( clrFore )
                    *lpVideoAdr |= xbit;
                else
                    *lpVideoAdr &= ixbit;
            }
            else
            {
                if( clrBack )
                    *lpVideoAdr |= xbit;
                else
                    *lpVideoAdr &= ixbit;
            }
            lpVideoAdr += widthBytes;
            y0 += yDir;//dir;
        }
    }
    else if( lpLineData->rop == R2_XORPEN )
    {
        while( sum-- )
        {
            if( pattern & patternMask[y0&0x07] )
            {
                if( clrFore )
                    *lpVideoAdr ^= xbit;
            }
            else
            {
                if( clrBack )
                    *lpVideoAdr ^= xbit;
            }
            lpVideoAdr += widthBytes;
            y0 += yDir;//dir;
        }
    }
    else if( lpLineData->rop == R2_NOT )
    {
        while( sum-- )
        {
            *lpVideoAdr ^= xbit;
            lpVideoAdr += widthBytes;
        }
    }
    return TRUE;
}

// *****************************************************************
//声明:static BOOL __VertialTransparentLine( _LPLINEDATA lpLineData, 
//										int x0, 
//										int y0, 
//										int yDir, 
//										unsigned int uLen )
//参数:
//	IN lpLineData - _LINEDATA结构指针,包含画线需要的数据
//	IN x0 - 起点 x 坐标
//	IN y0 - 起点 y 坐标
//	IN yDir - 方向(当 < 0 , 由下向上)
//	IN uLen - 点数
//返回值:
//	返回TRUE
//功能描述:
//	带模板画透明垂直线(即当模板对应位为1时,输出;为0时,不输出)
//引用: 
//	被 line.h 使用
// *****************************************************************

static BOOL __VertialTransparentLine( _LPLINEDATA lpLineData, int x0, int y0, int yDir, unsigned int uLen )
{
    register LPBYTE lpVideoAdr;
    register int sum, widthBytes;
    register WORD clrFore;
    register BYTE pattern, xbit, ixbit;

    widthBytes = lpLineData->lpDestImage->bmWidthBytes;
	lpVideoAdr = lpLineData->lpDestImage->bmBits + y0 * widthBytes + (x0 >> 3);
	if( yDir < 0 )
		widthBytes = -widthBytes;

    if( lpLineData->color )
        clrFore = 0xffff;
    else
        clrFore = 0;

	xbit = 0x80 >> (x0 & 0x07);
    ixbit = ~xbit;
    pattern = lpLineData->pattern;

    sum = uLen;//lpLineData->sum;
    if( lpLineData->rop == R2_COPYPEN )
    {
        if( clrFore )
        {

⌨️ 快捷键说明

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