graphic2.c
来自「好记星的控件,包括button,list,对文件操作」· C语言 代码 · 共 1,539 行 · 第 1/5 页
C
1,539 行
#include "kernel.h"
#include "graphin.h"
//#include "Plus\Nucleus.h"
//#include "file\pcdisk.h"
//#include "OsBase.h"
//#include "IoDriver.h"
//#include "Memory.h"
//#include "Reg.h"
//#include "File.h"
//#include "System.h"
//#include "Resource.h"
//#include "Graphic.h"
//#include "GraphIn.h"
//#include "Global.h"
extern UINT32 g_dwTransparentColor; /*Transparent Color*/
extern const UINT32 Std1To4[];
extern const UINT8 maskTable1[] ;
extern const UINT32 maskTable4[] ;
extern MTable1To4 g_mTable; //the table to change mono to gray16
extern MDC g_dcSystemDC; /* 系统DC */
extern UINT8 g_GraphRefreshFlag; /*Enable Lcd refresh flag*/
extern UINT8 g_uLcdIndex; /*Lcd logic index*/
extern NU_DRIVER *g_pLcdDriver; /*Lcd device handle*/
#ifdef __ED928__
extern NU_DRIVER *g_pExtLcdDriver;
#endif
extern BOOL g_bFillFade; /*Fill With Fade mode*/
/*************************************************************************/
/* FUNCTION: _PreDrawDotImage */
/* DESCRIPTION:prepare the table and change draw mode. */
/* INPUTS: pDC,Device to fill. */
/* dwColor,the color of 1. */
/* dwBKColor,the color of 0. */
/* OUTPUTS: NONE. */
/* RETURN: NONE. */
/*************************************************************************/
BOOL _PreDrawDotImage(MDC *pDC, UINT32 dwColor, UINT32 dwBKColor)
{
#if COLOR_LEVEL >= 4
UINT32 temp;
#endif
switch (pDC->dcBitMapInfo->bmpInfo.biBitCount) {
case 1:
if (dwColor == dwBKColor) {
return FALSE;
}
g_mTable.style = pDC->dcDrawMode;
switch (g_mTable.style) {
case DRMODE_SRCOR:
g_mTable.style = DRMODE_TRANSPARENT;
break;
case DRMODE_SRCCOPY:
if (dwColor == WHITE) {
g_mTable.style = DRMODE_NOTSRC;
}
break;
case DRMODE_NOTSRC:
if (dwColor == WHITE) {
g_mTable.style = DRMODE_SRCCOPY;
}
break;
}
break;
#if COLOR_LEVEL >= 4
case 4:
g_mTable.style = pDC->dcDrawMode;
switch (g_mTable.style) {
case DRMODE_SRCOR:
g_mTable.style = DRMODE_TRANSPARENT;
break;
case DRMODE_NOTSRC:
g_mTable.style = DRMODE_SRCCOPY;
temp = dwColor;
dwColor = dwBKColor;
dwBKColor = temp;
break;
}
// create the table
if (g_mTable.dwBKColor != dwBKColor || g_mTable.dwColor != dwColor)
{
g_mTable.dwBKColor = dwBKColor;
g_mTable.dwColor = dwColor;
if (dwColor == BLACK && dwBKColor == WHITE) {
g_mTable.pCurTable = (UINT32 *)&Std1To4;
break;
}
else {
UINT32 *pTmpDst, *pSrc;
int i;
g_mTable.pCurTable = (UINT32 *)&g_mTable.table;
pTmpDst = g_mTable.pCurTable;
pSrc = (UINT32 *)&Std1To4;
dwColor = (~dwColor & 0xffffff);
dwColor |= dwColor << 8;
dwBKColor = (~dwBKColor & 0xffffff);
dwBKColor |= dwBKColor << 8;
for (i = 0; i < 256; ++ i) {
*pTmpDst = pSrc[i] & dwColor | (~pSrc[i] & dwBKColor);
pTmpDst ++;
}
}
/*
if (dwColor == WHITE && dwBKColor == BLACK) { //reverse display tbl
// if (dwColor == BLACK && dwBKColor == WHITE) {
UINT32 *pTmpDst, *pSrc;
int i;
g_mTable.pCurTable = (UINT32 *)&g_mTable.table;
pTmpDst = g_mTable.pCurTable;
pSrc = (UINT32 *)&Std1To4;
dwColor = (~dwColor & 0xffffff);
dwColor |= dwColor << 8;
dwBKColor = (~dwBKColor & 0xffffff);
dwBKColor |= dwBKColor << 8;
for (i = 0; i < 256; ++ i) {
*pTmpDst = pSrc[i] & dwColor | (~pSrc[i] & dwBKColor);
pTmpDst ++;
}
break;
}
else {
g_mTable.pCurTable = (UINT32 *)&Std1To4;
}
*/
/*
if (dwColor == BLACK && dwBKColor == WHITE) {
g_mTable.pCurTable = (UINT32 *)&Std1To4;
break;
}
else {
UINT32 *pTmpDst, *pSrc;
int i;
g_mTable.pCurTable = (UINT32 *)&g_mTable.table;
pTmpDst = g_mTable.pCurTable;
pSrc = (UINT32 *)&Std1To4;
dwColor = (~dwColor & 0xffffff);
dwColor |= dwColor << 8;
dwBKColor = (~dwBKColor & 0xffffff);
dwBKColor |= dwBKColor << 8;
for (i = 0; i < 256; ++ i) {
*pTmpDst = pSrc[i] & dwColor | (~pSrc[i] & dwBKColor);
pTmpDst ++;
}
}
*/
}
break;
#endif
}
return TRUE;
}
/****************************************************************************/
/* FUNCTION: _DrawDotImage */
/* DESCRIPTION:Draw a 2-color image with dot information. */
/* INPUTS: pDC,Device to fill. */
/* x,x-coordinate of start point. */
/* y,y-coordinate of start point. */
/* uImageW,width or enable area. */
/* uImageH,height or enable area. */
/* dotbuff,dot image buffer. */
/* uOffbit,bit to avoid from left(support negative coordinate).*/
/* LineBytes,one line buffer length for bitmap of dc. */
/* bRevers,flag of invert data. */
/* OUTPUTS: NONE. */
/* RETURN: NONE. */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Qorse 2002-08-11 build */
/****************************************************************************/
VOID _DrawDotImage(MDC *pDC, INT x, INT y, UINT uImageW, UINT uImageH,
MBitMapInfoHeader *pSrcBmp, int nSrcX, int nSrcY)
{
UINT8 *pSrcBuffer;
UINT32 dwSrcLineBytes;
dwSrcLineBytes = _getLineBytes(pSrcBmp->biBitCount, pSrcBmp->biWidth);
pSrcBuffer = (UINT8 *)(pSrcBmp + 1) + dwSrcLineBytes * nSrcY
+ _getPaletteSize(pSrcBmp->biBitCount, pSrcBmp->biClrUsed);
_PreDrawDotImage(pDC, BLACK, WHITE);
_DrawTextImage(pDC, x, y, uImageW, uImageH,
pSrcBuffer, nSrcX, dwSrcLineBytes);
}
/*************************************************************************/
/* FUNCTION: _BitBlt4To4 */
/* DESCRIPTION:This function restore the image to appointed DC */
/* INPUTS: pDC,the pointer of appointed DC */
/* bmpinfo,a image block. */
/* x1,y1,x2,y2 define the area of DC to restore the image. */
/* OUTPUTS: BOOL */
/* RETURN: BOOL */
/*************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ===========================================*/
/* Bingle 2005-01-04 build */
/*************************************************************************/
VOID _BitBlt4To4(MDC *pDstDC, int x, int y, int width, int height,
MBitMapInfoHeader *pSrcBmp, int nSrcX, int nSrcY)
{
UINT8 *pSrcBuffer, *pDstBuffer;
UINT8 *pBakSrcBuffer, *pBakDstBuffer;
UINT32 dwSrcLineBytes, dwDstLineBytes;
UINT i, uLoopCount;
BOOL dstHead, srcHead, dstTail;
MBitMapInfoHeader *pDstBmp;
pDstBmp = &pDstDC->dcBitMapInfo->bmpInfo;
dwSrcLineBytes = _getLineBytes(pSrcBmp->biBitCount, pSrcBmp->biWidth);
dwDstLineBytes = _getLineBytes(pDstBmp->biBitCount, pDstBmp->biWidth);
pSrcBuffer = (UINT8 *)(pSrcBmp + 1) + dwSrcLineBytes * nSrcY
+ _getPaletteSize(pSrcBmp->biBitCount, pSrcBmp->biClrUsed);
pDstBuffer = (UINT8 *)(pDstBmp + 1) + dwDstLineBytes * y
+ _getPaletteSize(pDstBmp->biBitCount, pDstBmp->biClrUsed);
pSrcBuffer += nSrcX >> 1;
pDstBuffer += x >> 1;
dstHead = x & 1;
dstTail = (width - dstHead) & 1;
srcHead = nSrcX & 1;
uLoopCount = (width - dstHead) >> 1;
if (pDstDC->dcDrawMode == DRMODE_SRCCOPY) {
while (height -- > 0) {
pBakSrcBuffer = pSrcBuffer;
pBakDstBuffer = pDstBuffer;
if (dstHead) { //目标起始位置为奇
if (srcHead) {
*pBakDstBuffer ++ = (*pBakDstBuffer & 0xf0)
| (*pBakSrcBuffer ++ & 0xf);
}
else {
*pBakDstBuffer ++ = (*pBakDstBuffer & 0xf0)
| (*pBakSrcBuffer >> 4);
}
}
//起始位置奇偶性不同,需拆分组合每个字节,否则直接拷贝
if (dstHead != srcHead) {
for (i = 0; i < uLoopCount; ++i) {
*pBakDstBuffer ++ = (*pBakSrcBuffer ++ << 4)
| (pBakSrcBuffer[1] >> 4);
}
if (dstTail) { //最后一个象素占半个字节
*pBakDstBuffer = (*pBakSrcBuffer << 4)
| (*pBakDstBuffer & 0x0f);
}
}
else {
memmove(pBakDstBuffer, pBakSrcBuffer, uLoopCount);
pBakDstBuffer += uLoopCount;
pBakSrcBuffer += uLoopCount;
if (dstTail) { //最后一个象素占半个字节
*pBakDstBuffer = (*pBakSrcBuffer & 0xf0)
| (*pBakDstBuffer & 0x0f);
}
}
pSrcBuffer += dwSrcLineBytes;
pDstBuffer += dwDstLineBytes;
}
}
else if (pDstDC->dcDrawMode == DRMODE_TRANSPARENT) {
UINT8 bySrc, byHi, byLo, byAll;
byHi = g_dwTransparentColor & 0xf0;
byLo = g_dwTransparentColor & 0xf;
byAll = g_dwTransparentColor & 0xff;
while (height -- > 0) {
pBakSrcBuffer = pSrcBuffer;
pBakDstBuffer = pDstBuffer;
if (dstHead) { //目标起始位置为奇
if (srcHead) {
bySrc = *pBakSrcBuffer ++ & 0xf;
}
else {
bySrc = *pBakSrcBuffer >> 4;
}
if (bySrc != byLo) {
*pBakDstBuffer ++ = (*pBakDstBuffer & 0xf0) | bySrc;
}
}
//起始位置奇偶性不同,需拆分组合每个字节,否则直接拷贝
if (dstHead != srcHead) {
for (i = 0; i < uLoopCount; ++i) {
bySrc = (*pBakSrcBuffer ++ << 4)
| (pBakSrcBuffer[1] >> 4);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?