📄 guidev_1.c
字号:
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2004 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
***** emWin - Graphical user interface for embedded applications *****
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : GUIDEV_1.c
Purpose : Implementation of memory devices
This file handles 1 bit memory devices.
---------------------------END-OF-HEADER------------------------------
*/
#include <string.h>
#include "GUI_Private.h"
#include "GUIDebug.h"
#if GUI_WINSUPPORT
#include "WM.h"
#endif
/* Memory device capabilities are compiled only if support for them is enabled.*/
#if GUI_SUPPORT_MEMDEV
/*********************************************************************
*
* Macros
*
**********************************************************************
*/
#ifndef PIXELINDEX
#define PIXELINDEX U8
#define BITSPERPIXEL 1
#define API_LIST GUI_MEMDEV__APIList1
#endif
/*********************************************************************
*
* static consts
*
**********************************************************************
*/
/*********************************************************************
*
* ID translation table
*
* This table serves as translation table for DDBs
*/
static const LCD_PIXELINDEX aID[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
/*********************************************************************
*
* static code
*
**********************************************************************
*/
/*********************************************************************
*
* _XY2PTR_BITOFFSET
*/
static U8* _XY2PTR_BITOFFSET(int x, int y, int* pBitOffset) {
GUI_ALLOC_DATATYPE_U Offset;
GUI_MEMDEV* pDev;
U8* pData;
pDev = GUI_MEMDEV_H2P(GUI_Context.hDevData);
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("_XY2PTR: parameters out of bounds", x, y);
}
#endif
x -= pDev->x0;
y -= pDev->y0;
Offset = (GUI_ALLOC_DATATYPE_U)(y) * (GUI_ALLOC_DATATYPE_U)(pDev->BytesPerLine) + (x >> 3);
if (pBitOffset) {
*pBitOffset = 7 - (x & 7);
}
return pData + Offset;
}
/*********************************************************************
*
* _DrawBitLine1BPP
*/
static void _DrawBitLine1BPP(GUI_USAGE* pUsage, int x, int y, const U8 GUI_UNI_PTR * p, int Diff, unsigned int xsize,
const LCD_PIXELINDEX* pTrans, GUI_MEMDEV* pDev, PIXELINDEX* pDest)
{
PIXELINDEX pixels;
PIXELINDEX Index1;
unsigned int PixelCnt;
GUI_USE_PARA(pUsage);
PixelCnt = 8 - (Diff & 7);
pixels = (*p) << (Diff & 7);
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 */
do {
/* Prepare loop */
if (PixelCnt > xsize) {
PixelCnt = xsize;
}
xsize -= PixelCnt;
/* Write as many pixels as we are allowed to and have loaded in this inner loop */
do {
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(pTrans + ((U8)pixels >> 7)));
pixels <<= 1;
} while (--PixelCnt);
/* Check if an other Source byte needs to be loaded */
if (xsize == 0) {
return;
}
PixelCnt = 8;
pixels = *(++p);
} while (1);
case LCD_DRAWMODE_TRANS:
Index1 = *(pTrans + 1);
do {
/* Prepare loop */
if (PixelCnt > xsize) {
PixelCnt = xsize;
}
xsize -= PixelCnt;
while (pixels) {
if ((pixels & 0x80)) {
(*pDev->pAPIList->pfSetPixelIndex)(x, y, Index1);
}
x++;
pixels <<= 1;
if (--PixelCnt == 0) {
break;
}
}
/* Check if an other Source byte needs to be loaded */
if (xsize == 0) {
return;
}
x += PixelCnt;
PixelCnt = 8;
pixels = *(++p);
} while (1);
case LCD_DRAWMODE_XOR:;
PixelLoopXor:
if (PixelCnt > xsize) {
PixelCnt = xsize;
}
xsize -= PixelCnt;
do {
if ((pixels & 0x80)) {
(*pDev->pAPIList->pfXorPixel)(x, y);
}
x++;
pDest++;
pixels <<= 1;
} while (--PixelCnt);
if (xsize) {
PixelCnt = 8;
pixels = *(++p);
goto PixelLoopXor;
}
break;
}
}
/*********************************************************************
*
* _DrawBitLine2BPP
*/
static void _DrawBitLine2BPP(GUI_USAGE* pUsage, int x, int y, const U8 GUI_UNI_PTR * p, int Diff, int xsize,
const LCD_PIXELINDEX* pTrans, GUI_MEMDEV* pDev, PIXELINDEX* pDest)
{
U8 pixels;
U8 PixelCnt;
GUI_USE_PARA(pUsage);
GUI_USE_PARA(pDest);
PixelCnt = 4 - (Diff & 3);
pixels = (*p) << ((Diff & 3) << 1);
switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
case 0: /* Write mode */
PixelLoopWrite:
if (PixelCnt > xsize) {
PixelCnt = xsize;
}
xsize -= PixelCnt;
do {
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(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) {
(*pDev->pAPIList->pfSetPixelIndex)(x, y, *(pTrans + (pixels >> 6)));
}
x++;
pixels <<= 2;
} while (--PixelCnt);
if (xsize) {
PixelCnt = 4;
pixels = *(++p);
goto PixelLoopTrans;
}
break;
}
}
/*********************************************************************
*
* _DrawBitLine4BPP
*/
static void _DrawBitLine4BPP(GUI_USAGE* pUsage, int x, int y, const U8 GUI_UNI_PTR * p, int Diff, int xsize,
const LCD_PIXELINDEX* pTrans, GUI_MEMDEV* pDev, PIXELINDEX* pDest)
{
U8 pixels;
GUI_USE_PARA(pUsage);
GUI_USE_PARA(pDest);
pixels = (*p) << ((Diff & 1) << 2);
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) {
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(pTrans + (pixels >> 4)));
xsize--;
pixels = *++p;
}
/* Draw center area (2 pixels in one byte) */
if (xsize >= 2) {
int i = xsize >> 1;
xsize &= 1;
do {
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(pTrans + (pixels >> 4)));
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(pTrans + (pixels & 15)));
pixels = *++p;
} while (--i);
}
/* Draw incomplete bytes to the right of center area */
if (xsize) {
(*pDev->pAPIList->pfSetPixelIndex)(x++, y, *(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) {
(*pDev->pAPIList->pfSetPixelIndex)(x, y, *(pTrans + (pixels >> 4)));
}
x++;
xsize--;
pixels = *++p;
}
/* Draw center area (2 pixels in one byte) */
while (xsize >= 2) {
/* Draw 1. (left) pixel */
if (pixels & 0xF0) {
(*pDev->pAPIList->pfSetPixelIndex)(x, y, *(pTrans + (pixels >> 4)));
}
/* Draw 2. (right) pixel */
if (pixels &= 15) {
(*pDev->pAPIList->pfSetPixelIndex)(x + 1, y, *(pTrans + pixels));
}
x += 2;
xsize -= 2;
pixels = *++p;
}
/* Draw incomplete bytes to the right of center area */
if (xsize) {
if (pixels >>= 4) {
(*pDev->pAPIList->pfSetPixelIndex)(x, y, *(pTrans + pixels));
}
}
break;
}
}
/*********************************************************************
*
* _DrawBitLine8BPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -