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

📄 bits5.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 2 页
字号:
	colorIndex = (tmpColor & 0x07);	/* mask off all but 3 blue msbs */
	
	if (imgFlgs & im565) tmpColor = tmpColor >> 1; /* source image 5:6:5 format ? */

	colorIndex |= ((tmpColor >> 2) & 0x038);	/* shift down for 3 green msbs and 
				mask off all but green bits */
	colorIndex |= ((tmpColor >> 4) & 0x01c0);	/* shift down for 3 red msbs and 
				mask off all but red bits */

	tmpColor = (tmpXlPtr[colorIndex]);		/* fetch long from table set */
	return;
}

void RGB16_RGB24()	/* 16 bpp source, 24 bit dest */
{
	long colorIndex;

	if (imgFlgs & im565)	/* source image 5:6:5 format ? */
	{
		colorIndex = ((tmpColor & 0xf800) << 3);	/* get red and shift up */
		colorIndex |= ((tmpColor & 0x07e0) << 2);	/* get green and shift for blue */
		colorIndex |= ((tmpColor & 0x01f) << 3);	/* get blue and final shift 3 */
	}
	else	/* source image 5:5:5 format */
	{
		colorIndex = ((tmpColor & 0x7C00) << 3);	/* get red and shift up */
		colorIndex |= ((tmpColor & 0x03e0) << 3);	/* get green and shift for blue */
		colorIndex |= ((tmpColor & 0x01f) << 3);	/* get blue and final shift 3 */
	}
	tmpColor = colorIndex;
	return;
}

void RGB24_lowcolor() /* 24 bpp source,
			<= 256 color dest */
{
	/* takes the 3 msbs of the 8 bits of RG&B to make a 9 bit index to xlate table
	which must be 512 entries long */

	int colorIndex;

	tmpColor = (tmpColor >> 5);	/* initial shift for all colors */
	colorIndex = (tmpColor & 0x07);	/* mask off all but 3 blue msbs */
	colorIndex |= ((tmpColor >> 5) & 0x038);	/* shift down for 3 green msbs and 
				mask off all but green bits */
	colorIndex |= ((tmpColor >> 10) & 0x01c0);	/* shift down for 3 red msbs and 
				mask off all but red bits */

	tmpColor = (tmpXlPtr[colorIndex]);		/* fetch long from table set */
	return;
}

void RGB24_RGB16()	/* 24 bpp source, highcolor dest */
{
	/* takes the 5 msbs of the 8 bits of RG&B (6 of G if 5:6:5) to make a 15/16 bit value */

	long colorIndex;

	tmpColor = (tmpColor >> 3);	/* initial shift for all colors */
	colorIndex = (tmpColor & 0x1f);	/* mask off all but 5 blue msbs */

	if (flags & mf565)  /* source image 5:6:5 format ? */
	{
		colorIndex |= ((tmpColor >> 2) & 0x7E0);	/* shift down for 5 green msbs and 
				mask off all but green bits */
		colorIndex |= ((tmpColor >> 5) & 0xf800);	/* shift down for 5 red msbs and 
				mask off all but red bits */
	}
	else	/* source image 5:5:5 format */
	{
		colorIndex |= ((tmpColor >> 3) & 0x3E0);	/* shift down for 5 green msbs and 
				mask off all but green bits */
		colorIndex |= ((tmpColor >> 6) & 0x7c00);	/* shift down for 5 red msbs and 
				mask off all but red bits */
	}
	tmpColor = colorIndex;
	return;
}


void XL_NOP()	/* don't translate */
{
	return;
}

/* -------------------- Get image pixel routines -------------------------- */

void GetImPix1(void)	/* 1 bit GetImPix */
{
	/* 1 bit and 1 bit/multi-plane source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	planeSize = size of one plane in bytes
	planeTotal = size of all planes in bytes
	curX = current pixel X coord */
	long bfrX;
	short bfrBit;
	int i;
 
	bfrX = curX	+ tmpSrcImg->imAlign; /* figure byte offset + the
				image alignment bits (0..15) */
	bfrBit = 7 - (bfrX & 7);	/* which bit in byte */
	bfrX = (bfrX >> 3) + srcOffset;	/* byte offset relative to image start */
	bfrX += planeTotal;	/* and move to pixel in last plane */

	/* We are now at the desired raster, byte, and bit offset. */
	tmpColor = 0;	/* color value */

	for (i = 0; i < tmpSrcImg->imPlanes; i++)	/* for each image plane */
	{
		tmpColor = (tmpColor << 1);		/* shift last color bit */
		tmpColor += ((tmpSrcImg->imData[bfrX] >> bfrBit) & 1);	/* get bit */
		bfrX -= planeSize;	/* point to next planes data */
	}
	return;
}

void GetImPix2(void)	/* 2 bit GetImPix */
{
	/* 2 bit source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	planeSize = size of one plane in bytes
	curX = current pixel X coord
	note: a hibble is half a nibble */
	long bfrX;
	short bfrBit;

	bfrX = curX	+ tmpSrcImg->imAlign; /* figure byte offset + the
				image alignment bits (0..15) */
	bfrBit = (3 - (bfrX & 3)) << 1;	/* compute hibble address */
	bfrX = (bfrX >> 2) + srcOffset;	/* byte offset relative to image start */
	tmpColor = ((tmpSrcImg->imData[bfrX] >> bfrBit) & 3);	/* get bits */
	return;
}

void GetImPix4(void)	/* 4 bit GetImPix */
{
	/* 4 bit source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	curX = current pixel X coord */
	long bfrX;
	short bfrBit;

	bfrX = curX	+ tmpSrcImg->imAlign; /* figure byte offset + the
				image alignment bits (0..15) */
	bfrBit = (1 - (bfrX & 1)) << 2;	/* compute nibble address */
	bfrX = (bfrX >> 1) + srcOffset;	/* byte offset relative to image start */
	tmpColor = ((tmpSrcImg->imData[bfrX] >> bfrBit) & 0x0f);	/* get bits */
	return;
}

void GetImPix8(void)	/* 8 bit GetImPix */
{
	/* 8 bit source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	curX = current pixel X coord */
	long bfrX;

	bfrX = curX	+ tmpSrcImg->imAlign + srcOffset; /* figure byte offset + the
				image alignment bits (0..15) */
	tmpColor = tmpSrcImg->imData[bfrX];	/* get byte */
	return;
}

void GetImPix16(void)	/* 16 bit GetImPix */
{
	/* 15/16 bit source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	curX = current pixel X coord */
	long bfrX;

	bfrX = (curX << 1) + srcOffset; /* figure word offset */
	tmpColor = (tmpSrcImg->imData[bfrX] << 8) +
		tmpSrcImg->imData[bfrX+1];	/* get both bytes */
	return;
}

void GetImPix24(void)	/* 24 bit GetImPix */
{
	/* 24 bit source
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	curX = current pixel X coord */
	long bfrX;

	bfrX = (curX << 1) + curX + srcOffset; /* figure 3 byte offset */
	tmpColor = (tmpSrcImg->imData[bfrX] << 8) +
		tmpSrcImg->imData[bfrX+1];	/* get first two bytes */
	tmpColor = (tmpColor << 8) + tmpSrcImg->imData[bfrX+2];	/* get last byte */
	return;
}

void GetImPix83(void)	/* 8 bit/3 plane GetImPix */
{
	/* 8 bit 3  plane source used on 24 bit PCX files
	tmpSrcImg -> source image data area
	srcOffset -> beginning of raster line
	planeSize = size of one plane in bytes
	curX = current pixel X coord */
	long bfrX;

	bfrX = curX + tmpSrcImg->imAlign + srcOffset; /* figure byte offset */
	tmpColor = (tmpSrcImg->imData[bfrX] << 8);	/* get red byte */
	bfrX += planeSize;	/* next plane */
	tmpColor = (tmpColor << 8) + tmpSrcImg->imData[bfrX];	/* get green byte */
	bfrX += planeSize;	/* next plane */
	tmpColor = (tmpColor << 8) + tmpSrcImg->imData[bfrX];	/* get blue byte */
	return;
}

/* -------------------- set image pixel routines -------------------------- */

void SetImPix1(void)	/* 1 bit SetImPix */
{
	/* The 1 bit/pix also handles the multi-plane case
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord */

	long bfrX;
	unsigned char bfrBit;
	int i;
	unsigned char dstColor;

	/* make the bit mask for the desired pixel to affect in the byte */
	bfrBit = 7 - (curX & 7);	/* only want modulo bits */
	bfrBit = (1 << bfrBit);

	bfrX = (curX >> 3) + dstOffset;	/* byte offset relative to image start */

	/* We are now at the desired byte to affect (in plane 0, if multiplane)
	Since we are creating this image buffer ourselves, there is no alignment
	to worry about. */
	for (i = 0; i < tmpDstImg->imPlanes; i++)	/* for each image plane */
	{
		dstColor = tmpDstImg->imData[bfrX];	/* get byte the pixel is in */
		dstColor &= ~bfrBit;	/* clear the bit to affect */

		if (tmpColor & 1) dstColor |= bfrBit;	/* does this plane get a bit set */

		tmpDstImg->imData[bfrX] = dstColor;		/* put updated byte back in plane */
		bfrX += dstplaneSize;	/* point to next planes data */
		tmpColor = (tmpColor >> 1);		/* get next bit */
	}
	return;
}

void SetImPix2(void)	/* 2 bit SetImPix */
{
	/* 2 bit per pixel dest 
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord
	note: a hibble is half a nibble */

	long bfrX;
	unsigned char bfrBit;
	unsigned char dstColor;

	/* make the bit masks for the desired pixels to affect in the byte */
	bfrBit = (3 - (curX & 3)) << 1;	/* compute hibble address */
	tmpColor = (tmpColor << bfrBit);
	bfrBit = (3 << bfrBit);

	bfrX = (curX >> 2) + dstOffset;	/* byte offset relative to image start */
	dstColor = tmpDstImg->imData[bfrX];	/* get byte the pixel is in */
	dstColor &= ~bfrBit;	/* clear the bit to affect */
	dstColor |= tmpColor;	/* set appropriate bits */
	tmpDstImg->imData[bfrX] = dstColor;	/* put updated byte back in plane */
	return;
}

void SetImPix4()	/* 4 bit SetImPix */
{
	/* 4 bit per pixel dest 
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord */

	long bfrX;
	unsigned char bfrBit;
	unsigned char dstColor;

	/* make the bit masks for the desired pixels to affect in the byte */
	bfrBit = (1 - (curX & 1)) << 2;	/* compute nibble address */
	tmpColor = (tmpColor << bfrBit);

/* BobB 7/23/98 - corrected the following line for mask
	bfrBit = (7 << bfrBit); */
	bfrBit = (0x0f << bfrBit);

	bfrX = (curX >> 1) + dstOffset;	/* byte offset relative to image start */
	dstColor = tmpDstImg->imData[bfrX];	/* get byte the pixel is in */
	dstColor &= ~bfrBit;	/* clear the bit to affect */
	dstColor |= tmpColor;	/* set appropriate bits */
	tmpDstImg->imData[bfrX] = dstColor;	/* put updated byte back in plane */
	return;
}

void SetImPix8()	/* 8 bit SetImPix */
{
	/* 8 bit per pixel dest 
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord */

	long bfrX;

	bfrX = curX + dstOffset;	/* byte offset relative to image start */

/* BobB 5/5/98 - corrected the following line to get rid of a compiler warning
	tmpDstImg->imData[bfrX] = tmpColor;*/	/* put byte in plane */
	tmpDstImg->imData[bfrX] = (byte) tmpColor;	/* put byte in plane */
	return;
}

void SetImPix16()	/* 16 bit SetImPix */
{
	/* 16 bit per pixel dest 
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord */

	long bfrX;

	bfrX = (curX << 1) + dstOffset;	/* word offset relative to image start */

/* BobB 5/5/98 - corrected the following two lines to get rid of compiler warnings
	tmpDstImg->imData[bfrX] = (tmpColor >> 8); */	/* put first byte in plane */
	/* tmpDstImg->imData[bfrX+1] = (tmpColor & 0xff); */	/* put second byte in plane */
/* BobB 12/18/98 - corrected the following two lines for byte ordering
	tmpDstImg->imData[bfrX] = (byte) (tmpColor >> 8); */	/* put first byte in plane */
	/* tmpDstImg->imData[bfrX+1] = (byte) (tmpColor & 0xff);	 put second byte in plane */
	tmpDstImg->imData[bfrX] = (byte) (tmpColor & 0xff);	/* put first byte in plane */
	tmpDstImg->imData[bfrX+1] = (byte) (tmpColor >> 8);	/* put second byte in plane */
	return;
}

void SetImPix24()	/* 24 bit SetImPix */
{
	/* 24 bit per pixel dest 
	tmpDstImg -> destination image data area
	dstOffset -> beginning of raster line
	dstX = destination pixel X coord */

	long bfrX;

/* BobB 5/5/98 - corrected the following for 3 byte addressing
	bfrX = (curX << 1) + dstOffset;*/	/* word offset relative to image start */
	bfrX = (curX << 1) + curX + dstOffset; /* figure 3 byte offset */
	tmpDstImg->imData[bfrX+2] = (tmpColor & 0xff);	/* put third byte in plane */
	tmpColor = (tmpColor >> 8);	/* shift color byte */

/* BobB 5/5/98 - corrected the following two lines to get rid of compiler warnings
	tmpDstImg->imData[bfrX+1] = (tmpColor & 0xff); */	/* put second byte in plane */
	/* tmpDstImg->imData[bfrX] = (tmpColor >> 8); */	/* put first byte in plane */
	tmpDstImg->imData[bfrX+1] = (byte) (tmpColor & 0xff);	/* put second byte in plane */
	tmpDstImg->imData[bfrX] = (byte) (tmpColor >> 8);	/* put first byte in plane */
	return;
}

⌨️ 快捷键说明

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