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

📄 bitmap.c

📁 LInux 下的远程桌面工具 Rdesktop
💻 C
📖 第 1 页 / 共 2 页
字号:
			}		}	}	return True;}/* 3 byte bitmap decompress */static RD_BOOLbitmap_decompress3(uint8 * output, int width, int height, uint8 * input, int size){	uint8 *end = input + size;	uint8 *prevline = NULL, *line = NULL;	int opcode, count, offset, isfillormix, x = width;	int lastopcode = -1, insertmix = False, bicolour = False;	uint8 code;	uint8 colour1[3] = {0, 0, 0}, colour2[3] = {0, 0, 0};	uint8 mixmask, mask = 0;	uint8 mix[3] = {0xff, 0xff, 0xff};	int fom_mask = 0;	while (input < end)	{		fom_mask = 0;		code = CVAL(input);		opcode = code >> 4;		/* Handle different opcode forms */		switch (opcode)		{			case 0xc:			case 0xd:			case 0xe:				opcode -= 6;				count = code & 0xf;				offset = 16;				break;			case 0xf:				opcode = code & 0xf;				if (opcode < 9)				{					count = CVAL(input);					count |= CVAL(input) << 8;				}				else				{					count = (opcode <						 0xb) ? 8 : 1;				}				offset = 0;				break;			default:				opcode >>= 1;				count = code & 0x1f;				offset = 32;				break;		}		/* Handle strange cases for counts */		if (offset != 0)		{			isfillormix = ((opcode == 2) || (opcode == 7));			if (count == 0)			{				if (isfillormix)					count = CVAL(input) + 1;				else					count = CVAL(input) + offset;			}			else if (isfillormix)			{				count <<= 3;			}		}		/* Read preliminary data */		switch (opcode)		{			case 0:	/* Fill */				if ((lastopcode == opcode) && !((x == width) && (prevline == NULL)))					insertmix = True;				break;			case 8:	/* Bicolour */				colour1[0] = CVAL(input);				colour1[1] = CVAL(input);				colour1[2] = CVAL(input);			case 3:	/* Colour */				colour2[0] = CVAL(input);				colour2[1] = CVAL(input);				colour2[2] = CVAL(input);				break;			case 6:	/* SetMix/Mix */			case 7:	/* SetMix/FillOrMix */				mix[0] = CVAL(input);				mix[1] = CVAL(input);				mix[2] = CVAL(input);				opcode -= 5;				break;			case 9:	/* FillOrMix_1 */				mask = 0x03;				opcode = 0x02;				fom_mask = 3;				break;			case 0x0a:	/* FillOrMix_2 */				mask = 0x05;				opcode = 0x02;				fom_mask = 5;				break;		}		lastopcode = opcode;		mixmask = 0;		/* Output body */		while (count > 0)		{			if (x >= width)			{				if (height <= 0)					return False;				x = 0;				height--;				prevline = line;				line = output + height * (width * 3);			}			switch (opcode)			{				case 0:	/* Fill */					if (insertmix)					{						if (prevline == NULL)						{							line[x * 3] = mix[0];							line[x * 3 + 1] = mix[1];							line[x * 3 + 2] = mix[2];						}						else						{							line[x * 3] =							 prevline[x * 3] ^ mix[0];							line[x * 3 + 1] =							 prevline[x * 3 + 1] ^ mix[1];							line[x * 3 + 2] =							 prevline[x * 3 + 2] ^ mix[2];						}						insertmix = False;						count--;						x++;					}					if (prevline == NULL)					{						REPEAT						(							line[x * 3] = 0;							line[x * 3 + 1] = 0;							line[x * 3 + 2] = 0;						)					}					else					{						REPEAT						(							line[x * 3] = prevline[x * 3];							line[x * 3 + 1] = prevline[x * 3 + 1];							line[x * 3 + 2] = prevline[x * 3 + 2];						)					}					break;				case 1:	/* Mix */					if (prevline == NULL)					{						REPEAT						(							line[x * 3] = mix[0];							line[x * 3 + 1] = mix[1];							line[x * 3 + 2] = mix[2];						)					}					else					{						REPEAT						(							line[x * 3] =							 prevline[x * 3] ^ mix[0];							line[x * 3 + 1] =							 prevline[x * 3 + 1] ^ mix[1];							line[x * 3 + 2] =							 prevline[x * 3 + 2] ^ mix[2];						)					}					break;				case 2:	/* Fill or Mix */					if (prevline == NULL)					{						REPEAT						(							MASK_UPDATE();							if (mask & mixmask)							{								line[x * 3] = mix[0];								line[x * 3 + 1] = mix[1];								line[x * 3 + 2] = mix[2];							}							else							{								line[x * 3] = 0;								line[x * 3 + 1] = 0;								line[x * 3 + 2] = 0;							}						)					}					else					{						REPEAT						(							MASK_UPDATE();							if (mask & mixmask)							{								line[x * 3] = 								 prevline[x * 3] ^ mix [0];								line[x * 3 + 1] =								 prevline[x * 3 + 1] ^ mix [1];								line[x * 3 + 2] =								 prevline[x * 3 + 2] ^ mix [2];							}							else							{								line[x * 3] =								 prevline[x * 3];								line[x * 3 + 1] =								 prevline[x * 3 + 1];								line[x * 3 + 2] =								 prevline[x * 3 + 2];							}						)					}					break;				case 3:	/* Colour */					REPEAT					(						line[x * 3] = colour2 [0];						line[x * 3 + 1] = colour2 [1];						line[x * 3 + 2] = colour2 [2];					)					break;				case 4:	/* Copy */					REPEAT					(						line[x * 3] = CVAL(input);						line[x * 3 + 1] = CVAL(input);						line[x * 3 + 2] = CVAL(input);					)					break;				case 8:	/* Bicolour */					REPEAT					(						if (bicolour)						{							line[x * 3] = colour2[0];							line[x * 3 + 1] = colour2[1];							line[x * 3 + 2] = colour2[2];							bicolour = False;						}						else						{							line[x * 3] = colour1[0];							line[x * 3 + 1] = colour1[1];							line[x * 3 + 2] = colour1[2];							bicolour = True;							count++;						}					)					break;				case 0xd:	/* White */					REPEAT					(						line[x * 3] = 0xff;						line[x * 3 + 1] = 0xff;						line[x * 3 + 2] = 0xff;					)					break;				case 0xe:	/* Black */					REPEAT					(						line[x * 3] = 0;						line[x * 3 + 1] = 0;						line[x * 3 + 2] = 0;					)					break;				default:					unimpl("bitmap opcode 0x%x\n", opcode);					return False;			}		}	}	return True;}/* decompress a colour plane */static intprocess_plane(uint8 * in, int width, int height, uint8 * out, int size){	int indexw;	int indexh;	int code;	int collen;	int replen;	int color;	int x;	int revcode;	uint8 * last_line;	uint8 * this_line;	uint8 * org_in;	uint8 * org_out;	org_in = in;	org_out = out;	last_line = 0;	indexh = 0;	while (indexh < height)	{		out = (org_out + width * height * 4) - ((indexh + 1) * width * 4);		color = 0;		this_line = out;		indexw = 0;		if (last_line == 0)		{			while (indexw < width)			{				code = CVAL(in);				replen = code & 0xf;				collen = (code >> 4) & 0xf;				revcode = (replen << 4) | collen;				if ((revcode <= 47) && (revcode >= 16))				{					replen = revcode;					collen = 0;				}				while (collen > 0)				{					color = CVAL(in);					*out = color;					out += 4;					indexw++;					collen--;				}				while (replen > 0)				{					*out = color;					out += 4;					indexw++;					replen--;				}			}		}		else		{			while (indexw < width)			{				code = CVAL(in);				replen = code & 0xf;				collen = (code >> 4) & 0xf;				revcode = (replen << 4) | collen;				if ((revcode <= 47) && (revcode >= 16))				{					replen = revcode;					collen = 0;				}				while (collen > 0)				{					x = CVAL(in);					if (x & 1)					{						x = x >> 1;						x = x + 1;						color = -x;					}					else					{						x = x >> 1;						color = x;					}					x = last_line[indexw * 4] + color;					*out = x;					out += 4;					indexw++;					collen--;				}				while (replen > 0)				{					x = last_line[indexw * 4] + color;					*out = x;					out += 4;					indexw++;					replen--;				}			}		}		indexh++;		last_line = this_line;	}	return (int) (in - org_in);}/* 4 byte bitmap decompress */static RD_BOOLbitmap_decompress4(uint8 * output, int width, int height, uint8 * input, int size){	int code;	int bytes_pro;	int total_pro;	code = CVAL(input);	if (code != 0x10)	{		return False;	}	total_pro = 1;	bytes_pro = process_plane(input, width, height, output + 3, size - total_pro);	total_pro += bytes_pro;	input += bytes_pro;	bytes_pro = process_plane(input, width, height, output + 2, size - total_pro);	total_pro += bytes_pro;	input += bytes_pro;	bytes_pro = process_plane(input, width, height, output + 1, size - total_pro);	total_pro += bytes_pro;	input += bytes_pro;	bytes_pro = process_plane(input, width, height, output + 0, size - total_pro);	total_pro += bytes_pro;	return size == total_pro;}/* main decompress function */RD_BOOLbitmap_decompress(uint8 * output, int width, int height, uint8 * input, int size, int Bpp){	RD_BOOL rv = False;	switch (Bpp)	{		case 1:			rv = bitmap_decompress1(output, width, height, input, size);			break;		case 2:			rv = bitmap_decompress2(output, width, height, input, size);			break;		case 3:			rv = bitmap_decompress3(output, width, height, input, size);			break;		case 4:			rv = bitmap_decompress4(output, width, height, input, size);			break;		default:			unimpl("Bpp %d\n", Bpp);			break;	}	return rv;}/* *INDENT-ON* */

⌨️ 快捷键说明

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