Exemplo n.º 1
0
/*
 * convert a tcl keyed list into a feature db
 */
feature_db_struct* klist_feature(Tcl_Interp *interp,
                                 char **items,
                                 int num_items)
{
    feature_db_struct *feat_db;
    int i;
    Tcl_Obj *ptr;
    Tcl_Obj *list;

    if (NULL == (feat_db = (feature_db_struct *)xmalloc(num_items *
                           sizeof(feature_db_struct))))
        return NULL;

    for (i = 0; i < num_items; i++) {
        if (NULL == (feat_db[i].type = (char *)xmalloc(16 * sizeof(char))))
            return NULL;
        if (NULL == (feat_db[i].fill = (char *)xmalloc(20 * sizeof(char))))
            return NULL;
        if (NULL == (feat_db[i].outline = (char *)xmalloc(20 * sizeof(char))))
            return NULL;
        if (NULL == (feat_db[i].shape = (char *)xmalloc(20 * sizeof(char))))
            return NULL;

        list = Tcl_NewStringObj(items[i], -1);
        getls(feat_db[i], type);
        getli(feat_db[i], index);
        getls(feat_db[i], fill);
        getls(feat_db[i], outline);
        getli(feat_db[i], width);
        getls(feat_db[i], shape);
    }
    return feat_db;

}
Exemplo n.º 2
0
BOOL
bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size,
		  int Bpp)
{
	unsigned char *end = input + size;
	unsigned char *prevline = NULL, *line = NULL;
	int opcode, count, offset, isfillormix, x = width;
	int lastopcode = -1, insertmix = False, bicolour = False;
	uint8 code;
	uint32 colour1 = 0, colour2 = 0;
	uint8 mixmask, mask = 0;
	uint32 mix = 0xffffffff;
	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 = cvalx(&input, Bpp);
			case 3:	/* Colour */
				colour2 = cvalx(&input, Bpp);
				break;
			case 6:	/* SetMix/Mix */
			case 7:	/* SetMix/FillOrMix */
				mix = cvalx(&input, Bpp);
				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 * Bpp;
			}

			switch (opcode)
			{
				case 0:	/* Fill */
					if (insertmix)
					{
						if (prevline == NULL)
							setli(line, x, mix, Bpp);
						else
							setli(line, x,
							      getli(prevline, x, Bpp) ^ mix, Bpp);

						insertmix = False;
						count--;
						x++;
					}

					if (prevline == NULL)
					{
					REPEAT(setli(line, x, 0, Bpp))}
					else
					{
						REPEAT(setli
						       (line, x, getli(prevline, x, Bpp), Bpp));
					}
					break;

				case 1:	/* Mix */
					if (prevline == NULL)
					{
						REPEAT(setli(line, x, mix, Bpp));
					}
					else
					{
						REPEAT(setli
						       (line, x, getli(prevline, x, Bpp) ^ mix,
							Bpp));
					}
					break;

				case 2:	/* Fill or Mix */
					if (prevline == NULL)
					{
						REPEAT(MASK_UPDATE();
						       if (mask & mixmask) setli(line, x, mix, Bpp);
						       else
						       setli(line, x, 0, Bpp););
					}
					else
					{
						REPEAT(MASK_UPDATE();
						       if (mask & mixmask)
						       setli(line, x, getli(prevline, x, Bpp) ^ mix,
							     Bpp);
						       else
						       setli(line, x, getli(prevline, x, Bpp),
							     Bpp););
					}