graphic.c
来自「好记星的控件,包括button,list,对文件操作」· C语言 代码 · 共 1,483 行 · 第 1/5 页
C
1,483 行
INT8 bits_per_pixel;
UINT16 xmin,ymin; //最小的坐标
UINT16 xmax,ymax; //最大的坐标
UINT16 hres;
UINT16 vres;
INT8 palette[48];
INT8 reserved;
INT8 colour_planes;
UINT16 bytes_per_line; //每个编码行所占的字节数
UINT16 palette_type;
INT8 filler[58];
} MPCXHead;
const UINT8 PCXPallete[] = {0,0,0,0,0xff,0xff,0xff,0};
MBitMapInfo *PCX2BMP(MPCXHead *pPCXHead, MBitMap *bmpinfo)
{
UINT32 dwLineSize;
UINT8 *pBuffPCX,*pBuffBmp,*pDst,cByte,cCount;
UINT uWidth,uHeight,uBits,uLineBits;
if(pPCXHead == NULL)
{
GraphSetErrorCode(0x19);//图形调整参数错误!
return NULL;
}
uBits = pPCXHead->bits_per_pixel;
if(uBits!=1)
{
GraphSetErrorCode(0x18);//尚不支持此种文件格式!
return NULL;
}
uWidth = pPCXHead->xmax - pPCXHead->xmin + 1;
uHeight = pPCXHead->ymax - pPCXHead->ymin + 1;
dwLineSize = ((uWidth+31)>>5)<<2;
if(bmpinfo == NULL)
{
if((bmpinfo = MemAlloc(sizeof(MBitMap) + 8
+ dwLineSize*uHeight))==NULL)
{
GraphSetErrorCode(0x10);//内存不足!
return NULL;
}
}
memmove((UINT8*)bmpinfo,(UINT8*)SysDefaultBMP,sizeof(MBitMap));
bmpinfo->biBitCount = uBits;
bmpinfo->biWidth = uWidth;
bmpinfo->biHeight = uHeight;
pBuffPCX = (UINT8*)(pPCXHead + 1);
pBuffBmp = (UINT8*)(bmpinfo + 1);
memmove(pBuffBmp,PCXPallete,8);
pBuffBmp += 8;
uWidth = pPCXHead->bytes_per_line<<3;
while(uHeight--)
{
pDst = pBuffBmp;
uLineBits = 0;
do
{
cByte = *pBuffPCX++;
if((cByte&0xc0)==0xc0)
{
cCount = cByte&0x3f;
cByte = *pBuffPCX++;
memset(pDst,cByte,cCount);
}
else
{
*pDst = cByte;
cCount = 1;
}
pDst += cCount;
uLineBits += cCount<<3;
}
while(uLineBits<uWidth);
// if(((UINT)(pDst - pBuffBmp))&0x01)
// pBuffPCX += 2;
pBuffBmp += dwLineSize;
}
return (MBitMapInfo*)bmpinfo;
}
*/
/****************************************************************************/
/* FUNCTION: _GraphDrawBlock */
/* DESCRIPTION:Fill a rectangle with absolute coordinates. */
/* INPUTS: , DC pointer to get the bitmap buffer and fill. */
/* x/y,up-left corner of rectange relative to the screen border*/
/* defined by the bitmap. */
/* uWidth/uHeight,define the width and height. */
/* OUTPUTS: NONE. */
/* RETURN: NONE. */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Qorse 2002-08-11 build */
/****************************************************************************/
VOID _GraphDrawBlock(INT x,INT y,UINT uWidth,UINT uHeight)
{
UINT8 *pBuffer, *pBakBuffer;
UINT32 dwLineBytes;
int i, uLoopCount;
MBitMapInfoHeader *pBmp;
UINT8 dstHeadEx, srcTailEx; //头尾不成一个字节的位
UINT8 byColor, byDrawMode;
// for mono bitmap
UINT8 headMaskLeft, headMaskRight, tailMaskLeft, tailMaskRight;
pBmp = &g_dcSystemDC.dcBitMapInfo->bmpInfo;
dwLineBytes = _getLineBytes(pBmp->biBitCount, pBmp->biWidth);
pBuffer = (UINT8 *)(pBmp + 1) + dwLineBytes * y
+ _getPaletteSize(pBmp->biBitCount, pBmp->biClrUsed);
byDrawMode = g_dcSystemDC.dcDrawMode;
switch (pBmp->biBitCount) {
case 0x01:
pBuffer += x >> 3;
dstHeadEx = (8 - (x & 7)) & 7;
srcTailEx = (uWidth - dstHeadEx) & 7;
uLoopCount = (uWidth - dstHeadEx) >> 3;
headMaskLeft = maskTable1[dstHeadEx];
headMaskRight = ~headMaskLeft;
tailMaskLeft = maskTable1[(8 - srcTailEx) & 7];
tailMaskRight = ~tailMaskLeft;
if (g_dcSystemDC.dcBrush.bsColor == 0) {
byColor = 0xff;
}
else {
byColor = 0;
}
if (uWidth < dstHeadEx) { //小于一个字节
headMaskLeft |= ~maskTable1[dstHeadEx - uWidth];
headMaskRight = ~headMaskLeft;
uLoopCount = 0;
srcTailEx = 0;
}
if (byDrawMode == DRMODE_DSTSHADOW || byDrawMode == DRMODE_FADE) {
UINT8 byMask;
if ((g_dcSystemDC.dcX + g_dcSystemDC.dcY + (x >> 3) + y) & 1) {
byMask = 0XAA;
}
else {
byMask = 0x55;
}
while (uHeight -- > 0) {
pBakBuffer = pBuffer;
if (dstHeadEx) { //处理目标前部不到一个字节的部分
*pBakBuffer ++ &= byMask & headMaskRight;
}
for (i = 0; i < uLoopCount; ++ i) {
*pBakBuffer ++ &= byMask;
}
if (srcTailEx) { //最后不到一个字节的内容
*pBakBuffer &= byMask & tailMaskLeft;
}
pBuffer += dwLineBytes;
byMask = ~byMask;
}
}
else {
while (uHeight -- > 0) {
pBakBuffer = pBuffer;
if (dstHeadEx) { //处理目标前部不到一个字节的部分
*pBakBuffer ++ = (*pBakBuffer & headMaskLeft)
| (byColor & headMaskRight);
}
memset(pBakBuffer, byColor, uLoopCount); //中间部分
if (srcTailEx) { //最后不到一个字节的内容
pBakBuffer += uLoopCount;
*pBakBuffer = byColor & tailMaskLeft
| (*pBakBuffer & tailMaskRight);
}
pBuffer += dwLineBytes;
}
}
break;
#if COLOR_LEVEL >= 4
case 0x04:
pBuffer += x >> 1;
dstHeadEx = x & 1;
srcTailEx = (uWidth - dstHeadEx) & 1;
uLoopCount = (uWidth - dstHeadEx) >> 1;
// byColor = ~(g_dcSystemDC.dcBrush.bsColor) & 0xff;
byColor = (g_dcSystemDC.dcBrush.bsColor) & 0xff;
if (byDrawMode == DRMODE_DSTSHADOW || byDrawMode == DRMODE_FADE) {
UINT8 byMask;/*
if ((g_dcSystemDC.dcX + g_dcSystemDC.dcY + (x >> 1) + y) & 1) {
byMask = 0XF0;
}
else {
byMask = 0xF;
}*/
byMask = 0x88;
while (uHeight -- > 0) {
pBakBuffer = pBuffer;
if (dstHeadEx) { //目标起始位置为奇
*pBakBuffer ++ &= byMask & 0xf;
}
for (i = 0; i < uLoopCount; ++ i) {
*pBakBuffer ++ &= byMask;
}
if (srcTailEx) { //最后一个象素
*pBakBuffer &= byMask & 0xf0 | 0xf;
}
pBuffer += dwLineBytes;
}
}
else {
while (uHeight -- > 0) {
pBakBuffer = pBuffer;
if (dstHeadEx) { //目标起始位置为奇
*pBakBuffer ++ = (*pBakBuffer & 0xf0) | (byColor & 0xf);
}
memset(pBakBuffer, byColor, uLoopCount);
if (srcTailEx) { //最后一个象素
pBakBuffer += uLoopCount;
*pBakBuffer = (byColor & 0xf0) | (*pBakBuffer & 0x0f);
}
pBuffer += dwLineBytes;
}
}
break;
#endif
}
}
/****************************************************************************/
/* FUNCTION: GraphDrawDot */
/* DESCRIPTION:Draw a dot.the dot size and color are defined by pen. */
/* INPUTS: ,Device to fill. */
/* x,x-coordinate of dot. */
/* y,y-coordinate of dot. */
/* OUTPUTS: NONE. */
/* RETURN: NONE. */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Qorse 2002-08-11 build */
/****************************************************************************/
VOID GraphDrawDot(INT x,INT y)
{
UINT8 *pBuffer, byMask;
UINT32 dwLineBytes;
MBitMapInfoHeader *pBmp;
if (x < 0 || x >= (INT)g_dcSystemDC.dcWidth
|| y < 0 || y >= (INT)g_dcSystemDC.dcHeight)
{
return;
}
x += g_dcSystemDC.dcX;
y += g_dcSystemDC.dcY;
pBmp = &g_dcSystemDC.dcBitMapInfo->bmpInfo;
if (x < 0 || y < 0 || x >= pBmp->biWidth || y >= pBmp->biHeight) {
return;
}
dwLineBytes = _getLineBytes(pBmp->biBitCount, pBmp->biWidth);
pBuffer = (UINT8 *)(pBmp + 1) + dwLineBytes * y
+ _getPaletteSize(pBmp->biBitCount, pBmp->biClrUsed);
switch (pBmp->biBitCount) {
case 0x01:
pBuffer += x >> 3;
byMask = 1 << (7 - (x & 7));
*pBuffer &= ~byMask;
if (g_dcSystemDC.dcPen.pnColor == BLACK_COLOR) {
*pBuffer |= byMask;
}
break;
case 0x04:
pBuffer += x >> 1;
if (x & 1) {
*pBuffer &= 0xf0;
// *pBuffer |= ~(g_dcSystemDC.dcPen.pnColor) & 0xf;
*pBuffer |= (g_dcSystemDC.dcPen.pnColor) & 0xf;
}
else {
*pBuffer &= 0xf;
// *pBuffer |= ~(g_dcSystemDC.dcPen.pnColor) & 0xf0;
*pBuffer |= (g_dcSystemDC.dcPen.pnColor) & 0xf0;
}
break;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?