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

📄 m124_img.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************/
/*                                                                       */
/*         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          */
/*                                                                       */
/*      m124_img.c                                       1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains 1/2/4-bit memory image routines.              */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Robert G. Burrill, Accelerated Technology, Inc.                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*		None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*		   NAME            DATE                    REMARKS               */
/*                                                                       */
/*         BobB            1/5/99     Corrected read image # of bits     */
/*         BobB           1/15/99     Corrected image shifting & read    */
/*                                     image byte counting               */
/*         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.                        */  
/*         BobB          10/22/99     Corrected WriteImage start X and   */
/*                                      background color                 */
/*                                                                       */
/*************************************************************************/
#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 mwWRIM2_4B is a special case optimization for WriteImage,
2/4 bit per pixel linear memory. Also passes through 1->2/4Bit
WriteImage to mwWRIMM2_4B. */
void mwWRIM2_4B(blitRcd *blitRec)
{
	void mwWRIMM2_4B(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 DrawRectEntryImgM2_4B(blitRcd *blitRec);
	void nuResume(grafMap *dstBmap);
	void RepDestImgM2_4B(void);
	void OXADestImgM2_4B(void);
	void SetDestM2_4B(void);
	void NotDestSolidImgM2_4B(void);
	void InvertDestM2_4B(void);
	void QuickEnd(void);

	rect *rListPtr;	/* list pointer */
	int blitMayOverlap = 0;	/* Set false for region clipping*/
	int isLine = 0;	/* Set false */

	srcImag = (image *) blitRec->blitSmap; 

	if(srcImag->imBits == 1) /*is this a monochrome image?  */
	{
		mwWRIMM2_4B(blitRec);/* Let the 1->2/4 bit handler handle  */
		return;
	}

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

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

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

	M_PAUSE(dstBmap);

	dstWidth = dstBmap->pixBytes;
	shfCnt = dstBmap->pixBits;	/* determine number of bits per pixel */
	if (shfCnt == 2)
	{	/* 2 bpp */
		flipMask = 2;
		shiftMask = 0xc0;
		firstOffset = 0x03;
	}
	else
	{	/* 4 bpp */
		flipMask = 1;
		shiftMask = 0xf0;
		firstOffset = 0x01;
	}

	switch (dstClass)
	{	/* look up the optimization routine */
	  			    /* Memory non-transparent */
	case 0:		/* zREPz   :           src			 */
	case 4:		/* zNREPz  :        (NOT src)		 */
		optPtr = &RepDestImgM2_4B;
		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 = &OXADestImgM2_4B;
		break;
	case 8:		/* zCLEARz :           0's			 */
	case 12:	/* zSETz   :           1's			 */
		optPtr = &SetDestM2_4B;
		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 = &NotDestSolidImgM2_4B;
		break;
	case 10:	/* zNOPz   :           dst <NOP>	 */
		optPtr = &QuickEnd;
		break;
	case 14:	/* zINVERTz:        (NOT dst)		 */
		optPtr = &InvertDestM2_4B;
		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 */
		pnColr = (char)-1;	/* 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 */
		pnColr = 0;
		break;
	case 8:	/* zCLEARz */
		pnColr = 0;	/* sets all source bits to 0 */
		break;
	case 12:	/* zSETz */
	case 14:	/* zINVERTz */
		pnColr = (char)-1;	/* sets all source bits to 1 */
	}

	/* set up clipping */
	if (Set_Up_Clip(blitRec, &cRect, blitMayOverlap, isLine))
		goto WI_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 src & dst Xmax clip limit */
			dRect.Xmax  = cRect.Xmax;
			/* sXmax not altered because not used  */
		}
		if (dRect.Ymax > cRect.Ymax)
		{	/* Reset src & dst Ymax clip limit */
			dRect.Ymax  = cRect.Ymax;
		  /* sYmax not altered because not used  */
		}
		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 = &DrawRectEntryImgM2_4B;
			Blit_Clip_Region(blitRec, &dRect, &sRect);
			goto WI_RTN;
		}
	}
	
	DrawRectEntryImgM2_4B(blitRec);
WI_RTN:
	nuResume(dstBmap);
	return;
}


/* Draw the image */
void DrawRectEntryImgM2_4B(blitRcd *blitRec)
{

	lineCntM1 = dRect.Ymax - dRect.Ymin - 1;
	dstBgnByte = (dRect.Xmin >> flipMask);
	byteCntM1 = dRect.Xmax - dRect.Xmin - 1;
	srcBgnByte = (sRect.Xmin >> flipMask);

	optPtr();	/* blit the rectangle */

	return;
}


/* Function mwWRIMM2_4B is a special case optimization for 1->2/4Bit
WriteImage. */
void mwWRIMM2_4B(blitRcd *blitRec)
{
	void DrawRectEntry1B2_4B(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 RepDest1M2_4B(void);
	void OXADest1M2_4B(void);
	void SetDestM2_4B(void);
	void NotDestSolid1M2_4B(void);
	void InvertDestM2_4B(void);
	void QuickEnd(void);
	void SetTrans1M2_4B(void);
	void InvertTrans1M2_4B(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;
/* BobB 10/22/99 - corrected start X
	sRect.Xmin = 0; */
	sRect.Xmin = srcImag->imAlign;
	srcPixBytes = srcImag->imBytes;
	rListPtr =  (rect *) blitRec->blitList;

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

	M_PAUSE(dstBmap);

	bkColr = (char) blitRec->blitBack;	/* background color */
	pnColr = (char) blitRec->blitFore;	/* foreground color */

	switch (dstClass)
	{	/* look up the optimization routine */
	  			    /* Memory non-transparent */
	case 0:		/* zREPz   :           src			 */
	case 4:		/* zNREPz  :        (NOT src)		 */
		optPtr = &RepDest1M2_4B;
		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 = &OXADest1M2_4B;
		break;
	case 8:		/* zCLEARz :           0's			 */
	case 12:	/* zSETz   :           1's			 */
		optPtr = &SetDestM2_4B;
		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 = &NotDestSolid1M2_4B;
		break;
	case 10:	/* zNOPz   :           dst <NOP>	 */
		optPtr = &QuickEnd;
		break;
	case 14:	/* zINVERTz:        (NOT dst)		 */
		optPtr = &InvertDestM2_4B;
		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 = &SetTrans1M2_4B;
		break;
	case 18:	/* xXORx   :       !0src XOR dst	 */
	case 27:	/* xANDNx  :     !0src AND (NOT dst) */
	case 30:	/* xINVERTx:        (NOT dst)		 */
		optPtr = &InvertTrans1M2_4B;
		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 */
		pnColr = ~pnColr;	/* 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 */
		pnColr = 0;	/* sets all source bits to 0 */
		break;
	case 12:	/* zSETz */
	case 14:	/* zINVERTz */
		pnColr = (char)-1;	/* sets all source bits to 1 */
		break;
	default:	/* all transparent cases */
		break;
	}

	dstWidth = dstBmap->pixBytes;
	shfCnt = dstBmap->pixBits;	/* determine number of bits per pixel */
	if (shfCnt == 2)
	{	/* 2 bpp */
		flipMask = 2;
		shiftMask = 0xc0;
		firstOffset = 0x03;
		pnColr = pnColr & 0x03;

/* BobB 1/15/99 - corrected for image shifting */
		pnColr = pnColr | (pnColr << 2);
		pnColr = pnColr | (pnColr << 4);
/* BobB 10/22/99 - added background color */
		bkColr = bkColr & 0x03;
		bkColr = bkColr | (bkColr << 2);
		bkColr = bkColr | (bkColr << 4);
	}
	else
	{	/* 4 bpp */
		flipMask = 1;
		shiftMask = 0xf0;
		firstOffset = 0x01;
		pnColr = pnColr & 0x0f;

/* BobB 1/15/99 - corrected for image shifting */
		pnColr = pnColr | (pnColr << 4);
/* BobB 10/15/99 - added background color */
		bkColr = bkColr & 0x0f;
		bkColr = bkColr | (bkColr << 4);
	}

	/* 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 = &DrawRectEntry1B2_4B;
			Blit_Clip_Region(blitRec, &dRect, &sRect);
			goto WI1_RTN;
		}
	}

	DrawRectEntry1B2_4B(blitRec);
WI1_RTN:
	nuResume(dstBmap);

⌨️ 快捷键说明

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