📄 m2b4_lin.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_lin.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the thin line drawing functions for 2 bit and */
/* 4 bit memory or LCD. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 11/10/99 Removed unused line */
/* BobB 11/18/99 Corrected region clipping test */
/* */
/*************************************************************************/
#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 "blit_5.h"
/* Function mwLI2_4B is a special case optimization for thin line
drawing to 2/4 bit memory destinations, rectangular and/or region
clipping. */
void mwLI2_4B(blitRcd *lineRec)
{
void ClipAndDrawEntry(void);
int Set_Up_Clip(blitRcd *clipBlit, rect *clipR, int blitMayOverlap,
int isLine);
int Line_Clip_Region(int rectCnt, lineS *destRect);
void nuResume(grafMap *argGRAFMAP);
void M2_4BURTable(void);
void M2_4BMOTable(void);
void M2_4BUXTable(void);
void M2_4BMATable(void);
void M2_4BMO_NDTable(void);
void M2_4BMA_NDTable(void);
void QuickEnd(void);
lineS *listPtr; /* Pointer to line to draw */
int blitMayOverlap = 0; /* Set false */
int isLine = 1; /* Set true */
/* Table used to NOT the source color according to raster op. */
byte FlipTable[16] = {0, 0, 0, 0x0f,
0x0f, 0x0f, 0x0f, 0,
0, 0, 0, 0,
0, 0x0f, 0, 0x0f};
/* Table used to force the source color to 0x0f according to raster op. */
byte ForceTableOr[16] = {0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0x0f, 0, 0x0f, 0};
/* Table used to force the source color to 0 according to raster op. */
byte ForceTableAnd[16] = {0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f,
0, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f};
/* set up the rectangular/region clip info */
if (Set_Up_Clip(lineRec, &cRect, blitMayOverlap, isLine)) return;
/* do we need to worry about clipping at all*/
/* BobB 11/18/99 - corrected the following line
if (clipToRectFlag == 0) */
if (clipToRegionFlag == 0)
{ /* no--valid coordinates are guaranteed at a higher level */
cRect.Xmax--; /* the clipping code expects an old-style
Metawindow clip rect */
cRect.Ymax--;
}
else
{ /* yes, copy the clip rect to the base, unchanging clip rect */
bcXmin = cRect.Xmin;
bcYmin = cRect.Ymin;
bcXmax = cRect.Xmax - 1;
bcYmax = cRect.Ymax - 1;
}
listPtr = (lineS *) lineRec->blitList; /* set up local variables */
rectCnt = lineRec->blitCnt;
lclPortMask = lineRec->blitMask;
dstClass = lineRec->blitRop;
if (lineRec->blitPat == 0) /* pattern 0? */
{ /* yes, use background color */
if (dstClass & 0x10) return; /* done if transparent */
lclPenColor = (byte) lineRec->blitBack;
}
else
{ /* pattern 1 is the only other possibility */
lclPenColor = (byte) lineRec->blitFore;
}
dstClass = dstClass & 0x0f; /* we don't care about transparency */
lclPenColor = lclPenColor ^ FlipTable[dstClass]; /* NOT the
color if appropriate */
lclPenColor = lclPenColor | ForceTableOr[dstClass]; /* make
the color 0x0f if appropriate */
lclPenColor = lclPenColor & ForceTableAnd[dstClass]; /* make
the color 0 if appropriate */
lclPenColor = lclPenColor & ((byte) lclPortMask); /* mask it */
dstBmap = lineRec->blitDmap;
M_PAUSE(dstBmap); /* lock grafMap */
dstWidth = dstBmap->pixBytes;
shfCnt = dstBmap->pixBits; /* determine number of bits per pixel */
if (shfCnt == 2)
{ /* 2 bpp */
flipMask = 2;
shiftMask = 0xc0;
firstOffset = 0x03;
lclPenColor = (lclPenColor & 0x03) << 6;
}
else
{ /* 4 bpp */
flipMask = 1;
shiftMask = 0xf0;
firstOffset = 0x01;
lclPenColor = lclPenColor << 4;
}
rowTablePtr[1] = (long *) dstBmap->mapTable[0];
switch (dstClass)
{ /* look up the optimization routine */
/* LCD non-transparent */
case 0: /* zREPz : src */
case 4: /* zNREPz : (NOT src) */
case 8: /* zCLEARz : 0's */
case 12: /* zSETz : 1's */
optPtr = &M2_4BURTable;
break;
case 1: /* zORz : src OR dst */
case 5: /* zNORz : (NOT src) OR dst */
optPtr = &M2_4BMOTable;
break;
case 2: /* zXORz : src XOR dst */
case 6: /* zNXORz : (NOT src) XOR dst */
case 14: /* zINVERTz: (NOT dst) */
optPtr = &M2_4BUXTable;
break;
case 3: /* zNANDz : (NOT src) AND dst */
case 7: /* zANDz : src AND dst */
optPtr = &M2_4BMATable;
break;
case 9: /* zORNz : src OR (NOT dst) */
case 13: /* zNORNz : (NOT src) OR (NOT dst) */
optPtr = &M2_4BMO_NDTable;
break;
case 10: /* zNOPz : dst <NOP> */
optPtr = &QuickEnd;
break;
case 11: /* zANDNz : src AND (NOT dst) */
case 15: /* zNANDNz : (NOT src) AND (NOT dst) */
optPtr = &M2_4BMA_NDTable;
break;
}
if (clipToRegionFlag != 0)
{ /* handle region clipping in a separate loop */
LineDrawer = &ClipAndDrawEntry;
Line_Clip_Region(rectCnt, listPtr);
nuResume(dstBmap);
return;
}
while (rectCnt-- > 0)
{ /* Main line-drawing loop. */
dRect.Xmin = listPtr->lStart.X;
dRect.Ymin = listPtr->lStart.Y;
dRect.Xmax = listPtr->lEnd.X;
dRect.Ymax = listPtr->lEnd.Y;
drawStat = (char) listPtr->flStat;
listPtr++;
ClipAndDrawEntry(); /* clip and draw the line */
}
nuResume(dstBmap);
return;
}
#define M2_4BMOYMLR M2_4BMOV
#define M2_4BMOXMLR M2_4BMOH
#define M2_4BMODLR M2_4BMOH
#define M2_4BMOXMRL M2_4BMODRL
#define M2_4BMOYMLR_ND M2_4BMOV_ND
#define M2_4BMOXMLR_ND M2_4BMOH_ND
#define M2_4BMODLR_ND M2_4BMOH_ND
#define M2_4BMOXMRL_ND M2_4BMODRL_ND
#define M2_4BMAYMLR M2_4BMAV
#define M2_4BMAXMLR M2_4BMAH
#define M2_4BMADLR M2_4BMAH
#define M2_4BMAXMRL M2_4BMADRL
#define M2_4BMAYMLR_ND M2_4BMAV_ND
#define M2_4BMAXMLR_ND M2_4BMAH_ND
#define M2_4BMADLR_ND M2_4BMAH_ND
#define M2_4BMAXMRL_ND M2_4BMADRL_ND
void M2_4BURTable(void)
{
void M2_4BURYMRL(void);
void M2_4BURV(void);
void M2_4BURYMLR(void);
void M2_4BURDLR(void);
void M2_4BURXMLR(void);
void M2_4BURH(void);
void M2_4BURDRL(void);
void M2_4BURXMRL(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BURYMRL();
break;
case 1:
M2_4BURV();
break;
case 2:
M2_4BURYMLR();
break;
case 3:
M2_4BURDLR();
break;
case 4:
M2_4BURXMLR();
break;
case 5:
M2_4BURH();
break;
case 6:
M2_4BURDRL();
break;
case 7:
M2_4BURXMRL();
break;
}
return;
}
void M2_4BMOTable(void)
{
void M2_4BMOYMRL(void);
void M2_4BMOV(void);
void M2_4BMOYMLR(void);
void M2_4BMODLR(void);
void M2_4BMOXMLR(void);
void M2_4BMOH(void);
void M2_4BMODRL(void);
void M2_4BMOXMRL(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BMOYMRL();
break;
case 1:
M2_4BMOV();
break;
case 2:
M2_4BMOYMLR();
break;
case 3:
M2_4BMODLR();
break;
case 4:
M2_4BMOXMLR();
break;
case 5:
M2_4BMOH();
break;
case 6:
M2_4BMODRL();
break;
case 7:
M2_4BMOXMRL();
break;
}
return;
}
void M2_4BUXTable(void)
{
void M2_4BUXYMRL(void);
void M2_4BUXV(void);
void M2_4BUXYMLR(void);
void M2_4BUXDLR(void);
void M2_4BUXXMLR(void);
void M2_4BUXH(void);
void M2_4BUXDRL(void);
void M2_4BUXXMRL(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BUXYMRL();
break;
case 1:
M2_4BUXV();
break;
case 2:
M2_4BUXYMLR();
break;
case 3:
M2_4BUXDLR();
break;
case 4:
M2_4BUXXMLR();
break;
case 5:
M2_4BUXH();
break;
case 6:
M2_4BUXDRL();
break;
case 7:
M2_4BUXXMRL();
break;
}
return;
}
void M2_4BMATable(void)
{
void M2_4BMAYMRL(void);
void M2_4BMAV(void);
void M2_4BMAYMLR(void);
void M2_4BMADLR(void);
void M2_4BMAXMLR(void);
void M2_4BMAH(void);
void M2_4BMADRL(void);
void M2_4BMAXMRL(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BMAYMRL();
break;
case 1:
M2_4BMAV();
break;
case 2:
M2_4BMAYMLR();
break;
case 3:
M2_4BMADLR();
break;
case 4:
M2_4BMAXMLR();
break;
case 5:
M2_4BMAH();
break;
case 6:
M2_4BMADRL();
break;
case 7:
M2_4BMAXMRL();
break;
}
return;
}
void M2_4BMO_NDTable(void)
{
void M2_4BMOYMRL_ND(void);
void M2_4BMOV_ND(void);
void M2_4BMOYMLR_ND(void);
void M2_4BMODLR_ND(void);
void M2_4BMOXMLR_ND(void);
void M2_4BMOH_ND(void);
void M2_4BMODRL_ND(void);
void M2_4BMOXMRL_ND(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BMOYMRL_ND();
break;
case 1:
M2_4BMOV_ND();
break;
case 2:
M2_4BMOYMLR_ND();
break;
case 3:
M2_4BMODLR_ND();
break;
case 4:
M2_4BMOXMLR_ND();
break;
case 5:
M2_4BMOH_ND();
break;
case 6:
M2_4BMODRL_ND();
break;
case 7:
M2_4BMOXMRL_ND();
break;
}
return;
}
void M2_4BMA_NDTable(void)
{
void M2_4BMAYMRL_ND(void);
void M2_4BMAV_ND(void);
void M2_4BMAYMLR_ND(void);
void M2_4BMADLR_ND(void);
void M2_4BMAXMLR_ND(void);
void M2_4BMAH_ND(void);
void M2_4BMADRL_ND(void);
void M2_4BMAXMRL_ND(void);
switch (lineDir) /* appropriate for the line direction */
{
case 0:
M2_4BMAYMRL_ND();
break;
case 1:
M2_4BMAV_ND();
break;
case 2:
M2_4BMAYMLR_ND();
break;
case 3:
M2_4BMADLR_ND();
break;
case 4:
M2_4BMAXMLR_ND();
break;
case 5:
M2_4BMAH_ND();
break;
case 6:
M2_4BMADRL_ND();
break;
case 7:
M2_4BMAXMRL_ND();
break;
}
return;
}
/* Low-level line drawing optimizations. */
/* Unmasked low-level optimizations. */
/* Horizontal left->right replace. */
void M2_4BURH(void)
{
int i;
int pxShift;
byte pxBit;
byte pxColor;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
pxColor = (byte) (lclPenColor >> pxShift);
pxBit = (byte) (shiftMask >> pxShift);
dstPtr = (byte *) *rowTablePtr[0] + (dRect.Xmin >> flipMask);
for (i = 0; i <= majorAxisLengthM1; i++)
{
*dstPtr = (*dstPtr & ~pxBit) | pxColor;
pxColor = pxColor >> shfCnt;
pxBit = (pxBit >> shfCnt);
if(pxBit == 0)
{
dstPtr++;
pxBit = shiftMask;
pxColor = lclPenColor;
}
}
return;
}
/* Vertical top->bottom replace. */
void M2_4BURV()
{
int i;
int pxShift;
byte pxBit;
byte pxColor;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
pxColor = (byte) (lclPenColor >> pxShift);
pxBit = (byte) (shiftMask >> pxShift);
dstBgnByte = dRect.Xmin >> flipMask;
for (i = 0; i <= majorAxisLengthM1; i++)
{
dstPtr = (byte *) *rowTablePtr[0] + dstBgnByte;
*dstPtr = (*dstPtr & ~pxBit) | pxColor;
rowTablePtr[0]++;
}
return;
}
/* Diagonal top->bottom, right->left replace. */
void M2_4BURDRL(void)
{
int i;
int pxShift;
byte pxBit;
byte pxColor;
pxShift = (dRect.Xmin & firstOffset) * shfCnt;
pxColor = (byte) (lclPenColor >> pxShift);
pxBit = (byte) (shiftMask >> pxShift);
dstBgnByte = dRect.Xmin >> flipMask;
for (i = 0; i <= majorAxisLengthM1; i++)
{
dstPtr = (byte *) *rowTablePtr[0] + dstBgnByte;
*dstPtr = (*dstPtr & ~pxBit) | pxColor;
rowTablePtr[0]++;
pxColor = pxColor << shfCnt;
pxBit = (pxBit << shfCnt);
if(pxBit == 0)
{
dstBgnByte--;
if (shfCnt == 2)
{
pxBit = 0x03;
pxColor = lclPenColor >> 6;
}
else
{
pxBit = 0x0f;
pxColor = lclPenColor >> 4;
}
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -