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

📄 m24b_drv.c

📁 与Nucleus Plus配套的图形库
💻 C
📖 第 1 页 / 共 4 页
字号:
		break;
	case 8:	/* zCLEARz */
		pnColr24 = 0;	/* sets all source bits to 0 */
		break;
	case 12:	/* zSETz */
	case 14:	/* zINVERTz */
		pnColr24 = -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 = &DrawRectEntryImg1B24;
			Blit_Clip_Region(blitRec, &dRect, &sRect);
			goto WI1_RTN;
		}
	}

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


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

	lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
	dstBgnByte = 3 * 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 - (3 * byteCntM1) - 3;
/* 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);

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

	return;
}


/* Function mwRDIMA24 is a special case optimization for ReadImage,
24 bit per pixel, linear memory. */
void mwRDIMA24(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; /* # 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	= 24;  /* 24 bits per pixel  */

	dstImage->imAlign = gblXmin & 1;/* set to 0 if we start an even address
								    and one if it is odd  */
	dstImage->imWidth = gblXmax - gblXmin + 1;
/* BobB 5/26/99 - corrected the following line for the count.
	dstImage->imBytes = (dstImage->imWidth + dstImage->imAlign + 1) & ~1; */
	dstImage->imBytes = 3 * ((dstImage->imWidth + dstImage->imAlign + 1) & ~1);
	dstRowBytes = dstImage->imBytes;
	dstPtr = (byte *)(((long) &dstImage->imData[0]) + (3 * dstImage->imAlign));
/* 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)
	{
		dstPtr -= gblXmin;
		gblXmin = 0;
	}

	/* Check that gblYmin is not off bitmap  */
	if(gblYmin < 0)
	{
		dstPtr = (byte *) (((long) dstPtr) + (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 */
/* BobB 5/26/99 - corrected the following line for the count.
	byteCntM1 = (gblXmax - gblXmin); */
	byteCntM1 = 3 * (gblXmax - gblXmin + 1);
	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 - (3 * byteCntM1); */
	dstNextRow = dstRowBytes - byteCntM1;
/*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 - (3 * byteCntM1); */
	srcNextRow = srcRowBytes - byteCntM1;

	/* point to row table entry for the first row  */
	srcPtr = (byte *) *(srcMapTable + gblYmin) + (3 * gblXmin);

	do{
/* BobB 5/26/99 - corrected the following line for the count.
		for(count = 0; count <= (3 * byteCntM1); count++) */
		for(count = 0; count < byteCntM1; count++)
		{
			*dstPtr++ = *srcPtr++;
		}
		dstPtr += dstNextRow;
		srcPtr += srcNextRow;
	}while(--lineCntM1 >= 0);

RI_RTN:
	nuResume(rdiBmap);
	return;
}


/* Function SetDestM24B sets the destination pixel data. */
void SetDestM24B(void)
{
	byte *lclDstPtr, pnColrR, pnColrG, pnColrB;
	int lclLineCnt, lclByteCnt;
	byte * dstPtrSave;

	lclDstPtr = dstPtr;	/* set up local pointers */
	lclLineCnt = lineCntM1;
	pnColrR = (byte) (pnColr24 >> 16);	/* set up local colors */
	pnColrG = (pnColr24 >> 8) & 0xff;
	pnColrB = pnColr24  & 0xff;

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

		dstPtrSave = lclDstPtr;

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

		lclDstPtr = dstPtrSave + dstNextRow;
	}

	return;
}


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

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

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

		dstPtrSave = lclDstPtr;

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

		lclDstPtr = dstPtrSave + dstNextRow;
	}

	return;
}


/* Module mwSPA24 is a special case optimization for SetPixel, 24-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 mwSPA24(blitRcd *setpRec )
{

	void DrawRectEntry_setp24(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_setp24(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_setp24(setpRec);
			}
			else
			{	/* yes, clip to the region and draw */
				dRect.Xmax = dRect.Xmin + 1;
				dRect.Ymax = dRect.Ymin + 1;
				FillDrawer = &DrawRectEntry_setp24;
				Fill_Clip_Region(setpRec, &dRect);
			}
		}
	}

	nuResume(setpRec->blitDmap);
	return;
}

void DrawRectEntry_setp24(blitRcd *drwPRec)
{
	grafMap *drwGmap;
	long *rowTable;
	byte *bytePtr;
	byte pColorR, pColorG, pColorB;

	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 */
	bytePtr = (byte *) ((*rowTable) + (3 * dRect.Xmin));
	if (drwPRec->blitPat == 0)	/* pattern 0? */
	{	/* yes, use background color */
		if (drwPRec->blitRop & 0x10) return;	/* done if transparent */

		pColorR = (byte) (drwPRec->blitBack >> 16);
		pColorG = (byte) ((drwPRec->blitBack >> 8) & 0xff);
		pColorB = (byte) (drwPRec->blitBack & 0xff);
	}
	else
	{	/* no, use foreground color */
		pColorR = (byte) (drwPRec->blitFore >> 16);
		pColorG = (byte) ((drwPRec->blitFore >> 8) & 0xff);
		pColorB = (byte) (drwPRec->blitFore & 0xff);
	}

/* BobB 3/9/99 - corrected the sMapMask problem found earlier
	*bytePtr++ = pColorR & sMapMask;*/	/* draw the pixel */
	/**bytePtr++ = pColorG & sMapMask;
	*bytePtr = pColorB & sMapMask;*/
	*bytePtr++ = pColorR;	/* draw the pixel */
	*bytePtr++ = pColorG;
	*bytePtr = pColorB;

	return;
}


/* Module mwGPA24 is a special case optimization for GetPixel, 24-bit-per-pixel
   memory source.  */

int mwGPA24(int gblX, int gblY, grafMap *getpBmap)
{
#define egaCntlrP1 (egaCntlr + 1)
	void nuResume(grafMap *argGRAFMAP);
	byte *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 = (byte *) (*(getpBmap->mapTable[0] + gblY)) + (3 * gblX);
	pixelValue = (*pixelPtr++ << 16);
	pixelValue |= (*pixelPtr++ << 8);
	pixelValue |= *pixelPtr;
	nuResume(getpBmap);
	return(pixelValue);
}

⌨️ 快捷键说明

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