📄 bits1.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 */
/* */
/* BITS1.c 1.9 */
/* */
/* COMPONENT */
/* */
/* All */
/* */
/* DESCRIPTION */
/* */
/* This file contains the COPYBLIT & COPYBITS functions. */
/* */
/* AUTHOR */
/* */
/* Robert G. Burrill, Accelerated Technology, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* None */
/* */
/* FUNCTIONS */
/* */
/* None */
/* */
/* DEPENDENCIES */
/* */
/* None */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* BobB 5/5/98 Corrected for unsigned chars and */
/* compiler warnings */
/* */
/*************************************************************************/
#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_0.h"
/* Function CopyBlit copies a rectangular bitmap from one grafport to
another. The source rect will be 'clipped' to the intersection of the port
rect and the bitmap limits. If the source rect is 'clipped', the destination
rect is adjusted to correspond to the source origin. The destination rect
upper left determines the destination origin. The size of the transfer is
the smaller of the two rect sizes.
The devTechs for the source and destination grafMaps are combined,
and this combination is looked-up in a table to see if it is a supported
blit transfer combination. If it is, the type of transfer ( either
self to self, monochrome to self, memory to self, or self to memory)
indicated by the table is used to pick the appropriate blit primitive
vector. All the 'to self' types of transfers can be vectored through
the destination grafmaps vector list, however the 'self to memory' vector
is only contained in the source grafmap structure.
Returns an error (-1) for unsupported grafMaps combinations. */
int CopyBlit( metaPort *srcPORT, metaPort *dstPORT, rect *argSrcR, rect *argDstR )
{
/* BobB 5/5/98 - added following two lines to get rid of warning */
void mwPort2Gbl(rect *inpRect, metaPort *inpPort, rect *dstRect);
void mwGblClip(metaPort *inpClpPort, rect *outClipR);
blitRcd blitRec; /* blitRcd */
struct _rectlist /* blit list of two rectangles */
{
rect srcBR; /* source rect in blit list */
rect dstBR; /* dest rect in blit list */
} rectlist;
rect dstClipR; /* global clip rect for dest grafMap */
/* BobB 5/5/98 - corrected the following lines for unsigned values */
/*char cmbDevtech;*/ /* combined devtech of bitmaps */
/*char cmbBlitType;*/ /* combined blit type from table */
byte cmbDevtech; /* combined devtech of bitmaps */
byte cmbBlitType; /* combined blit type from table */
short gblPortMax;
short srcDelta;
short dstDelta;
short grafErrValue; /* error value */
/* Convert destination rect to global (possibly non-current port) */
mwPort2Gbl(argDstR, dstPORT, &rectlist.dstBR);
/* ===== Fill out blitRcd based on dest grafPort ======
NOTE: pattern list and curent pattern are not set (not used ) */
blitRec.blitFlags = bfClipRect; /* assume rect clip */
if (dstPORT->portFlags & pfRgnClip) /* are regions enabled ? */
{
blitRec.blitFlags |= bfClipRegn; /* yes, clip region */
blitRec.blitRegn = dstPORT->portRegion;
}
blitRec.blitRop = dstPORT->pnMode; /* set raster op */
blitRec.blitMask = dstPORT->portMask; /* set plane mask */
blitRec.blitBack = dstPORT->bkColor; /* set colors */
blitRec.blitFore = dstPORT->pnColor;
blitRec.blitCnt = 1; /* 1 set of rects */
blitRec.blitList = (long) &rectlist; /* addr of both rects */
blitRec.blitDmap = dstPORT->portMap; /* set dest grafmap */
blitRec.blitClip = &dstClipR; /* set pointer to clipR */
mwGblClip(dstPORT, &dstClipR); /* convert to global and check port clip */
/* ====== Setup source info =======
NOTE: may adjust dest rect! */
mwPort2Gbl(argSrcR, srcPORT, &rectlist.srcBR);
/* 'clip' source rect to source port */
if (rectlist.srcBR.Xmin < srcPORT->portOrgn.X) /* xmin < global port xmin ? */
{
rectlist.dstBR.Xmin += srcPORT->portOrgn.X - rectlist.srcBR.Xmin; /* adjust dest min */
rectlist.srcBR.Xmin = srcPORT->portOrgn.X; /* set src to minimum port coord */
}
if (rectlist.srcBR.Ymin < srcPORT->portOrgn.Y) /* ymin < global port ymin ? */
{
rectlist.dstBR.Ymin += srcPORT->portOrgn.Y - rectlist.srcBR.Ymin; /* adjust dest min */
rectlist.srcBR.Ymin = srcPORT->portOrgn.Y; /* set src to minimum port coord */
}
/* compute global port max X */
gblPortMax = srcPORT->portRect.Xmax - srcPORT->portRect.Xmin
+ srcPORT->portOrgn.X;
if (rectlist.srcBR.Xmax > gblPortMax) /* xmax > global port xmax ? */
{
rectlist.srcBR.Xmax = gblPortMax; /* set it equal */
}
/* compute global port max X */
gblPortMax = srcPORT->portRect.Ymax - srcPORT->portRect.Ymin
+ srcPORT->portOrgn.Y;
if (rectlist.srcBR.Ymax > gblPortMax) /* xmax > global port xmax ? */
{
rectlist.srcBR.Ymax = gblPortMax; /* set it equal */
}
blitRec.blitSmap = srcPORT->portMap; /* place source grafMap in blitRcd */
/* 'clip' source rect to bitmap limits */
if (rectlist.srcBR.Xmin < 0)
{
rectlist.dstBR.Xmin += rectlist.srcBR.Xmin; /* adjust dest min */
rectlist.srcBR.Xmin = 0; /* set src min to 0 */
}
if (rectlist.srcBR.Ymin < 0)
{
rectlist.dstBR.Ymin += rectlist.srcBR.Ymin; /* adjust dest min */
rectlist.srcBR.Ymin = 0; /* set src min to 0 */
}
if (rectlist.srcBR.Xmax > srcPORT->portMap->pixWidth)
{
rectlist.srcBR.Xmax = srcPORT->portMap->pixWidth; /* set src max to pixWidth */
}
if (rectlist.srcBR.Ymax > srcPORT->portMap->pixHeight)
{
rectlist.srcBR.Ymax = srcPORT->portMap->pixHeight; /* set src max to pixHeight */
}
/* force sizes to be smaller of either src or dst rect */
srcDelta = rectlist.srcBR.Xmax - rectlist.srcBR.Xmin; /* compute src width */
dstDelta = rectlist.dstBR.Xmax - rectlist.dstBR.Xmin; /* compute dest width */
if (srcDelta < dstDelta) /* src < dst ? */
{
rectlist.dstBR.Xmax = rectlist.dstBR.Xmin + srcDelta; /* set both to same size */
}
else
{
rectlist.srcBR.Xmax = rectlist.srcBR.Xmin + dstDelta; /* use min delta */
}
srcDelta = rectlist.srcBR.Ymax - rectlist.srcBR.Ymin; /* compute src height */
dstDelta = rectlist.dstBR.Ymax - rectlist.dstBR.Ymin; /* compute dest height */
if (srcDelta < dstDelta) /* src < dst ? */
{
rectlist.dstBR.Ymax = rectlist.dstBR.Ymin + srcDelta; /* set both to same size */
}
else
{
rectlist.srcBR.Ymax = rectlist.srcBR.Ymin + dstDelta; /* use min delta */
}
/* ===== call appropriate blit primitive ===== */
/* combine both devtechs into an index [dest][source] */
cmbDevtech = srcPORT->portMap->devTech | (dstPORT->portMap->devTech << 4);
cmbBlitType = blitxfertbl[cmbDevtech]; /* look up blit combo type from table */
switch(cmbBlitType)
{
case self2self:
blitRec.blitDmap->prBlitSS(&blitRec);
return(0);
case mem2self:
blitRec.blitDmap->prBlitMS(&blitRec);
return(0);
case self2mem:
blitRec.blitSmap->prBlitSM(&blitRec); /* must use source grafMap */
return(0);
case mono2self:
blitRec.blitDmap->prBlit1S(&blitRec);
return(0);
default:
/* not a supported combo */
grafErrValue = c_CopyBlit + c_InvDevFunc;
nuGrafErr(grafErrValue); /* report error */
return(-1);
}
}
/* Function COPYBITS copies the specified source rectangle (srcRECT) in the
source bitmap (srcBMap) to the destimation rectangle (dstRECT) in the
destination bitmap (dstBMap).
ALL RECTANGLES MUST BE EXPRESSED IN GLOBAL COORDINATES!!!
Returns an error (-1) for unsupported grafMaps combinations. */
int CopyBits( grafMap *srcBMAP, grafMap *dstBMAP, rect *srcRECT, rect *dstRECT,
rect *dstCLIP, int dstRASOP )
{
blitRcd cblitRec; /* blitRcd */
rect srcR; /* source rect */
rect dstR; /* dest rect */
/* BobB 5/5/98 - corrected the following lines for unsigned values */
/*char cmbDevtech;*/ /* combined devtech of bitmaps */
/*char cmbBlitType;*/ /* combined blit type from table */
byte cmbDevtech; /* combined devtech of bitmaps */
byte cmbBlitType; /* combined blit type from table */
short grafErrValue; /* error value */
cblitRec.blitRop = dstRASOP;
cblitRec.blitFlags = bfClipRect;
cblitRec.blitClip = dstCLIP;
cblitRec.blitCnt = 1;
cblitRec.blitBack = 0;
cblitRec.blitFore = 0xFFFFFFFF;
cblitRec.blitMask = 0xFFFFFFFF;
srcR = (*srcRECT);
dstR = (*dstRECT);
cblitRec.blitList = (long) &srcR;
cblitRec.blitSmap = srcBMAP;
cblitRec.blitDmap = dstBMAP;
/* BLITREC is filled out at this point */
/* combine both devtechs into an index [dest][source] */
cmbDevtech = srcBMAP->devTech | (dstBMAP->devTech << 4);
cmbBlitType = blitxfertbl[cmbDevtech]; /* look up blit combo type from table */
switch(cmbBlitType)
{
case self2self:
cblitRec.blitDmap->prBlitSS(&cblitRec);
return(0);
case mem2self:
cblitRec.blitDmap->prBlitMS(&cblitRec);
return(0);
case self2mem:
cblitRec.blitSmap->prBlitSM(&cblitRec); /* must use source grafMap */
return(0);
case mono2self:
cblitRec.blitDmap->prBlit1S(&cblitRec);
return(0);
default:
/* not a supported combo */
grafErrValue = c_CopyBits + c_InvDevFunc;
nuGrafErr(grafErrValue); /* report error */
return(-1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -