📄 m8b_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 */
/* */
/* m8b_drv.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains 8-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/6/98 Corrected pixel addressing and */
/* added transparent raster ops. */
/* BobB 5/26/99 Corrected read image addressing */
/* BobB 6/15/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 mwPBMAB is a special case optimization for monochrome
to memory, rectangular clipping with color translation. */
void mwPBMAB(blitRcd *blitRec)
{
int Check_YX_Band_Blit(rect *bandRect, rect *blitRectPtr,
rect *clipR, int *rectCnt);
void DrawRectEntryBlit1M(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 RepDest1M8B(void);
void OXADest1M8B(void);
void SetSrcLCD(void);
void NotDestSolid1M8B(void);
void InvertSrcLCD(void);
void QuickEnd(void);
/* BobB 5/6/98 - added the following functions for transparent raster ops */
void SetTrans1M8B(void);
void InvertTrans1M8B(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;
/* BobB 5/6/98 - changed the following line to include transparent
raster ops.
dstClass = blitRec->blitRop & 0x0f; */
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 = &RepDest1M8B;
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 = &OXADest1M8B;
break;
case 8: /* zCLEARz : 0's */
case 12: /* zSETz : 1's */
optPtr = &SetSrcLCD;
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 = &NotDestSolid1M8B;
break;
case 10: /* zNOPz : dst <NOP> */
optPtr = &QuickEnd;
break;
case 14: /* zINVERTz: (NOT dst) */
optPtr = &InvertSrcLCD;
break;
/* BobB 5/6/98 - added the following cases */
/* 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 = &SetTrans1M8B;
break;
case 18: /* xXORx : !0src XOR dst */
case 27: /* xANDNx : !0src AND (NOT dst) */
case 30: /* xINVERTx: (NOT dst) */
optPtr = &InvertTrans1M8B;
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;
/* BobB 5/6/98 - added the following for the transparent raster ops */
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 = &DrawRectEntryBlit1M;
if (Blit_Clip_Region(blitRec, &dRect, &sRect)
== 0) break;
continue;
}
}
DrawRectEntryBlit1M(blitRec); /* blit the rectangle */
}
PB_RTN:
nuResume(srcBmap);
nuResume(dstBmap);
return;
}
/* Function DrawRectEntryBlit1M blits the image to the memory */
void DrawRectEntryBlit1M(blitRcd *blitRec)
{
lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
srcBgnByte = sRect.Xmin >> 3;
dstBgnByte = dRect.Xmin;
byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
/* BobB 5/6/98 - changed the following line to correct pixel addressing
srcNextRow = srcPixBytes - ((byteCntM1 + 1) >> 3); */
srcNextRow = srcPixBytes - (sRect.Xmax >> 3) + srcBgnByte;
dstNextRow = dstBmap->pixBytes - byteCntM1 - 1;
dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
srcPtr = (byte *) (*(srcBmap->mapTable[0] + sRect.Ymin))
+ srcBgnByte;
optPtr(); /* blit the rectangle */
return;
}
/* Function NotDestSolid1M8B handles M8B "not dst" by inverting the
destination first. */
void NotDestSolid1M8B(void)
{
void InvertSrcLCD(void);
void OXADest1M8B(void);
InvertSrcLCD();
OXADest1M8B(); /* fill this rectangle */
return;
}
/* Function RepDest1M8B sets the destination pixel data to pnColr
if the source is 1 else bkColr. */
void RepDest1M8B(void)
{
byte *lclDstPtr, *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
/* BobB 5/6/98 - added another variable to allow pxBit to be set inside
the first while loop. */
int pxBitVal;
lclDstPtr = dstPtr; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
/* BobB 5/6/98 - changed the following line
pxBit = 128 >> (sRect.Xmin & 7); */
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
/* BobB 5/6/98 - added the following line: */
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*lclSrcPtr & pxBit)
{ /* source is 1 */
*lclDstPtr = pnColr;
}
else
{ /* source is 0 */
*lclDstPtr = bkColr;
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* BobB 5/6/98 */
/* Function SetTrans1M8B sets the destination pixel data to pnColr
if the source is 1 else it does nothing. */
void SetTrans1M8B(void)
{
byte *lclDstPtr, *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
/* BobB 5/6/98 - added another variable to allow pxBit to be set inside
the first while loop. */
int pxBitVal;
lclDstPtr = dstPtr; /* set up local pointers */
lclSrcPtr = srcPtr;
lclLineCnt = lineCntM1;
/* BobB 5/6/98 - changed the following line
pxBit = 128 >> (sRect.Xmin & 7); */
pxBitVal = 128 >> (sRect.Xmin & 7);
while (lclLineCnt-- >= 0)
{ /* for each row */
lclByteCnt = byteCntM1;
/* BobB 5/6/98 - added the following line: */
pxBit = pxBitVal;
while (lclByteCnt-- >= 0)
{ /* for each byte in the row */
if (*lclSrcPtr & pxBit)
{ /* source is 1 */
*lclDstPtr = pnColr;
}
lclDstPtr++;
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* BobB 5/6/98 */
/* Function InvertTrans1M8B inverts the destination pixel data
if the source is 1 else it does nothing. */
void InvertTrans1M8B(void)
{
byte *lclDstPtr, *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
byte pixlVal;
lclDstPtr = dstPtr; /* 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 OXADest1M8B sets the destination pixel data based on
the logical function "OR", "XOR" or "AND". */
void OXADest1M8B(void)
{
byte *lclDstPtr, *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int logFnc;
int pxBit;
/* BobB 5/6/98 - added another variable to allow pxBit to be set inside
the first while loop. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -