📄 m24b_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 */
/* */
/* m24b_drv.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains 24-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/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. */
/* */
/*************************************************************************/
#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 mwPBMAB24 is a special case optimization for monochrome
to 24-bit memory, rectangular clipping with color translation. */
void mwPBMAB24(blitRcd *blitRec)
{
int Check_YX_Band_Blit(rect *bandRect, rect *blitRectPtr,
rect *clipR, int *rectCnt);
void DrawRectEntryBlit1M24(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 RepDest1M24B(void);
void OXADest1M24B(void);
void SetDestM24B(void);
void NotDestSolid1M24B(void);
void InvertDestM24B(void);
void QuickEnd(void);
void SetTrans1M24B(void);
void InvertTrans1M24B(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 */
bkColr24 = blitRec->blitBack; /* background color */
pnColr24 = 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 = &RepDest1M24B;
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 = &OXADest1M24B;
break;
case 8: /* zCLEARz : 0's */
case 12: /* zSETz : 1's */
optPtr = &SetDestM24B;
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 = &NotDestSolid1M24B;
break;
case 10: /* zNOPz : dst <NOP> */
optPtr = &QuickEnd;
break;
case 14: /* zINVERTz: (NOT dst) */
optPtr = &InvertDestM24B;
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 = &SetTrans1M24B;
break;
case 18: /* xXORx : !0src XOR dst */
case 27: /* xANDNx : !0src AND (NOT dst) */
case 30: /* xINVERTx: (NOT dst) */
optPtr = &InvertTrans1M24B;
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 */
bkColr24 = ~bkColr24; /* this has the effect of notting the
pen color for all operations during this call */
pnColr24 = ~pnColr24;
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 */
bkColr24 = 0; /* sets all source bits to 0 */
pnColr24 = 0;
break;
case 12: /* zSETz */
case 14: /* zINVERTz */
bkColr24 = -1; /* sets all source bits to 1 */
pnColr24 = -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 = &DrawRectEntryBlit1M24;
if (Blit_Clip_Region(blitRec, &dRect, &sRect)
== 0) break;
continue;
}
}
DrawRectEntryBlit1M24(blitRec); /* blit the rectangle */
}
PB_RTN:
nuResume(srcBmap);
nuResume(dstBmap);
return;
}
/* Function DrawRectEntryBlit1M24 blits the image to the memory */
void DrawRectEntryBlit1M24(blitRcd *blitRec)
{
lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
srcBgnByte = sRect.Xmin >> 3;
dstBgnByte = 3 * dRect.Xmin;
byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
srcNextRow = srcPixBytes - (sRect.Xmax >> 3) + srcBgnByte;
dstNextRow = dstBmap->pixBytes - (3 * byteCntM1) - 3;
dstPtr = (byte *) (*(dstBmap->mapTable[0] + dRect.Ymin))
+ dstBgnByte;
srcPtr = (byte *) (*(srcBmap->mapTable[0] + sRect.Ymin))
+ srcBgnByte;
optPtr(); /* blit the rectangle */
return;
}
/* Function NotDestSolid1M24B handles M24B "not dst" by inverting the
destination first. */
void NotDestSolid1M24B(void)
{
void InvertDestM24B(void);
void OXADest1M24B(void);
InvertDestM24B();
OXADest1M24B(); /* fill this rectangle */
return;
}
/* Function RepDest1M24B sets the destination pixel data to pnColr24
if the source is 1 else bkColr24. */
void RepDest1M24B(void)
{
byte *lclDstPtr, pnColrR, pnColrG, pnColrB;
byte *lclSrcPtr, bkColrR, bkColrG, bkColrB;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
lclDstPtr = dstPtr; /* set up local pointers */
lclSrcPtr = srcPtr;
pnColrR = (byte) (pnColr24 >> 16); /* set up local colors */
pnColrG = (pnColr24 >> 8) & 0xff;
pnColrB = pnColr24 & 0xff;
bkColrR = (byte) (bkColr24 >> 16);
bkColrG = (bkColr24 >> 8) & 0xff;
bkColrB = bkColr24 & 0xff;
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++ = pnColrR;
*lclDstPtr++ = pnColrG;
*lclDstPtr++ = pnColrB;
}
else
{ /* source is 0 */
*lclDstPtr++ = bkColrR;
*lclDstPtr++ = bkColrG;
*lclDstPtr++ = bkColrB;
}
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* Function SetTrans1M24B sets the destination pixel data to pnColr24
if the source is 1 else it does nothing. */
void SetTrans1M24B(void)
{
byte *lclDstPtr, *lclSrcPtr;
byte pnColrR, pnColrG, pnColrB;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
lclDstPtr = dstPtr; /* set up local pointers */
lclSrcPtr = srcPtr;
pnColrR = (byte) (pnColr24 >> 16); /* set up local colors */
pnColrG = (pnColr24 >> 8) & 0xff;
pnColrB = pnColr24 & 0xff;
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++ = pnColrR;
*lclDstPtr++ = pnColrG;
*lclDstPtr++ = pnColrB;
}
else
{
lclDstPtr += 3;
}
pxBit = pxBit >> 1;
if (pxBit == 0)
{
pxBit = 128;
lclSrcPtr++;
}
}
lclDstPtr += dstNextRow; /* advance to next row */
lclSrcPtr += srcNextRow;
}
return;
}
/* Function InvertTrans1M24B inverts the destination pixel data
if the source is 1 else it does nothing. */
void InvertTrans1M24B(void)
{
byte *lclDstPtr, *lclSrcPtr;
int lclLineCnt, lclByteCnt;
int pxBit;
int pxBitVal;
byte pixlVal;
lclDstPtr = dstPtr; /* set up local pointers */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -