📄 vram.c
字号:
}
else // 超过一个整单位
{
#ifdef BIG_ENDIAN_ORDER
mask = MAKEMASK( 32 - desBitOffset );
#else
mask = ~MAKEMASK( desBitOffset );
#endif
(*pixelPos) ^= mask;
pixelPos++;
for( i = 1; i < num; i++, pixelPos++ )
(*pixelPos) ^= unitMask;
if( r != 0 ) // 尾部
{
#ifdef BIG_ENDIAN_ORDER
mask = ~MAKEMASK( 32 - r );
#else
mask = MAKEMASK( r );
#endif
(*pixelPos) ^= mask;
}
}
}
else // 起始边界对齐
{
for( i = 0; i < num; i++, pixelPos++ )
(*pixelPos) ^= unitMask;
if( r != 0 ) // 尾部
{
#ifdef BIG_ENDIAN_ORDER
mask = ~MAKEMASK( 32 - r );
#else
mask = MAKEMASK( r );
#endif
(*pixelPos) ^= mask;
}
}
}
void LineUnicolorMaskOp( PIXEL *desLinePos, CHAR desBitOffset, WORD len, PIXEL srcValue, WORD mask, WORD op )
{
PIXEL *pixelPos;
PIXEL unitValue = srcValue;
WORD i, enBit = 0;
CHAR bitOffset;
pixelPos = desLinePos;
bitOffset = desBitOffset;
for( i = 0; i < len; i++ )
{
if( enBit == 0 )
enBit = 0x8000;
if( enBit & mask )
PixelOp( pixelPos, bitOffset, srcValue, op );
GetNextPixelPosition( &pixelPos, &bitOffset, pixelPos, bitOffset );
enBit = enBit >> 1;
}
}
//LineOp 对指定的两行进行逻辑操作(包括按位与、或、异或、复制等)
//以16比特为一组
void LineOp( PIXEL *desLinePos, CHAR desBitOffset, PIXEL *srcLinePos, CHAR srcBitOffset, WORD len, WORD op )
{
WORD i;
WORD *srcPos = (WORD *)srcLinePos, *desPos = (WORD *)desLinePos;
WORD mask;
DWORD totalOffset, num, r;
if( ( (DWORD)srcPos ) & 0x1 ) // 奇地址
{
srcPos = (WORD *)( ((DWORD)srcPos) -1 );
srcBitOffset += 8;
}
if( ( (DWORD)desPos ) & 0x1 ) // 奇地址
{
desPos = (WORD *)( ((DWORD)desPos) -1 );
desBitOffset += 8;
}
totalOffset = ( len << LOG_PIXEL_BITS ) + desBitOffset; // 要求一行的像素个数小于1023
num = totalOffset >> 4;
r = totalOffset & 0xf; // 尾比特数
if( num == 0 ) // 像素尺寸小于剩余单位
{
WORD tempValue;
#ifdef BIG_ENDIAN_ORDER
mask = MAKEMASK( totalOffset - desBitOffset ) << ( 16 - totalOffset );
#else
mask = MAKEMASK( totalOffset - desBitOffset ) << desBitOffset;
#endif
if( srcBitOffset <= desBitOffset )
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (*srcPos) >> ( desBitOffset - srcBitOffset );
#else
tempValue = (*srcPos) << ( desBitOffset - srcBitOffset );
#endif
UnitMaskOp( desPos, tempValue, mask, op );
}
else
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) << ( srcBitOffset - desBitOffset ) ) >> 16 );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> ( srcBitOffset - desBitOffset ) ) & 0xffff );
#endif
UnitMaskOp( desPos, tempValue, mask, op );
}
}
else // 其他
{
if( desBitOffset == srcBitOffset ) // 边界对齐
{
#ifdef BIG_ENDIAN_ORDER
mask = MAKEMASK( 16 - srcBitOffset );
#else
mask = ~MAKEMASK( srcBitOffset );
#endif
UnitMaskOp( desPos, *srcPos, mask, op );
desPos++;
srcPos++;
switch( op )
{
case GPC_REPLACE_STYLE:
case GPC_COPY_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
(*desPos) = (*srcPos);
break;
case GPC_XOR_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
(*desPos) ^= (*srcPos);
break;
case GPC_AND_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
(*desPos) &= (*srcPos);
break;
case GPC_OR_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
(*desPos) |= (*srcPos);
break;
default:
break;
}
#ifdef BIG_ENDIAN_ORDER
mask = ~MAKEMASK( 16 - r );
#else
mask = MAKEMASK( r );
#endif
UnitMaskOp( desPos, *srcPos, mask, op );
}
else // 边界不对齐
{
WORD tempValue, t;
if( desBitOffset < srcBitOffset )
{
t = srcBitOffset - desBitOffset;
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> ( 16 - t ) ) );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
}
else
{
t = desBitOffset - srcBitOffset;
#ifdef BIG_ENDIAN_ORDER
tempValue = (*srcPos) >> t;
#else
tempValue = (*srcPos) << t;
#endif
}
#ifdef BIG_ENDIAN_ORDER
mask = MAKEMASK( 16 - desBitOffset );
#else
mask = ~MAKEMASK( desBitOffset );
#endif
UnitMaskOp( desPos, tempValue, mask, op );
desPos++;
if( desBitOffset < srcBitOffset )
{
srcPos++;
#ifdef BIG_ENDIAN_ORDER
t = 16 - t;
#endif
}
else
{
#ifdef BIG_ENDIAN_ORDER
#else
t = 16 - t;
#endif
}
switch( op )
{
case GPC_REPLACE_STYLE:
case GPC_COPY_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
(*desPos) = tempValue;
}
break;
case GPC_XOR_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
(*desPos) ^= tempValue;
}
break;
case GPC_AND_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
(*desPos) &= tempValue;
}
break;
case GPC_OR_STYLE:
for( i = 1; i < num; i++, desPos++, srcPos++ )
{
#ifdef BIG_ENDIAN_ORDER
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#else
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
(*desPos) |= tempValue;
}
break;
default:
break;
}
#ifdef BIG_ENDIAN_ORDER
mask = ~MAKEMASK( 16 - r );
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );//old
// tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> ( 16 - t ) ) );
#else
mask = MAKEMASK( r );
tempValue = (WORD)( ( (*((DWORD *)srcPos)) >> t ) );
#endif
UnitMaskOp( desPos, tempValue, mask, op );
}
}
}
//BlockUnicolorOP 对指定块进行单色逻辑操作(包括按位与、或、异或、复制等)
void BlockUnicolorOp( PIXEL *desLinePos, CHAR desBitOffset, WORD width, WORD height, PIXEL srcValue, WORD op, VRAM *vram )
{
PIXEL *curPos = desLinePos;
// PIXEL *nextPos;
CHAR curBitOffset = desBitOffset;
// CHAR nextBitOffset;
WORD i;
for( i = 0; i < height; i++ )
{
LineUnicolorOp( curPos, curBitOffset, width, srcValue, op );
GetNextLine( &curPos, &curBitOffset, curPos, curBitOffset, vram );
// curPos = nextPos;
// curBitOffset = nextBitOffset;
}
}
void BlockUnicolorMaskOp( PIXEL *desLinePos, CHAR desBitOffset, WORD width, WORD height, PIXEL srcValue, WORD mask, WORD op, VRAM *vram )
{
PIXEL *curPos = desLinePos;
// PIXEL *nextPos;
CHAR curBitOffset = desBitOffset;
// CHAR nextBitOffset;
WORD i;
for( i = 0; i < height; i++ )
{
LineUnicolorMaskOp( curPos, curBitOffset, width, srcValue, mask, op );
GetNextLine( &curPos, &curBitOffset, curPos, curBitOffset, vram );
// curPos = nextPos;
// curBitOffset = nextBitOffset;
}
}
//InvertBlock 对指定块进行反色操作
void InvertBlock( PIXEL *desLinePos, CHAR desBitOffset, WORD width, WORD height, VRAM *vram )
{
PIXEL *curPos = desLinePos;
// PIXEL *nextPos;
CHAR curBitOffset = desBitOffset;
// CHAR nextBitOffset;
WORD i;
for( i = 0; i < height; i++ )
{
InvertLine( curPos, curBitOffset, width );
GetNextLine( &curPos, &curBitOffset, curPos, curBitOffset, vram );
// curPos = nextPos;
// curBitOffset = nextBitOffset;
}
}
//BlockOP 对指定的两块区域进行逻辑操作(包括按位与、或、异或、复制等)
void BlockOp( PIXEL *desLinePos, CHAR desBitOffset, PIXEL *srcLinePos, CHAR srcBitOffset, WORD width, WORD height, WORD op, VRAM *desVram, VRAM *srcVram )
{
PIXEL *curDesPos = desLinePos, *curSrcPos = srcLinePos;
// PIXEL *nextDesPos, *nextSrcPos;
CHAR curDesOffset = desBitOffset, curSrcOffset = srcBitOffset;
// CHAR nextDesOffset, nextSrcOffset;
WORD i;
for( i = 0; i < height; i++ )
{
LineOp( curDesPos, curDesOffset, curSrcPos, curSrcOffset, width, op );
GetNextLine( &curDesPos, &curDesOffset, curDesPos, curDesOffset, desVram );
GetNextLine( &curSrcPos, &curSrcOffset, curSrcPos, curSrcOffset, srcVram );
// curDesPos = nextDesPos;
// curDesOffset = nextDesOffset;
// curSrcPos = nextSrcPos;
// curSrcOffset = nextSrcOffset;
}
}
//---------------functions for test------------------------
//GetVRAM 申请一块指定大小的vram
VRAM *GetVRAM( WORD width, WORD height )
{
VRAM *vram;
DWORD size;
vram = (VRAM *)SysLmalloc( sizeof( VRAM ) );
if( vram == NULL )
return NULL;
vram->widthInPixel = width;
vram->widthInBit = width << LOG_PIXEL_BITS;
vram->widthInUnit = ( vram->widthInBit + PIXEL_UNIT -1 ) >> LOG_UNIT;
vram->height = height;
vram->lcdx = 0;
vram->lcdy = 0;
size = vram->widthInUnit * vram->height << LOG_UNIT_BYTE;
vram->ad = ( PIXEL * )SysLmalloc( size );
if( vram->ad == NULL )
return NULL;
else
{
memset( vram->ad, 0xff, size );
return vram;
}
}
//GetVRAMSize 获取指定vram的大小(字节单位)
DWORD GetVRAMSize( VRAM *vram )
{
DWORD size;
if( vram == NULL )
return 0;
size = vram->widthInUnit * vram->height << LOG_UNIT_BYTE;
return size;
}
//GetBlock 申请一块指定大小的vram
PIXEL *GetBlock( WORD width, WORD height )
{
PIXEL *block;
DWORD size;
size = ( ( width * BITS_PER_PIXEL + PIXEL_UNIT -1 ) >> ( LOG_UNIT - LOG_UNIT_BYTE ) ) * height;
block = ( PIXEL * )SysLmalloc( size );
if( block == NULL )
return NULL;
else
return block;
}
//FreeVRAM 释放一块指定的vram
void FreeVRAM( VRAM *vram )
{
if( vram == NULL )
return;
if( vram->ad != NULL )
SysLfree( vram->ad );
SysLfree( vram );
return;
}
/*
void VRAMMap( WORD *x2, WORD *y2, WORD x1, WORD y1, VRAM *vram )
{
*x2 = x1 < vram->lcdx ? 0 : x1 - vram->lcdx;
*y2 = y1 < vram->lcdy ? 0 : y1 - vram->lcdy;
if( *x2 >= vram->widthInPixel )
*x2 = vram->widthInPixel -1;
if( *y2 >= vram->height )
*y2 = vram->height -1;
}
*/
/////////////////////////////////////////////////////////////////////////////////
void LinearColorMap( BYTE *color, BYTE index, BYTE maxColor, BYTE maxIndex)
{
//if( index > maxIndex || !maxIndex || !maxColor )
// return E_PAR;
if( maxIndex == maxColor )
*color = index;
else
*color = index * maxColor / maxIndex;
return;
}
///////////////////////////////////////////////////////////////////////////////////
void Unit1to2Op( PIXEL *desPos, CHAR desBitOffset, BYTE mask, WORD FrColor, WORD BkColor, WORD op )
{
WORD Value;
WORD index;
Value = maskEx[mask];
index = (WORD)( Value & ColorPalette[FrColor] );
index |= ~Value & ColorPalette[BkColor];
LineOp( desPos, desBitOffset, (PIXEL *)(&index), 0, 8, op );
}
#endif
#endif
#ifdef COLOR_PDA
/************************************
*
*
*
*
*
* FUNCTION LIST
* GetPixel 获取指定位置的像素值
* GetPixelPosition 获取指定像素的物理地址
* GetNextPixel 获取指定像素的下一个像素值
* GetNextPixelPosition 获取指定像素的下一个像素的物理地址
* GetLine 获取指定行的行首像素的物理地址
* GetNextLine 获取指定行的下一行的行首像素的物理地址(同列)
* SetPixel 设置指定像素的值
* PixelOp 对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
* PixelMaskOp 利用掩码对指定像素进行逻辑操作(包括按位与、或、异或、复制等)
* SetLine 设置指定行的值
* LineUnicolorOp 对指定行进行单色逻辑操作(包括按位与、或、异或、复制等)
* LineOp 对指定的两行进行逻辑操作(包括按位与、或、异或、复制等)
* BlockUnicolorOP 对指定块进行单色逻辑操作(包括按位与、或、异或、复制等)
* BlockOP 对指定的两块区域进行逻辑操作(包括按位与、或、异或、复制等)
*
*
*
*
***********************************************************************/
#if BITS_PER_PIXEL >= 8
PIXEL INDEX_RED_MASK = MAKEMASK( INDEX_RED_BITS );
PIXEL INDEX_GREEN_MASK = MAKEMASK( INDEX_GREEN_BITS );
PIXEL INDEX_BLUE_MASK = MAKEMASK( INDEX_BLUE_BITS );
const PIXEL PixelMask =
( MAKEMASK( INDEX_RED_BITS ) << INDEX_RED_OFFSET ) |
( MAKEMASK( INDEX_GREEN_BITS ) << INDEX_GREEN_OFFSET ) |
( MAKEMASK( INDEX_BLUE_BITS ) << INDEX_BLUE_OFFSET );
#else
PIXEL PixelMask = MAKEMASK( BITS_PER_PIXEL );
#endif
#if ( BITS_PER_PIXEL == 2 ) //特化
PIXEL ByteMask2[4] = { 0x03, 0x0c, 0x30, 0xc0 };
#endif
//关于vram的操作
//GetPixel 获取指定位置的像素值
void newGetPixel( PIXEL *pixelValue, PIXEL *pixelPos, CHAR bitOffset )
{
#if BITS_PER_PIXEL == PIXEL_BIT_DEPTH // 像素存储无冗余
#if ( BITS_PER_PIXEL != PIXEL_UNIT) // 非整单位像素
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -