📄 sd0108.h
字号:
//
// Windows CE Software Graphics Library
// sd0108.h
//
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
// This header file contains the function template for special case blit
// routines with 1 bit source and 8 bit destination surfaces. This code
// does not stretch, colorkey, mask, clip, or blend.
#if !defined(FUNCTION)
#error Must define FUNCTION
#endif
#if !defined(BYTE_OP)
#error Must define BYTE_OP
#endif
BOOL
FUNCTION(
BLT_PARAM * Parameters
)
{
// Local variables.
// Source-related info.
const RECT * SrcRect = Parameters->SourceRect;
LONG SrcScanStride = Parameters->Source->Stride;
BYTE * SrcScanLine = (BYTE *)Parameters->Source->Ptr +
SrcRect->top * SrcScanStride +
(SrcRect->left >> 3);
// Destination-related info.
const RECT * DstRect = Parameters->DestRect;
LONG DstScanStride = Parameters->Destination->Stride;
BYTE * DstScanLine = (BYTE *)Parameters->Destination->Ptr +
DstRect->top * DstScanStride +
DstRect->left;
ULONG SourceColors[2];
ULONG Rows = RectHeight(DstRect);
ULONG Cols = 0;
ULONG FirstBit;
ULONG StartAlignment;
ULONG EndAlignment;
ULONG WholeCols;
ULONG Preshift;
ULONG Row, Col;
BYTE * SrcPixel;
BYTE * DstPixel;
register BYTE SrcValue;
// Check parameters.
// !TODO!
FirstBit = (8 - (SrcRect->left & 0x7));
if (Cols >= 8) {
// We know that we will make at least one byte boundary, and hence
// do not need a preshift, we need only read to the boundary.
Preshift = 0;
StartAlignment = FirstBit & 0x7;
}
else {
// All of the bits we need are within a single byte. (eg. Cols should
// never be greater than FirstBit here: that would imply that we are
// crossing a byte boundary.)
Preshift = FirstBit - Cols;
StartAlignment = Cols;
}
WholeCols = (Cols - StartAlignment) >> 3;
EndAlignment = (Cols - StartAlignment) & 0x7;
// Lookup the palette for the source surface for use in calling the
// BYTE_OP macro.
if (!InitColorConverter(Parameters->Source->Format,
Parameters->Destination->Format)) {
return FALSE;
}
SourceColors[0] = ColorConvert(0);
SourceColors[1] = ColorConvert(1);
CleanupColorConverter();
for (Row = 0; Row < Rows; Row++) {
// Set up pointers to first bytes on source and destination scanlines.
SrcPixel = SrcScanLine;
DstPixel = DstScanLine;
// Do the unaligned first couple bits.
SrcValue = (*SrcPixel) >> Preshift;
switch (StartAlignment) {
case 7:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 6) & 0x1]);
case 6:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 5) & 0x1]);
case 5:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 4) & 0x1]);
case 4:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 3) & 0x1]);
case 3:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 2) & 0x1]);
case 2:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 1) & 0x1]);
case 1:
*DstPixel++ = BYTE_OP(*DstPixel, (BYTE)SourceColors[SrcValue & 0x1]);
SrcPixel++;
}
// Do the main aligned loop.
for (Col = 0; Col < WholeCols; Col++ ) {
SrcValue = *SrcPixel;
*(DstPixel + 7) = BYTE_OP(*(DstPixel + 7), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 6) = BYTE_OP(*(DstPixel + 6), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 5) = BYTE_OP(*(DstPixel + 5), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 4) = BYTE_OP(*(DstPixel + 4), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 3) = BYTE_OP(*(DstPixel + 3), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 2) = BYTE_OP(*(DstPixel + 2), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel + 1) = BYTE_OP(*(DstPixel + 1), (BYTE)SourceColors[SrcValue & 0x1]);
SrcValue = SrcValue >> 1;
*(DstPixel) = BYTE_OP(*DstPixel, (BYTE)SourceColors[SrcValue & 0x1]);
DstPixel += 8;
SrcPixel++;
}
// Do the unaligned end bits.
SrcValue = *SrcPixel;
switch (EndAlignment) {
case 7: *(DstPixel + 6) = BYTE_OP(*(DstPixel + 6), (BYTE)SourceColors[(SrcValue >> 1) & 0x1]);
case 6: *(DstPixel + 5) = BYTE_OP(*(DstPixel + 5), (BYTE)SourceColors[(SrcValue >> 2) & 0x1]);
case 5: *(DstPixel + 4) = BYTE_OP(*(DstPixel + 4), (BYTE)SourceColors[(SrcValue >> 3) & 0x1]);
case 4: *(DstPixel + 3) = BYTE_OP(*(DstPixel + 3), (BYTE)SourceColors[(SrcValue >> 4) & 0x1]);
case 3: *(DstPixel + 2) = BYTE_OP(*(DstPixel + 2), (BYTE)SourceColors[(SrcValue >> 5) & 0x1]);
case 2: *(DstPixel + 1) = BYTE_OP(*(DstPixel + 1), (BYTE)SourceColors[(SrcValue >> 6) & 0x1]);
case 1: *DstPixel = BYTE_OP(*DstPixel, (BYTE)SourceColors[(SrcValue >> 7) & 0x1]);
case 0: break;
}
// Advance to next scanline.
SrcScanLine += SrcScanStride;
DstScanLine += DstScanStride;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -