📄 guidev.c
字号:
/*! @file GUIDEV.c
* Implementation of memory devices
*
* @author hiber modified
* @author Copyleft (C) 1981-2006, All Rights Givenup
* @date 04/18/2006
* @version
*
* @note
* @attention
* @warning
* @bug
*
* @todo
* @example <file-name>
* @see
*/
#include <string.h>
#include "GUI_Private.h"
#include "GUIDebug.h"
//////////////////////////////////////////////////////////////////////////
// HIBER
#if GUI_WINSUPPORT
//#include "wm.h"
#endif
#if GUI_SUPPORT_MEMDEV
#define GUI_ALLOC_H2P(h) _GUI_ALLOC_h2p_Lock(h)
#define GUI_ALLOC_FREE(handle) GUI_ALLOC_Free(handle)
#define GUI_ALLOC_LOCK(handle) _GUI_ALLOC_h2p_Lock(handle)
#define GUI_ALLOC_UNLOCK(handle)
#ifdef GUI_USAGE_H2P
#undef GUI_USAGE_H2P
#define GUI_USAGE_H2P(h) ((GUI_USAGE*)_GUI_ALLOC_h2p_Lock(h))
#endif
#ifdef GUI_MEMDEV_H2P
#undef GUI_MEMDEV_H2P
#define GUI_MEMDEV_H2P _GUI_ALLOC_h2p_Lock
#endif
const struct tLCDDEV_APIList_struct GUI_MEMDEV__APIList8 = {NULL};// 兼容3.90a
//! 适应3.90a版,带LOCK的GUI_ALLOC_h2p
void* _GUI_ALLOC_h2p_Lock(GUI_HMEM hMem)
{
void * p;
GUI_LOCK();
p = GUI_ALLOC_h2p(hMem);
GUI_UNLOCK();
return p;
}
//////////////////////////////////////////////////////////////////////////
#define POS_AUTO -4095 /* Position value for auto-pos */
//! This table contains 0, 1, 2, ... and serves as translation table for DDBs
#define INTS(Base) Base+0,Base+1,Base+2,Base+3,Base+4,Base+5, \
Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \
Base+12,Base+13,Base+14,Base+15
//! 颜色转换表结构(用于DDB-设备相关位图)
static const LCD_PIXELINDEX aID[] =
{
INTS(0)
};
//////////////////////////////////////////////////////////////////////////
//! internal routines (not part of interface table)
//! @note 原函数名为GUI_MEMDEV_XY2PTR,修改已适应3.90a
void *GUI_MEMDEV__XY2PTR(int x, int y)
{
GUI_MEMDEV* pDev = GUI_ALLOC_H2P(GUI_Context.hDevData);
U8 *pData = (U8*)(pDev+1);
//////////////////////////////////////////////////////////////////////////
#if GUI_DEBUG_LEVEL >= GUI_DEBUG_LEVEL_CHECK_ALL
if ((x >= pDev->x0 + pDev->XSize) | (x < pDev->x0) |
(y >= pDev->y0 + pDev->YSize) | (y < pDev->y0))
{
GUI_DEBUG_ERROROUT2("GUI_MEMDEV_XY2PTR: parameters out of bounds", x, y);
}
#endif
pData += (y - pDev->y0) *pDev->BytesPerLine;
return ((LCD_PIXELINDEX*)pData) + x - pDev->x0;
}
//! 存储设备绘制1位直线
static void DrawBitLine1BPP(GUI_USAGE *pUsage, int x, int y, U8 const *p, int Diff,
int xsize, const LCD_PIXELINDEX *pTrans)
{
LCD_PIXELINDEX pixels;
LCD_PIXELINDEX Index0 = *(pTrans + 0);
LCD_PIXELINDEX Index1 = *(pTrans + 1);
LCD_PIXELINDEX *pData;
U8 PixelCnt;
GUI_MEMDEV* pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
PixelCnt = 8-(Diff &7);
pixels = (*p) << (Diff &7);
pData = (LCD_PIXELINDEX *)GUI_MEMDEV__XY2PTR(x, y);
GUI_DEBUG_ERROROUT3_IF(x < pDev->x0, "GUIDEV.c: DrawBitLine1BPP, Act= %d, Border= %d, Clip= %d",
x, pDev->x0, GUI_Context.ClipRect.x0);
switch (GUI_Context.DrawMode &(LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
{
case 0:
/* Write mode */
PixelLoopWrite: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
*pData++ = (pixels &0x80) ? Index1 : Index0;
pixels <<= 1;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 8;
pixels = *(++p);
goto PixelLoopWrite;
}
break;
case LCD_DRAWMODE_TRANS:
PixelLoopTrans: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
if ((pixels &0x80))
{
if (pUsage)
{
GUI_USAGE_AddPixel(pUsage, x, y);
}
*pData = Index1;
}
x++;
pData++;
pixels <<= 1;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 8;
pixels = *(++p);
goto PixelLoopTrans;
}
break;
case LCD_DRAWMODE_XOR:
;
PixelLoopXor: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
if ((pixels &0x80))
{
*pData = pDev->NumColors - 1- *pData;
}
pData++;
pixels <<= 1;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 8;
pixels = *(++p);
goto PixelLoopXor;
}
break;
}
}
//! 存储设备绘制2位直线
static void DrawBitLine2BPP(GUI_USAGE *pUsage, int x, int y, U8 const *p, int Diff,
int xsize, const LCD_PIXELINDEX *pTrans)
{
U8 pixels;
U8 PixelCnt;
LCD_PIXELINDEX *pData;
PixelCnt = 4-(Diff &3);
pixels = (*p) << ((Diff &3) << 1);
pData = (LCD_PIXELINDEX *)GUI_MEMDEV__XY2PTR(x, y);
switch (GUI_Context.DrawMode &(LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
{
case 0:
/* Write mode */
PixelLoopWrite: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
*pData++ = *(pTrans + (pixels >> 6));
pixels <<= 2;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 4;
pixels = *(++p);
goto PixelLoopWrite;
}
break;
case LCD_DRAWMODE_TRANS:
PixelLoopTrans: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
if (pixels &0xc0)
{
*pData = *(pTrans + (pixels >> 6));
GUI_USAGE_AddPixel(pUsage, x, y);
}
pData++;
pixels <<= 2;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 4;
pixels = *(++p);
goto PixelLoopTrans;
}
break;
case LCD_DRAWMODE_XOR:
PixelLoopXor: if (PixelCnt > xsize)
{
PixelCnt = xsize;
}
xsize -= PixelCnt;
do
{
if ((pixels &0xc0))
{
*pData ^= 255;
}
pData++;
pixels <<= 2;
} while (--PixelCnt);
if (xsize)
{
PixelCnt = 4;
pixels = *(++p);
goto PixelLoopXor;
}
break;
}
}
//! 存储设备绘制4位直线
static void DrawBitLine4BPP(GUI_USAGE *pUsage, int x, int y, U8 const *p, int Diff,
int xsize, const LCD_PIXELINDEX *pTrans)
{
U8 pixels;
LCD_PIXELINDEX *pData;
U8 PixelCnt;
PixelCnt = 2-(Diff &1);
pixels = (*p) << ((Diff &1) << 2);
pData = (LCD_PIXELINDEX *)GUI_MEMDEV__XY2PTR(x, y);
switch (GUI_Context.DrawMode &(LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
{
/*
* Write mode *
*/
case 0:
/* Draw incomplete bytes to the left of center area */
if (Diff)
{
*pData = *(pTrans + (pixels >> 4));
pData++;
xsize--;
pixels = *++p;
}
/* Draw center area (2 pixels in one byte) */
if (xsize >= 2)
{
int i = xsize >> 1;
xsize &= 1;
do
{
*pData = *(pTrans + (pixels >> 4)); /* Draw 1. (left) pixel */
*(pData + 1) = *(pTrans + (pixels &15)); /* Draw 2. (right) pixel */
pData += 2;
pixels = *++p;
}
while (--i);
}
/* Draw incomplete bytes to the right of center area */
if (xsize)
{
*pData = *(pTrans + (pixels >> 4));
}
break;
/*
* Transparent draw mode *
*/
case LCD_DRAWMODE_TRANS:
/* Draw incomplete bytes to the left of center area */
if (Diff)
{
if (pixels &0xF0)
{
*pData = *(pTrans + (pixels >> 4));
if (pUsage)
{
GUI_USAGE_AddPixel(pUsage, x, y);
}
}
pData++;
x++;
xsize--;
pixels = *++p;
}
/* Draw center area (2 pixels in one byte) */
while (xsize >= 2)
{
/* Draw 1. (left) pixel */
if (pixels &0xF0)
{
*pData = *(pTrans + (pixels >> 4));
if (pUsage)
{
GUI_USAGE_AddPixel(pUsage, x, y);
}
}
/* Draw 2. (right) pixel */
if (pixels &= 15)
{
*(pData + 1) = *(pTrans + pixels);
if (pUsage)
{
GUI_USAGE_AddPixel(pUsage, x + 1, y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -