📄 gpcdrv.c
字号:
// x2,y2:specified the coordinate of the lines end point in pixel
// ColorIndex:the color of the pixel
// mask:line style mask,such as GPC_SOLID_LINE,GPC_DASH_LINE,GPC_DOT_LINE,GPC_DASHDOT_LINE
// style : the style to be use to paint the pixel. consisted of:GPC_REPLACE_STYLE,
// GPC_AND_STYLE,GPC_OR_STYLE,GPC_XOR_STYLE,GPC_COPY_STYLE,GPC_NOT_STYLE
//
// No return value
//-------------------------------------------------------------------------
//此函数的功能只是画实线,即没有判断mask.且并没有判断dotwidth
void seDrawLine(GC *gc, SHORT x1, SHORT y1,SHORT x2, SHORT y2, PIXEL ColorIndex, WORD mask, WORD style)
{
SHORT dx, dy, incrE, incrNE, d, x, y, x00, y00, x01, y01, bit; //topx, topy;
// WORD ColorIndex1;
bit = 0x80;
// TurnOffLCD(); //Julias 2002/5/7
// * start point definition*//
if ( x1 < x2 )
{ x00 = x1;
y00 = y1;
x01 = x2;
y01 = y2;
}
else
{ x00 = x2;
y00 = y2;
x01 = x1;
y01 = y1;
}
dx = x01 - x00;
if ( y00 < y01 ) //倾角大于270
{
dy = y01 - y00;
if( dy < dx ) //倾角大于315度
{ d = -(2*dy - dx); /*初始化判别式d*/
incrE = -2*dy; /*取像素E时判别式的增量*/
incrNE = -2*(dy - dx); /*取像素NE时判别式的增量*/
y = y00;
/* switch ( mask )
{
case GPC_SOLID_LINE:
for( x = x00; x <= x01; )
{
SETPIXEL(x, y)
if( d >= 0 )
{ d += incrE;
x++;
}
else
{ d +=incrNE;
x++;
y++;
}
}
break;
}
*/
//2002.2.5 zhuli
for ( x = x00; x <= x01; )
{
if ( (bit & mask) != 0 )
{
//SETPIXEL(x, y)
PIXEL *pixelPos;
CHAR bitOffset;
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
PixelOp( pixelPos, bitOffset, ColorIndex, style );
}
bit = bit >> 1;
if ( bit == 0 )
bit = 0x80;
if ( d >= 0 )
{
d += incrE;
x++;
}
else
{
d +=incrNE;
x++;
y++;
}
}
}
else
{ d = -(2*dx - dy); /*初始化判别式d*/
incrE = -2*dx; /*取像素E时判别式的增量*/
incrNE = -2*(dx-dy); /*取像素NE时判别式的增量*/
x = x00;
/* switch( mask )
{
case GPC_SOLID_LINE :
for( y = y00; y <= y01; )
{
SETPIXEL(x, y)
if( d >= 0 ) //取像素E
{ d += incrE;
y++;
}
else //取像素NE
{ d += incrNE;
y++;
x++;
}
}
break;
}
*/
for ( y = y00; y <= y01; )
{
if ( (bit & mask) != 0 )
{
//SETPIXEL(x, y)
PIXEL *pixelPos;
CHAR bitOffset;
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
PixelOp( pixelPos, bitOffset, ColorIndex, style );
}
bit = bit >> 1;
if ( bit == 0 )
bit = 0x80;
if ( d >= 0 ) //取像素E
{
d += incrE;
y++;
}
else //取像素NE
{
d += incrNE;
y++;
x++;
}
}
}
}
else
{ dy = y00 - y01;
if( dy < dx )
{ d = -(2*dy - dx); /*初始化判别式d*/
incrE = -2*dy; /*取像素E时判别式的增量*/
incrNE = -2*(dy - dx); /*取像素NE时判别式的增量*/
y = y00;
/* switch( mask )
{
case GPC_SOLID_LINE :
for( x = x00; x <= x01; )
{
SETPIXEL(x, y)
if( d >= 0 ) //取像素E
{ d += incrE;
x++;
}
else //取像素NE
{ d += incrNE;
x++;
y--;
}
}
break;
}
*/
for( x = x00; x <= x01; )
{
if ( (bit & mask) != 0 )
{
//SETPIXEL(x, y)
PIXEL *pixelPos;
CHAR bitOffset;
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
PixelOp( pixelPos, bitOffset, ColorIndex, style );
}
bit = bit >> 1;
if ( bit == 0 )
bit = 0x80;
if ( d >= 0 ) //取像素E
{ d += incrE;
x++;
}
else //取像素NE
{ d += incrNE;
x++;
y--;
}
}
}
else
{
d = -(2*dx - dy); /*初始化判别式d*/
incrE = -2*dx; /*取像素E时判别式的增量*/
incrNE = -2*(dx - dy); /*取像素NE时判别式的增量*/
x = x00;
/* switch( mask )
{
case GPC_SOLID_LINE :
for( y = y00; y >= y01; )
{
SETPIXEL(x, y)
if( d >= 0 ) //取像素E
{ d += incrE;
y--;
}
else //取像素NE
{ d += incrNE;
y--;
x++;
}
}
break;
}
}
*/
for( y = y00; y >= y01; )
{
if ( (bit & mask) != 0 )
{
//SETPIXEL(x, y)
PIXEL *pixelPos;
CHAR bitOffset;
GetPixelPosition( &pixelPos, &bitOffset, gc->vram, x, y );
PixelOp( pixelPos, bitOffset, ColorIndex, style );
}
bit = bit >> 1;
if ( bit == 0 )
bit = 0x80;
if( d >= 0 ) //取像素E
{ d += incrE;
y--;
}
else //取像素NE
{ d += incrNE;
y--;
x++;
}
}
}
}
// topx = x1 < x2 ? x1 : x2;
// topy = y1 < y2 ? y1 : y2;
// x00 = x1 < x2 ? x1 : x2;
// x01 = x1 < x2 ? x2 : x1;
// y00 = y1 < y2 ? y1 : y2;
// y01 = y1 < y2 ? y2 : y1;
// if( gc == gSysTcbTbl[ gLcdOwnerTskId-1 ].gc )
// WRITELCD( x00, x01, y00, y01 )
}
//------------------------------------------------------------------------------
// Function name : seSetMonoImageLine()
//
// Description : set mono line of a image in buffer onto screen
//
// No return value
//
// Parameters : PPHYIMAGEINFO ppii
// SHORT ppii->x
// SHORT ppii->y
// SHORT ppii->width
// BYTE* ppii->buffer
// BYTE ppii->method
// WORD ppii->ColorIndex
// WORD ppii->BkColorIndex
// Remarks : before the line being put, it should be converted to
// hardware dependent format. In this driver, a 256 color one.
// Generally, this function is always used to implement font
// and text function.
// So also :
//------------------------------------------------------------------------------
void seSetMonoImageLine( GC *gc, PPHYIMAGEINFO ppii )
{
PIXEL TgtLine[160]; // the maximum size of a line is width of the screen.
SHORT i, sByte, sBit;
VRAM vram;
// TurnOffLCD(); //Julias 2002/5/7
sByte = 0;
sBit = 0x80;
for( i=0; i < ppii->width; i++ )
{
if( ppii->buffer[sByte] & sBit )
TgtLine[i] = (PIXEL)(ppii->ColorIndex);
else
TgtLine[i] = (PIXEL)(ppii->BkColorIndex);
sBit = sBit>>1;
if( sBit == 0 ) //if( !sBit )
{
sBit = 0x80;
sByte++;
}
}
vram.ad = TgtLine;
vram.lcdx = 0;
vram.lcdy = 0;
vram.widthInPixel = ppii->width;
vram.widthInBit = ppii->width * BITS_PER_PIXEL;
vram.widthInUnit = ( vram.widthInBit + PIXEL_UNIT -1 ) / PIXEL_UNIT;
vram.height = ppii->height;
seSetImage( gc, ppii->x, ppii->y, ppii->width, 1, &vram, ppii->method );
}
//------------------------------------------------------------------------------
// Function name : seSetMonoImage()
// Description : put a specified monoimage
// No return value
// Parameters : PPHYIMAGEINFO ppii
// Remarks :
// So also :
//------------------------------------------------------------------------------
/*
void seSetMonoImage( GC *gc, PPHYIMAGEINFO ppii )
{
SHORT height;
PHYIMAGEINFO pii;
BYTE* pImageLineStart;
SHORT sBytesPerLine;
// get a new physical image information header for put image line
memcpy( &pii, ppii, sizeof( PHYIMAGEINFO ) );
// pointer to data of first line
pImageLineStart = ppii->buffer;
// bytes per line
sBytesPerLine = ( ppii->width + 7 ) / 8;
height = ppii->height;
while( (height--) )
{
pii.buffer = pImageLineStart;
pImageLineStart += sBytesPerLine;
seSetMonoImageLine( gc, &pii );
pii.y ++;
}
}
*/
// revised by longn_qi 2001/11/09
void seSetMonoImage( GC *gc, PPHYIMAGEINFO ppii )
{
WORD mode, j, m;
WORD nByte, rByte, k;
PBYTE buffer;
WORD style;
PIXEL ColorIndex, BkColorIndex; // ColorIndex1,topx, topy, endx, endy;
PIXEL *lineAd, *nextLineAd, *nextPixelPos;
CHAR bitOffset, nextLineOffset, nextPixelOffset;
// TurnOffLCD(); //Julias 2002/5/7
GetPixelPosition( &lineAd, &bitOffset, gc->vram, ppii->x, ppii->y );
ColorIndex = ppii->ColorIndex;
BkColorIndex = ppii->BkColorIndex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -