⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m16b_drv.c

📁 与Nucleus Plus配套的图形库
💻 C
📖 第 1 页 / 共 3 页
字号:
	srcBgnByte = sRect.Xmin;
	srcPtr16 = (word *) (srcImag->imData + (sRect.Ymin * srcPixBytes))
				+ srcBgnByte;

	dstPtr16 = (word *) (*(dstBmap->mapTable[0] + dRect.Ymin))
				+ dstBgnByte;
	optPtr();	/* blit the rectangle */

	return;
}


/* Function mwWRIMMA16 is a special case optimization for 1->16Bit
WriteImage. */
void mwWRIMMA16(blitRcd *blitRec)
{
	void DrawRectEntryImg1B16(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 *rListPtr;	/* list pointer */
	int blitMayOverlap = 0;	/* Set false for region clipping*/
	int isLine = 0;	/* Set false */

	srcImag = (image *) blitRec->blitSmap; 

	if((srcImag->imWidth <= 0) || (srcImag->imHeight <= 0))
		return;

	sRect.Ymin = 0;
	sRect.Xmin = 0;
	srcPixBytes = srcImag->imBytes;
	rListPtr =  (rect *) blitRec->blitList;

	dstBmap =  blitRec->blitDmap;
	dstClass = blitRec->blitRop & 0x1f;

	M_PAUSE(dstBmap);

	bkColr16 = (short) blitRec->blitBack;	/* background color */
	pnColr16 = (short) blitRec->blitFore;	/* foreground color */

	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 */
		pnColr16 = ~pnColr16;	/* this has the effect of notting the
					pen color for all operations during this call */
	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 */
		pnColr16 = 0;	/* sets all source bits to 0 */
		break;
	case 12:	/* zSETz */
	case 14:	/* zINVERTz */
		pnColr16 = -1;	/* sets all source bits to 1 */
		break;
	default:	/* all transparent cases */
		break;
	}

	/* set up clipping */
	if (Set_Up_Clip(blitRec, &cRect, blitMayOverlap, isLine))
		goto WI1_RTN;

	dRect = *rListPtr;
/* See if the destination is too wide  */
	if((dRect.Xmax - dRect.Xmin) > srcImag->imWidth)
		dRect.Xmax = dRect.Xmin + srcImag->imWidth;
/* sXmax not adjusted because not used  */

/* See if the destination is too high  */
	if((dRect.Ymax - dRect.Ymin) > srcImag->imHeight)
		dRect.Ymax = dRect.Ymin + srcImag->imHeight;
/* sYmax not adjusted because not used  */

/* do we need to worry about clipping */
	if(clipToRectFlag != 0)
	{
		if (dRect.Xmin < cRect.Xmin)
		{	/* Reset src & dst Xmin clip limit */
			sRect.Xmin -= (dRect.Xmin - cRect.Xmin);
			dRect.Xmin  = cRect.Xmin;
		}
		if (dRect.Ymin < cRect.Ymin)
		{	/* Reset src & dst Ymin clip limit */
			sRect.Ymin -= (dRect.Ymin - cRect.Ymin);
			dRect.Ymin  = cRect.Ymin;
		}
		if (dRect.Xmax > cRect.Xmax)
		{	/* Reset dst Xmax clip limit */
			dRect.Xmax  = cRect.Xmax;
		}
		if (dRect.Ymax > cRect.Ymax)
		{	/* Reset dst Ymax clip limit */
			dRect.Ymax  = cRect.Ymax;
		}
		if ((dRect.Xmin >= dRect.Xmax) || (dRect.Ymin >= dRect.Ymax))
			return;
	/* do we need to worry about region clipping?  */
		if (clipToRegionFlag != 0)
		{	/* yes, go do it  */
			FillDrawer = &DrawRectEntryImg1B16;
			Blit_Clip_Region(blitRec, &dRect, &sRect);
			goto WI1_RTN;
		}
	}

	DrawRectEntryImg1B16(blitRec);
WI1_RTN:
	nuResume(dstBmap);
	return;
}


/* Function DrawRectEntryImg1B16 blits the image to the memory */
void DrawRectEntryImg1B16(blitRcd *blitRec)
{

	lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
	dstBgnByte = dRect.Xmin;
/* BobB 6/14/99 - added the following line to correct write addressing */
	srcBgnByte = (sRect.Xmin >> 3);
	byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
	dstNextRow = (dstBmap->pixBytes >> 1) - byteCntM1 - 1;
/* BobB 6/14/99 - corrected the following lines for write addressing
	srcNextRow = srcPixBytes - ((byteCntM1 + 1) >> 3);
	srcPtr = (byte *) (srcImag->imData); */
	srcNextRow = srcPixBytes - ((sRect.Xmin + byteCntM1 + 1) >> 3)
		+ srcBgnByte;
	srcPtr = (byte *) (srcImag->imData + (sRect.Ymin * srcPixBytes)
		+ srcBgnByte);

	dstPtr16 = (word *) (*(dstBmap->mapTable[0] + dRect.Ymin))
		+ dstBgnByte;
	optPtr();	/* blit the rectangle */

	return;
}


/* Function mwRDIMA16 is a special case optimization for ReadImage,
16 bit per pixel, linear memory. */
void mwRDIMA16(grafMap * rdiBmap, image *dstImage, int gblYmax, int gblXmax,
			 int gblYmin, int gblXmin)
{
	void nuResume(grafMap *dstBmap);

	int	srcRowBytes	;/*# of bytes across a source bitmap row  */
	int	dstRowBytes	;/* # of bytes across an dstImage row  */
	int	cXmax,cYmax	;/* bitmap limits  */
	short grafErrValue;
	long *srcMapTable;
	int count;

	gblXmax--;
	gblYmax--;

	M_PAUSE(rdiBmap);
	
	srcRowBytes = (rdiBmap->pixBytes >> 1); /* # of byte across the source  */
	srcMapTable = (long *)rdiBmap->mapTable[0]; /* store mapTable[0] pointer locally  */
 /* get the source bitmap's limits  */
	cXmax = rdiBmap->pixWidth - 1;
	cYmax = rdiBmap->pixHeight - 1;

/* Initialize dstImage header and destination copy parameters  */
	dstImage->imFlags  = 0;  /* assume no span segment  */
	dstImage->imPlanes = 1;  /* always plane # 1  */    
	dstImage->imBits	= 16;  /* 8 bits per pixel  */

	dstImage->imAlign = 0;	/* set to 0   */
	dstImage->imWidth = gblXmax - gblXmin + 1;
	dstRowBytes = dstImage->imWidth;
	dstImage->imBytes = dstRowBytes << 1;
	dstPtr16 = (word *)((long) &dstImage->imData[0]);
/* Calculate dstImage height in pixels  */
	dstImage->imHeight = gblYmax - gblYmin + 1;

	if((dstImage->imWidth > 0x7FFF) || (dstImage->imHeight > 0x7FFF))
	{
		grafErrValue = c_ReadImag + c_OfloRect;
		rdiBmap->cbPostErr(grafErrValue);
		dstImage->imWidth = 0;
		dstImage->imHeight = 0;
		dstImage->imBytes = 0;
		goto RI_RTN;
	}
	if((dstImage->imWidth < 0) || (dstImage->imHeight < 0))
	{
		grafErrValue = c_ReadImag + c_NullRect;
		rdiBmap->cbPostErr(grafErrValue);
		dstImage->imWidth = 0;
		dstImage->imHeight = 0;
		dstImage->imBytes = 0;
		goto RI_RTN;
	}
	if((dstImage->imWidth == 0) || (dstImage->imHeight == 0))
	{
		dstImage->imWidth = 0;
		dstImage->imHeight = 0;
		dstImage->imBytes = 0;
		goto RI_RTN;
	}

/* Now clip to the source bitmap */
	/* check that gblXmin is not off bitmap  */
	if(gblXmin < 0)
	{
		dstPtr16 -= gblXmin;
		gblXmin = 0;
	}

	/* Check that gblYmin is not off bitmap  */
	if(gblYmin < 0)
	{
		dstPtr16 = dstPtr16 - (dstRowBytes * gblYmin);
		gblYmin = 0;
	}

	/* Check that gblYmax is not off bitmap  */
	if(cYmax < gblYmax) gblYmax = cYmax;

	/* Check that gblXmax is not off bitmap */
	if(cXmax < gblXmax) gblXmax = cXmax;

	/* Now set the horizontal and vertical */
	byteCntM1 = (gblXmax - gblXmin);
	if(byteCntM1 < 0) goto RI_RTN;
	lineCntM1 = (gblYmax - gblYmin);
	if(lineCntM1 < 0) goto RI_RTN;

/*Set the offset from the end of one dstImage row to the start of the next  */
/* BobB 5/26/99 - corrected the following line for the pointer.
	dstNextRow = dstRowBytes - byteCntM1; */
	dstNextRow = dstRowBytes - byteCntM1 - 1;
/*Set offset from the end of one source rectangle row to the start 
			of the next  */
/* BobB 5/26/99 - corrected the following line for the pointer.
	srcNextRow = srcRowBytes - byteCntM1; */
	srcNextRow = srcRowBytes - byteCntM1 - 1;

	/* point to row table entry for the first row  */
	srcPtr16 = (word *) *(srcMapTable + gblYmin) + gblXmin;

	do{
		for(count = 0; count <= byteCntM1; count++)
		{
			*dstPtr16++ = *srcPtr16++;
		}
		dstPtr16 += dstNextRow;
		srcPtr16 += srcNextRow;
	}while(--lineCntM1 >= 0);

RI_RTN:
	nuResume(rdiBmap);
	return;
}


/* Function SetDestM16B sets the destination pixel data. */
void SetDestM16B(void)
{
	word *lclDstPtr;
	int lclLineCnt, lclByteCnt;
	word * dstPtrSave;

	lclDstPtr = dstPtr16;	/* set up local pointers */
	lclLineCnt = lineCntM1;

	while (lclLineCnt-- >= 0)
	{	/* for each row */

		dstPtrSave = lclDstPtr;

		lclByteCnt = byteCntM1;
		while (lclByteCnt-- >= 0)
		{	/* for each byte in the row */
			*lclDstPtr++ = pnColr16;
		}

		lclDstPtr = dstPtrSave + dstNextRow;
	}

	return;
}


/* Function InvertDestM16B inverts the destination pixel data. */
void InvertDestM16B(void)
{
	word *lclDstPtr;
	int lclLineCnt, lclByteCnt;
	word * dstPtrSave;

	lclDstPtr = dstPtr16;	/* set up local pointers */
	lclLineCnt = lineCntM1;

	while (lclLineCnt-- >= 0)
	{	/* for each row */

		dstPtrSave = lclDstPtr;

		lclByteCnt = byteCntM1;
		while (lclByteCnt-- >= 0)
		{	/* for each byte in the row */
			*lclDstPtr = ~(*lclDstPtr);
			lclDstPtr++;
		}

		lclDstPtr = dstPtrSave + dstNextRow;
	}

	return;
}


/* Function mwSPA16 is a special case optimization for SetPixel, 16-bit-per-pixel
   memory destination, rectangular and/or region clipping with color
   translation.  */
/*       *******************************************
         * Only patterns 0 and 1 are handled here, *
         * and only raster ops 0 and 16!!!!        *
         *******************************************

blitCnt is ignored; it's assumed to be 1.
*/
void mwSPA16(blitRcd *setpRec )
{

	void DrawRectEntry_setp16(blitRcd *drwPRec);
	int Set_Up_Clip(blitRcd *clipBlit, rect *cRect, int blitMayOverlap,
				int isLine);
	int Fill_Clip_Region(blitRcd *fcRec, rect *dRectect);
	void nuResume(grafMap *argGRAFMAP);
	point *drawPt;	/* Pointer to point to draw */
	
	int blitMayOverlap = 0;	/* Set false */
	int isLine = 0;	/* Set false */

	/* set up the rectangular/region clip info */
	if (Set_Up_Clip(setpRec, &cRect, blitMayOverlap, isLine)) return;

	drawPt = (point *) setpRec->blitList;	/* set up pointer */
	dRect.Xmin = drawPt->X;
	dRect.Ymin = drawPt->Y;
	M_PAUSE(setpRec->blitDmap);	/* lock grafMap */

	/* do we need to worry about clipping at all*/
	if (clipToRectFlag == 0)
	{	/* no--valid coordinates are guaranteed at a higher level */
		DrawRectEntry_setp16(setpRec);	/* draw the point */
	}
	else
	{	/* yes first check trivial reject */
		if ((dRect.Xmin >= cRect.Xmin) && (dRect.Ymin >= cRect.Ymin) &&
			(dRect.Xmin < cRect.Xmax) && (dRect.Ymin < cRect.Ymax))
		{	/* it passes so far - do we need to worry about region clipping? */
			if (clipToRegionFlag == 0)
			{	/* no, draw the point */
				DrawRectEntry_setp16(setpRec);
			}
			else
			{	/* yes, clip to the region and draw */
				dRect.Xmax = dRect.Xmin + 1;
				dRect.Ymax = dRect.Ymin + 1;
				FillDrawer = &DrawRectEntry_setp16;
				Fill_Clip_Region(setpRec, &dRect);
			}
		}
	}

	nuResume(setpRec->blitDmap);
	return;
}

void DrawRectEntry_setp16(blitRcd *drwPRec)
{
	grafMap *drwGmap;
	long *rowTable;
	word *wordPtr;
	short pColor;

	drwGmap = drwPRec->blitDmap;	/* get grafMap */
	if ((dRect.Ymin < drwGmap->mapWinYmin[0]) ||	/* below window #0? */
		(dRect.Ymin > drwGmap->mapWinYmax[0]))	/* above window #0? */
	{	/* yes, map in bank */
		drwGmap->mapBankMgr(drwGmap, dRect.Ymin, -1, 0);
	}
	rowTable = (long *) drwGmap->mapTable[0];	/* point to row table */
	rowTable = rowTable + dRect.Ymin;	/* look up the starting row */
	/* point to pixel */
	wordPtr = (word *) (*rowTable) + dRect.Xmin;
	if (drwPRec->blitPat == 0)	/* pattern 0? */
	{	/* yes, use background color */
		if (drwPRec->blitRop & 0x10) return;	/* done if transparent */

		pColor = (short) drwPRec->blitBack;
	}
	else
	{	/* no, use foreground color */
		pColor = (short) drwPRec->blitFore;
	}

/* BobB 3/9/99 - corrected the sMapMask problem found earlier
	*wordPtr = pColor & sMapMask;*/	/* draw the pixel */
	*wordPtr = pColor;	/* draw the pixel */

	return;
}


/* Function mwGPA16 is a special case optimization for GetPixel, 16-bit-per-pixel
   memory source.  */

int mwGPA16(int gblX, int gblY, grafMap *getpBmap)
{
	void nuResume(grafMap *argGRAFMAP);
	word *pixelPtr;
	int pixelValue;


	/* check if off bitmap */
	if ((gblX < 0) || (gblY < 0) || (gblX >= getpBmap->pixWidth) ||
		(gblY >= getpBmap->pixHeight)) return(0);

	M_PAUSE(getpBmap);	/* lock grafMap */

	if( (gblY < getpBmap->mapWinYmin[0]) ||
		(gblY > getpBmap->mapWinYmax[0] ) )
		getpBmap->mapBankMgr(getpBmap, gblY, -1);

	pixelPtr = (word *) (*(getpBmap->mapTable[0] + gblY)) + gblX;
	pixelValue = *pixelPtr;
	nuResume(getpBmap);
	return(pixelValue);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -