📄 graphics.c
字号:
return;
}
}
/*-------------------------------------------------------------------------*/
static void _Pixel4bpp(Int32 x, Int32 y, UInt32 color32)
{
unsigned left, right;
Int32 bytes;
UInt8 color4 = (UInt8) (color32 & 0x0f);
pvUInt8 bpt = 0;
UInt32 offset;
UInt8 val;
color4 |= (color4 << 4);
left = 0xFF >> ((x & 0x1)*4);
bytes = (x+1)/2 - x/2 - 1;
right = 0xFF >> (((x+1) & 0x1)*4);
right = ~right;
if (bytes < 0)
left &= right;
if (UseIndirectMode)
{
offset = (y * stride) + (x / 2);
val = halReadDisplay8(offset);
val &= ~left;
val |= (color4 & left);
halWriteDisplay8(offset, val, 1);
}
else
{
bpt = (pvUInt8) (addr + (y * stride) + (x / 2));
*bpt &= ~left;
*bpt |= (color4 & left);
}
}
/*-------------------------------------------------------------------------*/
//
// _Line4bpp()
//
// For horizontal/vertical lines only
// Does not include the last point in the line (x2, y2)
//
static void _Line4bpp(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 color32)
{
Int32 y;
unsigned left;
unsigned right;
Int32 bytes;
UInt8 color4 = (UInt8) (color32 & 0x0f);
pvUInt8 bpt = 0;
UInt32 offset = 0;
UInt8 val;
if (UseIndirectMode)
offset = (y1 * stride) + (x1 / 2);
else
bpt = (pvUInt8) (addr + (y1 * stride) + (x1 / 2));
if (y1 == y2) /* horiz. line */
{
left = 0xFF >> ((x1 & 0x1)*4);
right = ~(0xFF >> ((x2 & 0x1)*4));
bytes = x2/2 - x1/2 - 1;
color4 |= (color4 << 4);
if (bytes < 0) /* one byte only */
{
left &= right;
if (UseIndirectMode)
{
val = halReadDisplay8(offset);
val &= ~left;
val |= (color4 & left);
halWriteDisplay8(offset, val, 1);
}
else
{
*bpt &= ~left;
*bpt |= (color4 & left);
}
return;
}
if (UseIndirectMode)
{
val = halReadDisplay8(offset);
val &= ~left;
val |= (color4 & left);
halWriteDisplay8(offset, val, 1);
offset++;
//halWriteDisplay8Address(offset);
while (bytes-- > 0)
{
*pIndirectDataWrite = (UInt8) color4;
++offset;
}
val = halReadDisplay8(offset);
val &= ~right;
val |= (color4 & right);
halWriteDisplay8(offset, val, 1);
}
else
{
*bpt &= ~left;
*bpt |= (color4 & left);
bpt++;
while (bytes-- > 0)
*bpt++ = (UInt8) color4;
*bpt &= ~right;
*bpt |= (color4 & right);
}
return;
}
if (x1 == x2) /* vert. line */
{
UInt8 BitPosition = (UInt8) ((1 - (x1 & 0x1)) <<2);
UInt8 mask = (UInt8) (0xf << BitPosition);
color4 <<= BitPosition;
if (UseIndirectMode)
{
for (y = y1; y < y2; y++, offset += stride)
{
val = halReadDisplay8(offset);
val &= ~mask;
val |= color4;
halWriteDisplay8(offset, val, 1);
}
}
else
{
for (y = y1; y < y2; y++, bpt += stride)
{
*bpt &= ~mask;
*bpt |= color4;
}
}
return;
}
}
/*-------------------------------------------------------------------------*/
#if 0
static void _Pixel8bpp(Int32 x, Int32 y, UInt32 color32)
{
pvUInt8 bpt;
UInt32 offset;
if (UseIndirectMode)
{
offset = (y * stride) + x;
halWriteDisplay8(offset, (UInt8) (color32 & 0xff), 1);
}
else
{
bpt = (pvUInt8) (addr + y * stride + x);
*bpt = (UInt8) (color32 & 0xff);
}
}
#endif
/*-------------------------------------------------------------------------*/
//
// _Line8bpp()
//
// For horizontal/vertical lines only
// Does not include the last point in the line (x2, y2)
//
static void _Line8bpp(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 color32)
{
Int32 x, y;
UInt8 color8 = (UInt8) (color32 & 0xff);
pvUInt8 bpt = 0;
UInt32 offset = 0;
if (UseIndirectMode)
offset = (y1 * stride) + x1;
else
bpt = (pvUInt8) (addr + (y1 * stride) + x1);
if (y1 == y2) /* horiz. line */
{
if (UseIndirectMode)
{
//halWriteDisplayAddress(offset);
for (x = x1; x < x2; x++)
{
*pIndirectDataWrite = color8;
++offset;
}
}
else
{
for (x = x1; x < x2; x++)
*bpt++ = color8;
}
return;
}
if (x1 == x2) /* vert. line */
{
if (UseIndirectMode)
{
;
for (y = y1; y < y2; y++, offset += stride)
halWriteDisplay8(offset, color8, 1);
}
else
{
for (y = y1; y < y2; y++, bpt += stride)
*bpt = color8;
}
return;
}
}
/*-------------------------------------------------------------------------*/
//
// _Line16bpp()
//
// For horizontal/vertical lines only
// Does not include the last point in the line (x2, y2)
//
static void _Line16bpp(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 color32)
{
Int32 x, y;
UInt32 WordsPerScanline = stride / 2;
UInt16 color16 = (UInt16) (color32 & 0xffff);
pvUInt16 wpt = 0;
UInt32 offset = 0;
if (UseIndirectMode)
offset = (y1 * stride) + (x1 * 2);
else
wpt = (pvUInt16) (addr + (y1 * stride) + (x1 * 2));
if (y1 == y2) /* horiz. line */
{
if (UseIndirectMode)
{
//halWriteDisplayAddress(offset);
for (x = x1; x < x2; x++)
{
//*pIndirectDataWrite = color16;
++offset;
}
}
else
{
for (x = x1; x < x2; x++)
*wpt++ = color16;
}
return;
}
if (x1 == x2) /* vert. line */
{
if (UseIndirectMode)
{
for (y = y1; y < y2; y++, offset += stride)
halWriteDisplay16(offset, color16, 1);
}
else
{
for (y = y1; y < y2; y++, wpt += WordsPerScanline)
*wpt = color16;
}
return;
}
}
//---------------------------------------------------------------------------
// FUNCTION: SetPixel()
//
// DESCRIPTION:
// This routine writes a pixel.to display memory.
//
// PARAMETERS:
// x - horizontal coordinate (0 = left of image)
// y - vertical cooridinate (0 = top of image)
// color - color of pixel
// For 1, 2, 4, and 8 bpp, color is an index into LUT.
// For 16 bpp, color is in RGB format.
//
// RETURNS:
// Nothing.
//
// MODIFIES:
// Display memory.
//---------------------------------------------------------------------------
void SetPixel(Int32 x, Int32 y, UInt32 color)
{
/*
** If horizontal or vertical lines, use the following optimized
** functions.
*/
switch (BitsPerPixel)
{
case 1:
_Pixel1bpp(x, y, color);
break;
case 2:
_Pixel2bpp(x, y, color);
break;
case 4:
_Pixel4bpp(x, y, color);
break;
}
}
//---------------------------------------------------------------------------
// FUNCTION: DrawLine()
//
// DESCRIPTION:
// This routine writes a line.to display memory.
// Note that the last point (x2, y2) is not written.
//
// PARAMETERS:
// x1 - horizontal coordinate of top left corner
// y1 - vertical cooridinate of top left corner
// x2 - horizontal coordinate of bottom right corner
// y2 - vertical cooridinate of bottom right corner
// color - color of pixel
// For 1, 2, 4, and 8 bpp, color is an index into LUT.
// For 16 bpp, color is in RGB format.
//
// RETURNS:
// Nothing.
//
// MODIFIES:
// Display memory.
//---------------------------------------------------------------------------
void DrawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 color)
{
if (x1 > x2)
{
_Swap(&x1, &x2);
_Swap(&y1, &y2);
}
/*
** Diagonal lines
*/
switch (BitsPerPixel)
{
case 1:
_Line(x1, y1, x2, y2, color, _Pixel1bpp);
break;
case 2:
_Line(x1, y1, x2, y2, color, _Pixel2bpp);
break;
case 4:
_Line(x1, y1, x2, y2, color, _Pixel4bpp);
break;
}
}
//---------------------------------------------------------------------------
// FUNCTION: DrawRect()
//
// DESCRIPTION:
// This routine writes a line.to display memory.
// Note that the bottom and right sides are not written.
//
// PARAMETERS:
// x1 - horizontal coordinate of top left corner
// y1 - vertical cooridinate of top left corner
// x2 - horizontal coordinate of bottom right corner
// y2 - vertical cooridinate of bottom right corner
// color - color of pixel
// For 1, 2, 4, and 8 bpp, color is an index into LUT.
// For 16 bpp, color is in RGB format.
// SolidFill - SOLIDFILL_ON if rectangle is solid color
// SOLIDFILL_OFF if rectangle shows only border
//
// RETURNS:
// Nothing.
//
// MODIFIES:
// Display memory.
//---------------------------------------------------------------------------
void DrawRect(Int32 x1, Int32 y1, Int32 x2, Int32 y2, UInt32 color, Boolean SolidFill)
{
void (*linefn)(Int32,Int32,Int32,Int32,UInt32);
Int32 y;
if (y1 > y2)
{
y = y2;
y2 = y1;
y1 = y;
}
switch (BitsPerPixel)
{
case 1:
linefn = _Line1bpp;
break;
case 2:
linefn = _Line2bpp;
break;
case 4:
linefn = _Line4bpp;
break;
case 8:
default:
linefn = _Line8bpp;
break;
case 16:
linefn = _Line16bpp;
break;
}
if (x1 == x2)
(*linefn)(x1, y1, x2, y2, color);
else
{
if (SolidFill == SOLIDFILL_ON)
{
if (y1 == y2)
(*linefn)(x1, y1, x2, y1, color);
else
{
for (y = y1; y < y2; y++)
(*linefn)(x1, y, x2, y, color);
}
}
else
{
(*linefn)(x1, y1, x2, y1, color);
(*linefn)(x1, y2-1, x2, y2-1, color);
(*linefn)(x1, y1, x1, y2, color);
(*linefn)(x2-1, y1, x2-1, y2, color);
}
}
}
/*-------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -