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

📄 wndo6.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 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          */
/*                                                                       */
/*      WNDO6.c                                          1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the AlignPattern function.                    */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Robert G. Burrill, Accelerated Technology, Inc.                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*                                                                       */
/*************************************************************************/

#include "meta_wnd.h"
#include "metconst.h"    /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h"    /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"


/* Function AlignPattern aligns the specified pattern number, PATNBR,
with the specified pixel position.  Patterns can be any size so long
as they meet the conditions listed below.

ERROR CONDITIONS (c_BadPatt):

	a)  pattern number is < 0 or > 31.	[ noop, nothing happens ]
	b)  patAlign must be zero		[ noop,    "       "    ]
	c)  rowBytes > 1024.			[ noop,    "       "    ]
	d)  X alignment mod patWidth  > 255.	[ skip column alignment ]
	e)  Y alignment mod patHeight > 255.	[ skip row alignment    ] */
void AlignPattern(int PATNBR, int PIXX, int PIXY)
{
#define APAP1 0
#define APNAP1 1
#define APAP2D 0
#define APAP2 1
#define APNAP2D 2
#define APNAP2 3
#define APBbot 4

	char bitP1;
	char bitP2;
	char bitP2All;
	char sizlByte;
	short bytP1;
	short bytP2;
	short tCnt;
	short rowCnt;
	short numRows;
	short plnCnt;
	int xdelta;
	int ydelta;
	int rot;
	int sizRow;
	int sizPln;
	byte *bgnData;
	byte *curRow;
	byte *savCurRow;
	byte *srcCurRow;
	int BytDlt;
	int lastByte;
	int Part1;
	int Part2;
	patList *patL;
	pattern *patR;
	short grafErrValue;
	int xyAlign;
	int oldxyAlign;
	int bitsPerRow;
	int alnPatData;
	byte tempRow[32];
	/* Mask bits left */
	byte BitsLf[8] = {0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE};


	if (PATNBR > 31)
	{	/* number too large - post an error & exit */
		grafErrValue = c_AlignPat + c_BadPatt;
		nuGrafErr(grafErrValue);
		return;
	}

	patL = thePort->portPat;	/* current pattern list */
	patR = patL->patPtr[PATNBR];	/* current pattern record */

	#ifdef FIXUP386
	patR -= dllFixup;	/* unfixup */
	#endif

	if ((patR->patAlign != 0) || (patR->patBytes > 1024))
	{
		grafErrValue = c_AlignPat + c_BadPatt;
		nuGrafErr(grafErrValue);
		return;
	}

	/* First do X alignment */
	xyAlign = PIXX % patR->patWidth;	/* calculate mod of X alignment */
	if (xyAlign < 0) xyAlign += patR->patWidth;
	if (xyAlign > 255)
	{	/* alignment > 255 - post an error & move on to Y alignment */
		grafErrValue = c_AlignPat + c_BadPatt;
		nuGrafErr(grafErrValue);
		goto APYalign;
	}

	oldxyAlign = patL->patAlignX[PATNBR];	/* get old X alignment */
	patL->patAlignX[PATNBR] = xyAlign;	/* store new alignment */
	xdelta = xyAlign - oldxyAlign;
	if (xdelta == 0) goto APYalign;
	if (xdelta < 0) xdelta += patR->patWidth;

	xdelta *= patR->patBits;	/* calculate bits to shift */
	bitsPerRow = patR->patBits * patR->patWidth;

	if (bitsPerRow == 8)
	{	/* X align 8 bit pattern - rotate bits in each byte */
		curRow = &patR->patData[0];
		rot = 8 - xdelta;
		for (plnCnt = 0; plnCnt < patR->patPlanes; plnCnt++)
		{
			for (rowCnt = 0; rowCnt < patR->patHeight; rowCnt++)
			{
				alnPatData = *curRow;
				*curRow = (((alnPatData >> xdelta) |
					(alnPatData << rot)) & 0xFF);
				curRow += patR->patBytes;
			}
		}

		goto APYalign;
	}

	if (bitsPerRow < 8)
	{	/* X align < 8 bit pattern */
		rot = patR->patWidth - xdelta;
		curRow = &patR->patData[0];
		for (plnCnt = 0; plnCnt < patR->patPlanes; plnCnt++)
		{
			for (rowCnt = 0; rowCnt < patR->patHeight; rowCnt++)
			{
				alnPatData = *curRow & BitsLf[patR->patWidth];
				*curRow = (((alnPatData >> xdelta) |
					(alnPatData << rot)) & 0xFF);
				curRow += patR->patBytes;
			}
		}

		goto APYalign;
	}

	/* X align > 8 bit pattern */
	plnCnt = patR->patPlanes;	/* load plane count */
	numRows = patR->patHeight;	/* load row count */
	sizRow = patR->patBytes;	/* load row size */

	BytDlt = xdelta >> 3;	/* byte X delta */
	bitP1 = xdelta & 7;	/* bit X delta */

	lastByte = patR->patWidth * patR->patBits;
	sizlByte = lastByte & 7;	/* # bits in last byte */
	lastByte = lastByte >> 3;
	if (sizlByte != 0) lastByte++;

	bytP1 = lastByte - BytDlt;	/* part1 = total - byte_delta */
	bytP2 = BytDlt;
	lastByte--;	/* lastByte = last pat byte in row */

	if (sizlByte == 0)
	{
		bitP2All = bitP1;
	}
	else
	{
		bitP2All = (8 - sizlByte + bitP1);
	}
	bitP2 = bitP2All & 7;

	if (bitP1 == 0)
	{
		Part1 = APAP1;	/* part 1 is aligned */
	}
	else
	{
		Part1 = APNAP1;	/* part 1 is non-aligned */
	}

	if (bytP2 == 0)
	{	/* no second part */
		Part2 = APBbot;
	}
	else
	{
		if (bitP2All == 0)
		{	/* part 2 is aligned */
			Part2 = APAP2;
		}
		else
		{
			if (bitP2 == 0)
			{	/* part part 2 is aligned (dec src) */
				Part2 = APAP2D;
			}
			else
			{
				if (!(bitP2All & 8))
				{	/* part 2 is non aligned */
					Part2 = APNAP2;
				}
				else
				{	/* part 2 is non alignd (dec src) */
					Part2 = APNAP2D;
				}
			}
		}
	}

	curRow = &patR->patData[0];

	while(plnCnt--)
	{
		rowCnt = numRows;
		while(rowCnt--)
		{
			savCurRow = curRow;
			switch(Part1)
			{
			case APAP1:		/* aligned part 1 */
				for (tCnt = 0; tCnt < bytP1; tCnt++)
				{	/* copy first part (xdelta bytes) to shifted position */
					tempRow[tCnt + BytDlt] = *curRow++;
				}
				break;

			case APNAP1:	/* non-aligned part 1 */
				if (sizlByte == 0)
				{
					alnPatData = *(curRow + lastByte);
				}
				else
				{
					rot = 8 - sizlByte;
					alnPatData = (((*(curRow + lastByte - 1) << sizlByte))
						& 0xFF) | (*(curRow + lastByte) >> rot);
				}

				rot = 8 - bitP1;
				for (tCnt = 0; tCnt < bytP1; tCnt++)
				{	/* copy first part (xdelta bytes) to shifted position */
					tempRow[tCnt + BytDlt] = ((alnPatData << rot)
						& 0xFF) | (*curRow >> bitP1);
					alnPatData = *curRow++;
				}
			}
		
			switch(Part2)
			{
			case APAP2D:	/* aligned part 2 (dec src) */
				curRow--;

			case APAP2:		/* aligned part 2 */
				for (tCnt = 0; tCnt < bytP2; tCnt++)
				{	/* copy second part (total - xdelta bytes) */
					tempRow[tCnt] = *curRow++;
				}
				break;

			case APNAP2D:	/* non-aligned part 2 (dec src) */
				curRow--;

			case APNAP2:		/* non-aligned part 2 */
				rot = 8 - bitP2;
				alnPatData = *(curRow - 1);
				for (tCnt = 0; tCnt < bytP2; tCnt++)
				{	/* copy second part (total - xdelta bytes) */
					tempRow[tCnt] = ((alnPatData << rot)
						& 0xFF) | (*curRow >> bitP1);
					alnPatData = *curRow++;
				}
				break;

			case APBbot:
				break;
			}
		
			/* copy temp row back to pattern space */
			curRow = savCurRow;
			for (tCnt = 0; tCnt < sizRow; tCnt++)
			{	/* copy second part (total - xdelta bytes) */
				*savCurRow++ = tempRow[tCnt];
			}

			curRow += sizRow;	/* inc curRow */
		}
	}

	/* Now do Y alignment */
APYalign:
	xyAlign = PIXY % patR->patHeight;	/* calculate mod of X alignment */
	if (xyAlign < 0) xyAlign += patR->patHeight;
	if (xyAlign > 255)
	{	/* alignment > 255 - post an error & move on to Y alignment */
		grafErrValue = c_AlignPat + c_BadPatt;
		nuGrafErr(grafErrValue);
		return;
	}

	oldxyAlign = patL->patAlignY[PATNBR];	/* get old X alignment */
	patL->patAlignY[PATNBR] = xyAlign;	/* store new alignment */
	ydelta = xyAlign - oldxyAlign;
	if (ydelta == 0) return;
	if (ydelta < 0) ydelta += patR->patHeight;

	rot = ydelta * patR->patBytes;
	numRows = patR->patHeight;	/* load row count */
	sizPln = patR->patHeight * patR->patBytes;	/* size of plane */
	bgnData = &patR->patData[0];	/* start of data */
	plnCnt = patR->patPlanes;
	curRow = bgnData;
	
	while (plnCnt--)
	{
		rowCnt = numRows;
		savCurRow = curRow;
		for (tCnt = 0; tCnt < patR->patBytes; tCnt++)
		{
			tempRow[tCnt] = *curRow++;
		}

		srcCurRow = savCurRow;
		while (rowCnt--)
		{
			curRow = srcCurRow;
			srcCurRow -= rot;
			if (srcCurRow < bgnData) srcCurRow += sizPln;
			if (srcCurRow != savCurRow)
			{
				for (tCnt = 0; tCnt < patR->patBytes; tCnt++)
				{
					*curRow++ = *srcCurRow++;
				}
				srcCurRow -= patR->patBytes;
				continue;
			}

			for (tCnt = 0; tCnt < patR->patBytes; tCnt++)
			{
				*curRow++ = tempRow[tCnt];
			}
			srcCurRow = curRow;
			savCurRow = curRow;
			for (tCnt = 0; tCnt < patR->patBytes; tCnt++)
			{
				tempRow[tCnt] = *curRow++;
			}
		}

		bgnData += sizPln;
	}

	return;
}

⌨️ 快捷键说明

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