📄 m2b4_drv.c
字号:
/*************************************************************************/
/* */
/* Copyright (c) 1997 - 1999 Accelerated Technology, Inc. */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are governed */
/* by the license agreement. The recipient of this software implicitly */
/* accepts the terms of the license. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* m2b4_drv.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains 2/4-bit memory primitve driver routines. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 12/29/98 Corrected set pixel */
/* BobB 1/15/99 Corrected image shifting */
/* */
/*************************************************************************/
#include "meta_wnd.h"
#include "metconst.h" /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h" /* MetaWINDOW Port & Bitmap Definitions */
#include "metaproc.h"
#include "grafdata.h"
#include "regclipv.h"
#include "blit_5.h"
/* Function mwPB1S2_4B is a special case optimization for monochrome
to memory, rectangular clipping with color translation. */
void mwPB1S2_4B(blitRcd *blitRec)
{
int Check_YX_Band_Blit(rect *bandRect, rect *blitRectPtr,
rect *clipR, int *rectCnt);
void DrawRectEntryBlit1M2_4B(blitRcd *blitRec);
int Set_Up_Clip(blitRcd *clipBlit, rect *clipR, int blitMayOverlap,
int isLine);
int Blit_Clip_Region(blitRcd *fcRec, rect *fillRect, rect *sRect);
void nuResume(grafMap *srcBmap);
void RepDest1M2_4B(void);
void OXADest1M2_4B(void);
void SetDestM2_4B(void);
void NotDestSolid1M2_4B(void);
void InvertDestM2_4B(void);
void QuickEnd(void);
void SetTrans1M2_4B(void);
void InvertTrans1M2_4B(void);
rect clipR; /* Clip rect */
rect *rListPtr; /* list pointer */
int blitMayOverlap = 0; /* Set false for region clipping*/
int isLine = 0; /* Set false */
rectCnt = blitRec->blitCnt;
rListPtr = (rect *) blitRec->blitList;
srcBmap = blitRec->blitSmap;
srcPixBytes = srcBmap->pixBytes;
M_PAUSE(srcBmap); /* pause the source */
bkColr = (char) blitRec->blitBack; /* background color */
pnColr = (char) blitRec->blitFore; /* foreground color */
dstBmap = blitRec->blitDmap;
dstClass = blitRec->blitRop & 0x1f;
M_PAUSE(dstBmap);
switch (dstClass)
{ /* look up the optimization routine */
/* Memory non-transparent */
case 0: /* zREPz : src */
case 4: /* zNREPz : (NOT src) */
optPtr = &RepDest1M2_4B;
break;
case 1: /* zORz : src OR dst */
case 2: /* zXORz : src XOR dst */
case 3: /* zNANDz : (NOT src) AND dst */
case 5: /* zNORz : (NOT src) OR dst */
case 6: /* zNXORz : (NOT src) XOR dst */
case 7: /* zANDz : src AND dst */
optPtr = &OXADest1M2_4B;
break;
case 8: /* zCLEARz : 0's */
case 12: /* zSETz : 1's */
optPtr = &SetDestM2_4B;
break;
case 9: /* zORNz : src OR (NOT dst) */
case 11: /* zANDNz : src AND (NOT dst) */
case 13: /* zNORNz : (NOT src) OR (NOT dst) */
case 15: /* zNANDNz : (NOT src) AND (NOT dst) */
optPtr = &NotDestSolid1M2_4B;
break;
case 10: /* zNOPz : dst <NOP> */
optPtr = &QuickEnd;
break;
case 14: /* zINVERTz: (NOT dst) */
optPtr = &InvertDestM2_4B;
break;
/* Memory transparent */
case 16: /* xREPx : !0src */
case 17: /* xORx : !0src OR dst */
case 25: /* xORNx : !0src OR (NOT dst) */
case 28: /* xSETx : 1's */
optPtr = &SetTrans1M2_4B;
break;
case 18: /* xXORx : !0src XOR dst */
case 27: /* xANDNx : !0src AND (NOT dst) */
case 30: /* xINVERTx: (NOT dst) */
optPtr = &InvertTrans1M2_4B;
break;
case 19: /* xNANDx : (NOT !0src) AND dst */
case 20: /* xNREPx : (NOT !0src) */
case 21: /* xNORx : (NOT !0src) OR dst */
case 22: /* xNXORx : (NOT !0src) XOR dst */
case 23: /* xANDx : !0src AND dst */
case 24: /* xCLEARx : 0's */
case 26: /* xNOPx : dst <NOP> */
case 29: /* xNORNx : (NOT !0src) OR (NOT dst) */
case 31: /* xNANDNx : (NOT !0src) AND (NOT dst) */
optPtr = &QuickEnd;
break;
}
/* modify the pen color as necessary */
switch (dstClass)
{
case 3: /* zNANDz */
case 4: /* zNREPz */
case 5: /* zNORz */
case 6: /* zNXORz */
case 13: /* zNORNz */
case 15: /* zNANDNz */
bkColr = ~bkColr; /* this has the effect of notting the
pen color for all operations during this call */
pnColr = ~pnColr;
case 0: /* zREPz */
case 1: /* zORz */
case 2: /* zXORz */
case 7: /* zANDz */
case 9: /* zORNz */
case 10: /* zNOPz */
case 11: /* zANDNz */
break;
case 8: /* zCLEARz */
bkColr = 0; /* sets all source bits to 0 */
pnColr = 0;
break;
case 12: /* zSETz */
case 14: /* zINVERTz */
bkColr = (char)-1; /* sets all source bits to 1 */
pnColr = (char)-1;
break;
default: /* all transparent cases */
break;
}
dstWidth = dstBmap->pixBytes;
shfCnt = dstBmap->pixBits; /* determine number of bits per pixel */
if (shfCnt == 2)
{ /* 2 bpp */
flipMask = 2;
shiftMask = 0xc0;
firstOffset = 0x03;
pnColr = pnColr & 0x03;
pnColr = pnColr | (pnColr << 2);
pnColr = pnColr | (pnColr << 4);
bkColr = bkColr & 0x03;
bkColr = bkColr | (bkColr << 2);
bkColr = bkColr | (bkColr << 4);
}
else
{ /* 4 bpp */
flipMask = 1;
shiftMask = 0xf0;
firstOffset = 0x01;
pnColr = pnColr & 0x0f;
pnColr = pnColr | (pnColr << 4);
bkColr = bkColr & 0x0f;
bkColr = bkColr | (bkColr << 4);
}
/* set up clipping */
if (Set_Up_Clip(blitRec, &clipR, blitMayOverlap, isLine))
goto PB_RTN;
while (--rectCnt >= 0 )
{
sRect = *rListPtr++;
dRect = *rListPtr++;
if (clipToRectFlag != 0) /* do we need to worry about clipping */
{ /* yes, do trivial reject */
if (dRect.Xmin < clipR.Xmin)
{ /* Reset src & dst Xmin clip limit */
sRect.Xmin -= (dRect.Xmin - clipR.Xmin);
dRect.Xmin = clipR.Xmin;
}
if (dRect.Ymin < clipR.Ymin)
{ /* Reset src & dst Ymin clip limit */
sRect.Ymin -= (dRect.Ymin - clipR.Ymin);
dRect.Ymin = clipR.Ymin;
}
if (dRect.Xmax > clipR.Xmax)
{ /* Reset src & dst Xmax clip limit */
sRect.Xmax -= (dRect.Xmax - clipR.Xmax);
dRect.Xmax = clipR.Xmax;
}
if (dRect.Ymax > clipR.Ymax)
{ /* Reset src & dst Ymax clip limit */
sRect.Ymax -= (dRect.Ymax - clipR.Ymax);
dRect.Ymax = clipR.Ymax;
}
if (dRect.Ymin >= dRect.Ymax)
{ /* Check to see whether the rectangle was trivially
clipped because it was fully below the clip rect,
in which case we can discard the rest of a YX banded
blitList, or because it was fully above the clip
rect, in which case we can whiz ahead through a YX
banded blitList until we run out of rects or find a
rect that isn't fully above the clip rect. */
if (Check_YX_Band_Blit(&dRect, rListPtr, &clipR,
&rectCnt)) break;
continue;
}
if (dRect.Xmin >= dRect.Xmax) continue;
/* do we need to worry about region clipping? */
if (clipToRegionFlag != 0)
{ /* yes */
FillDrawer = &DrawRectEntryBlit1M2_4B;
if (Blit_Clip_Region(blitRec, &dRect, &sRect)
== 0) break;
continue;
}
}
DrawRectEntryBlit1M2_4B(blitRec); /* blit the rectangle */
}
PB_RTN:
nuResume(srcBmap);
nuResume(dstBmap);
return;
}
/* Function DrawRectEntryBlit1M2_4B blits the image to the memory */
void DrawRectEntryBlit1M2_4B(blitRcd *blitRec)
{
lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
srcBgnByte = sRect.Xmin >> 3;
dstBgnByte = (dRect.Xmin >> flipMask);
byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
srcNextRow = srcPixBytes - (sRect.Xmax >> 3) + srcBgnByte;
srcPtr = (byte *) (*(srcBmap->mapTable[0] + sRect.Ymin))
+ srcBgnByte;
optPtr(); /* blit the rectangle */
return;
}
/* Function NotDestSolid1M2_4B handles M2_4B "not dst" by inverting the
destination first. */
void NotDestSolid1M2_4B(void)
{
void InvertDestM2_4B(void);
void OXADest1M2_4B(void);
InvertDestM2_4B();
OXADest1M2_4B(); /* fill this rectangle */
return;
}
/* Function RepDest1M2_4B sets the destination pixel data to pnColr
if the source is 1 else bkColr. */
void RepDest1M2_4B(void)
{
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
int pxShift;
byte dstPxBit;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
dstPxBit = (byte) (shiftMask >> pxShift);
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*srcPtr & pxBit)
{ /* source is 1 */
*dstPtr = (*dstPtr & ~dstPxBit) | (dstPxBit & pnColr);
}
else
{ /* source is 0 */
*dstPtr = (*dstPtr & ~dstPxBit) | (dstPxBit & bkColr);
}
dstPxBit = (dstPxBit >> shfCnt);
if (dstPxBit == 0)
{ /* advance to next byte */
dstPtr++;
if (shfCnt == 2)
{
dstPxBit = 0xc0;
}
else
{
dstPxBit = 0xf0;
}
}
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
srcPtr++;
}
}
dRect.Ymin++; /* advance to next row */
srcPtr += srcNextRow;
}
return;
}
/* Function SetTrans1M2_4B sets the destination pixel data to pnColr
if the source is 1 else it does nothing. */
void SetTrans1M2_4B(void)
{
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
int pxShift;
byte dstPxBit;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
dstPxBit = (byte) (shiftMask >> pxShift);
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*srcPtr & pxBit)
{ /* source is 1 */
*dstPtr = (*dstPtr & ~dstPxBit) | (dstPxBit & pnColr);
}
dstPxBit = (dstPxBit >> shfCnt);
if (dstPxBit == 0)
{ /* advance to next byte */
dstPtr++;
if (shfCnt == 2)
{
dstPxBit = 0xc0;
}
else
{
dstPxBit = 0xf0;
}
}
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
srcPtr++;
}
}
dRect.Ymin++; /* advance to next row */
srcPtr += srcNextRow;
}
return;
}
/* Function InvertTrans1M2_4B inverts the destination pixel data
if the source is 1 else it does nothing. */
void InvertTrans1M2_4B(void)
{
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
int pxShift;
byte dstPxBit;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
dstPxBit = (byte) (shiftMask >> pxShift);
while (lclByteCnt-- >= 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -