📄 m16b_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 */
/* */
/* m16b_drv.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains 16-bit memory primitve driver routines. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 5/26/99 Corrected read image addressing */
/* BobB 6/14/99 Corrected write image addressing */
/* Mike Manning 9/16/99 Corrected WriteImage by calling */
/* Blit_Clip_Region() instead of */
/* Fill_Clip_Region(). Blit used */
/* and updates sRect where fill */
/* did not. sRect needed to be */
/* updated for each new piece of */
/* a region. */
/* BobB 11/10/99 Removed extra line */
/* */
/*************************************************************************/
#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 mwPBMAB16 is a special case optimization for monochrome
to memory, rectangular clipping with color translation. */
void mwPBMAB16(blitRcd *blitRec)
{
int Check_YX_Band_Blit(rect *bandRect, rect *blitRectPtr,
rect *clipR, int *rectCnt);
void DrawRectEntryBlit1M16B(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 RepDest1M16B(void);
void OXADest1M16B(void);
void SetDestM16B(void);
void NotDestSolid1M16B(void);
void InvertDestM16B(void);
void QuickEnd(void);
void SetTrans1M16B(void);
void InvertTrans1M16B(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 */
bkColr16 = (short) blitRec->blitBack; /* background color */
pnColr16 = (short) 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 = &RepDest1M16B;
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 = &OXADest1M16B;
break;
case 8: /* zCLEARz : 0's */
case 12: /* zSETz : 1's */
optPtr = &SetDestM16B;
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 = &NotDestSolid1M16B;
break;
case 10: /* zNOPz : dst <NOP> */
optPtr = &QuickEnd;
break;
case 14: /* zINVERTz: (NOT dst) */
optPtr = &InvertDestM16B;
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 = &SetTrans1M16B;
break;
case 18: /* xXORx : !0src XOR dst */
case 27: /* xANDNx : !0src AND (NOT dst) */
case 30: /* xINVERTx: (NOT dst) */
optPtr = &InvertTrans1M16B;
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 */
bkColr16 = ~bkColr16; /* this has the effect of notting the
pen color for all operations during this call */
pnColr16 = ~pnColr16;
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 */
bkColr16 = 0; /* sets all source bits to 0 */
pnColr16 = 0;
break;
case 12: /* zSETz */
case 14: /* zINVERTz */
bkColr16 = -1; /* sets all source bits to 1 */
pnColr16 = -1;
break;
default: /* all transparent cases */
break;
}
/* 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 = &DrawRectEntryBlit1M16B;
if (Blit_Clip_Region(blitRec, &dRect, &sRect)
== 0) break;
continue;
}
}
DrawRectEntryBlit1M16B(blitRec); /* blit the rectangle */
}
PB_RTN:
nuResume(srcBmap);
nuResume(dstBmap);
return;
}
/* Function DrawRectEntryBlit1M16B blits the image to the memory */
void DrawRectEntryBlit1M16B(blitRcd *blitRec)
{
lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
srcBgnByte = sRect.Xmin >> 3;
dstBgnByte = dRect.Xmin;
byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
srcNextRow = srcPixBytes - (sRect.Xmax >> 3) + srcBgnByte;
dstNextRow = (dstBmap->pixBytes >> 1) - byteCntM1 - 1;
dstPtr16 = (word *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
srcPtr = (byte *) (*(srcBmap->mapTable[0] + sRect.Ymin))
+ srcBgnByte;
optPtr(); /* blit the rectangle */
return;
}
/* Function NotDestSolid1M16B handles M16B "not dst" by inverting the
destination first. */
void NotDestSolid1M16B(void)
{
void InvertDestM16B(void);
void OXADest1M16B(void);
InvertDestM16B();
OXADest1M16B(); /* fill this rectangle */
return;
}
/* Function RepDest1M16B sets the destination pixel data to pnColr16
if the source is 1 else bkColr16. */
void RepDest1M16B(void)
{
word *lclDstPtr;
byte *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
lclDstPtr = dstPtr16; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*lclSrcPtr & pxBit)
{ /* source is 1 */
*lclDstPtr = pnColr16;
}
else
{ /* source is 0 */
*lclDstPtr = bkColr16;
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* Function SetTrans1M16B sets the destination pixel data to pnColr16
if the source is 1 else it does nothing. */
void SetTrans1M16B(void)
{
word *lclDstPtr;
byte *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
lclDstPtr = dstPtr16; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*lclSrcPtr & pxBit)
{ /* source is 1 */
*lclDstPtr = pnColr16;
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* Function InvertTrans1M16B inverts the destination pixel data
if the source is 1 else it does nothing. */
void InvertTrans1M16B(void)
{
word *lclDstPtr;
byte *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
word pixlVal;
lclDstPtr = dstPtr16; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*lclSrcPtr & pxBit)
{ /* source is 1 */
pixlVal = *lclDstPtr;
*lclDstPtr = ~pixlVal;
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* Function OXADest1M16B sets the destination pixel data based on
the logical function "OR", "XOR" or "AND". */
void OXADest1M16B(void)
{
word *lclDstPtr;
byte *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int logFnc;
int pxBit;
int pxBitVal;
lclDstPtr = dstPtr16; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
logFnc = (dstClass & 3); /* only two lower bits needed */
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (!(*lclSrcPtr & pxBit))
{ /* source is 0 */
if ((logFnc == 3) || (*lclDstPtr == 0))
{ /* "AND" or 0,0 */
*lclDstPtr = bkColr16;
}
else
{ /* "OR","XOR" with 0,1 */
*lclDstPtr = pnColr16;
}
}
else
{ /* source is 1 */
if (logFnc == 1)
{ /* "OR" with 1,X */
*lclDstPtr = pnColr16;
}
else
{
if (logFnc == 3)
{ /* "AND" */
if (*lclDstPtr)
{ /* "AND", with 1,1 */
*lclDstPtr = pnColr16;
}
else
{ /* "AND", with 1,0 */
*lclDstPtr = bkColr16;
}
}
else
{ /* "XOR" */
if (*lclDstPtr)
{ /* "XOR", with 1,1 */
*lclDstPtr = bkColr16;
}
else
{ /* "XOR", with 1,0 */
*lclDstPtr = pnColr16;
}
}
}
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -