示例#1
0
文件: postal.c 项目: bertilxi/Pegaso
int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length)
{
	/* Handles the PLANET  system used for item tracking in the US */
	unsigned int i, sum, check_digit;
	int error_number;
	
	error_number = 0;
	
	if(length > 38) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	sum = 0;

	/* start character */
	strcpy(dest, "L");

	for (i=0; i < length; i++)
	{
		lookup(NEON, PLTable, source[i], dest);
		sum += ctoi(source[i]);
	}

	check_digit = (10 - (sum % 10)) % 10;
	concat(dest, PLTable[check_digit]);

	/* stop character */
	concat (dest, "L");

	return error_number;
}
示例#2
0
const char *MacroCodeReplacer::replaceField(const char *field){
   if (isempty(field))
      return NULL;

   size_t l = strlen(field);
      
   char *tmpfield = strdupn(field);
   char MACROS  = MACROS_NONE;
   char MACROS1 = MACROS_NONE;

   getOpt(1);   //singles [xxx[a]
   getOpt(2);   //doubles [xxx[a]

   const char *res = MacroReplacer::replaceField(tmpfield);
   free(tmpfield);

   const char *tmp;
      
   switch(MACROS){
      case MACROS_HTML      : tmp = coder->HTMLEncode(res);           break;
      case MACROS_SOFT_HTML : tmp = coder->SoftHTMLEncode(res);       break;
      case MACROS_PHTML     : tmp = coder->HTMLEncode(res, true);     break;
      case MACROS_SOFT_PHTML: tmp = coder->SoftHTMLEncode(res, true); break;
      case MACROS_URL       : tmp = coder->URLEncode(res);            break;
      case MACROS_NUMBER    : tmp = coder->numberEncode(res);         break;
      case MACROS_FLOAT     : tmp = coder->floatEncode(res, ctoi(MACROS1)); break;
      case MACROS_SQL       : tmp = coder->sqlEncode(res);            break;
      case MACROS_SQLNULL   : tmp = coder->sqlNullEncode(res);        break;
      case MACROS_NO        : tmp = res;                              break;

      default               : tmp = res;
         printflog(LOG_NOTIFY, "Macrocode: Using macros without encoding.\n");
   }

   return tmp;
};
示例#3
0
void read_time(tm_elems *tm){
    char sYear[4];
    char sMonth[2];
    char sDate[2];
    char sHour[2];
    char sMinute[2];
    char sSecond[2];
    uint8 i = 0;
    for(i=0;i<4;i++){ sYear[i] = value[i]; }
    for(i=0;i<2;i++){ sMonth[i] = value[i+5]; }
    for(i=0;i<2;i++){ sDate[i] = value[i+8]; }
    for(i=0;i<2;i++){ sHour[i] = value[i+11]; }
    for(i=0;i<2;i++){ sMinute[i] = value[i+14]; }
    for(i=0;i<2;i++){ sSecond[i] = value[i+17]; }
    tm->year = ctoi(sYear, 4)-2000;
    tm->month = ctoi(sMonth, 2);
    tm->date = ctoi(sDate, 2);
    tm->hours = ctoi(sHour, 2);
    tm->minutes = ctoi(sMinute, 2);
    tm->seconds = ctoi(sSecond, 2);
}
int code32(struct zint_symbol *symbol, unsigned char source[], int length)
{   /* Italian Pharmacode */
    int i, zeroes, error_number, checksum, checkpart, checkdigit;
    char localstr[10], risultante[7];
    long int pharmacode, remainder, devisor;
    int codeword[6];
    char tabella[34];

    /* Validate the input */
    if(length > 8) {
        strcpy(symbol->errtxt, "Input too long");
        return ERROR_TOO_LONG;
    }
    error_number = is_sane(NEON, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
        strcpy(symbol->errtxt, "Invalid characters in data");
        return error_number;
    }

    /* Add leading zeros as required */
    zeroes = 8 - length;
    memset(localstr, '0', zeroes);
    strcpy(localstr + zeroes, (char*)source);

    /* Calculate the check digit */
    checksum = 0;
    checkpart = 0;
    for(i = 0; i < 4; i++) {
        checkpart = ctoi(localstr[i * 2]);
        checksum += checkpart;
        checkpart = 2 * (ctoi(localstr[(i * 2) + 1]));
        if(checkpart >= 10) {
            checksum += (checkpart - 10) + 1;
        } else {
            checksum += checkpart;
        }
    }

    /* Add check digit to data string */
    checkdigit = checksum % 10;
    localstr[8] = itoc(checkdigit);
    localstr[9] = '\0';

    /* Convert string into an integer value */
    pharmacode = atoi(localstr);

    /* Convert from decimal to base-32 */
    devisor = 33554432;
    for(i = 5; i >= 0; i--) {
        codeword[i] = pharmacode / devisor;
        remainder = pharmacode % devisor;
        pharmacode = remainder;
        devisor /= 32;
    }

    /* Look up values in 'Tabella di conversione' */
    strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
    for(i = 5; i >= 0; i--) {
        risultante[5 - i] = tabella[codeword[i]];
    }
    risultante[6] = '\0';
    /* Plot the barcode using Code 39 */
    error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante));
    if(error_number != 0) {
        return error_number;
    }

    /* Override the normal text output with the Pharmacode number */
    ustrcpy(symbol->text, (unsigned char*)"A");
    uconcat(symbol->text, (unsigned char*)localstr);

    return error_number;
}
示例#5
0
文件: png.c 项目: domribaut/zint
int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{
	struct mainprog_info_type wpng_info;
	struct mainprog_info_type *graphic;

	unsigned char outdata[image_width * 3];
	png_structp  png_ptr;
	png_infop  info_ptr;
	graphic = &wpng_info;
	unsigned char *image_data;
	int i, row, column, errn;
	int fgred, fggrn, fgblu, bgred, bggrn, bgblu;

	switch(rotate_angle) {
		case 0:
		case 180:
			graphic->width = image_width;
			graphic->height = image_height;
			break;
		case 90:
		case 270:
			graphic->width = image_height;
			graphic->height = image_width;
			break;
	}

	/* sort out colour options */
	to_upper((unsigned char*)symbol->fgcolour);
	to_upper((unsigned char*)symbol->bgcolour);

	if(strlen(symbol->fgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	if(strlen(symbol->bgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}
	errn = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
	if (errn == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	errn = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
	if (errn == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}

	fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
	fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
	fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
	bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
	bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
	bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);

	/* Open output file in binary mode */
	if((symbol->output_options & BARCODE_STDOUT) != 0) {
		graphic->outfile = stdout;
	} else {
		if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
			strcpy(symbol->errtxt, "Can't open output file");
			return ZERROR_FILE_ACCESS;
		}
	}

	/* Set up error handling routine as proc() above */
	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL);
	if (!png_ptr) {
		strcpy(symbol->errtxt, "Out of memory");
		return ZERROR_MEMORY;
	}

	info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr) {
		png_destroy_write_struct(&png_ptr, NULL);
		strcpy(symbol->errtxt, "Out of memory");
		return ZERROR_MEMORY;
	}

	/* catch jumping here */
	if (setjmp(graphic->jmpbuf)) {
		png_destroy_write_struct(&png_ptr, &info_ptr);
		strcpy(symbol->errtxt, "libpng error occurred");
		return ZERROR_MEMORY;
	}

	/* open output file with libpng */
	png_init_io(png_ptr, graphic->outfile);

	/* set compression */
	png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);

	/* set Header block */
	png_set_IHDR(png_ptr, info_ptr, graphic->width, graphic->height,
		     8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
       PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

	/* write all chunks up to (but not including) first IDAT */
	png_write_info(png_ptr, info_ptr);

	/* set up the transformations:  for now, just pack low-bit-depth pixels
	into bytes (one, two or four pixels per byte) */
	png_set_packing(png_ptr);

	/* Pixel Plotting */

	switch(rotate_angle) {
		case 0: /* Plot the right way up */
			for(row = 0; row < image_height; row++) {
				for(column = 0; column < image_width; column++) {
					i = column * 3;
					switch(*(pixelbuf + (image_width * row) + column))
					{
						case '1':
							outdata[i] = fgred;
							outdata[i + 1] = fggrn;
							outdata[i + 2] = fgblu;
							break;
						default:
							outdata[i] = bgred;
							outdata[i + 1] = bggrn;
							outdata[i + 2] = bgblu;
							break;

					}
				}
				/* write row contents to file */
				image_data = outdata;
				png_write_row(png_ptr, image_data);
			}
			break;
		case 90: /* Plot 90 degrees clockwise */
			for(row = 0; row < image_width; row++) {
				for(column = 0; column < image_height; column++) {
					i = column * 3;
					switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row))
					{
						case '1':
							outdata[i] = fgred;
							outdata[i + 1] = fggrn;
							outdata[i + 2] = fgblu;
							break;
						default:
							outdata[i] = bgred;
							outdata[i + 1] = bggrn;
							outdata[i + 2] = bgblu;
							break;

					}
				}

				/* write row contents to file */
				image_data = outdata;
				png_write_row(png_ptr, image_data);
			}
			break;
		case 180: /* Plot upside down */
			for(row = 0; row < image_height; row++) {
				for(column = 0; column < image_width; column++) {
					i = column * 3;
					switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1)))
					{
						case '1':
							outdata[i] = fgred;
							outdata[i + 1] = fggrn;
							outdata[i + 2] = fgblu;
							break;
						default:
							outdata[i] = bgred;
							outdata[i + 1] = bggrn;
							outdata[i + 2] = bgblu;
							break;

					}
				}

				/* write row contents to file */
				image_data = outdata;
				png_write_row(png_ptr, image_data);
			}
			break;
		case 270: /* Plot 90 degrees anti-clockwise */
			for(row = 0; row < image_width; row++) {
				for(column = 0; column < image_height; column++) {
					i = column * 3;
					switch(*(pixelbuf + (image_width * column) + (image_width - row - 1)))
					{
						case '1':
							outdata[i] = fgred;
							outdata[i + 1] = fggrn;
							outdata[i + 2] = fgblu;
							break;
						default:
							outdata[i] = bgred;
							outdata[i + 1] = bggrn;
							outdata[i + 2] = bgblu;
							break;

					}
				}

				/* write row contents to file */
				image_data = outdata;
				png_write_row(png_ptr, image_data);
			}
			break;
	}

	/* End the file */
	png_write_end(png_ptr, NULL);

	/* make sure we have disengaged */
	if (png_ptr && info_ptr) png_destroy_write_struct(&png_ptr, &info_ptr);
	fclose(wpng_info.outfile);
	return 0;
}
int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 11 */

    int i;
	int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
	int weight[128], error_number;
	char dest[1024]; /* 6 +  121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
	char checkstr[3];
	
	error_number = 0;

	if(length > 121) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(SODIUM, source, length);
    if(error_number == ERROR_INVALID_DATA1) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	c_weight = 1;
	c_count = 0;
	k_weight = 1;
	k_count = 0;

	/* start character */
	strcpy(dest, "112211");

	/* Draw main body of barcode */
	for(i = 0; i < length; i++) {
		lookup(SODIUM, C11Table, source[i], dest);
		if(source[i] == '-')
			weight[i] = 10;
		else
			weight[i] = ctoi(source[i]);
	}

	/* Calculate C checksum */
	for(h = length - 1; h >= 0; h--) {
		c_count += (c_weight * weight[h]);
		c_weight++;

		if(c_weight > 10) {
			c_weight = 1;
		}
	}
	c_digit = c_count % 11;

	weight[length] = c_digit;

	/* Calculate K checksum */
	for(h = length; h >= 0; h--) {
		k_count += (k_weight * weight[h]);
		k_weight++;

		if(k_weight > 9) {
			k_weight = 1;
		}
	}
	k_digit = k_count % 11;

	checkstr[0] = itoc(c_digit);
	checkstr[1] = itoc(k_digit);
	if(checkstr[0] == 'A') { checkstr[0] = '-'; }
	if(checkstr[1] == 'A') { checkstr[1] = '-'; }
	checkstr[2] = '\0';
	lookup(SODIUM, C11Table, checkstr[0], dest);
	lookup(SODIUM, C11Table, checkstr[1], dest);
	
	/* Stop character */
	concat (dest, "11221");

	expand(symbol, dest);

	ustrcpy(symbol->text, source);
	uconcat(symbol->text, (unsigned char*)checkstr);
	return error_number;
}
示例#7
0
void process_sample_delay(){
    DataLogging_SetSampleDelay(ctoi(value, valuelen));
}
示例#8
0
文件: upcean.c 项目: Jinxiaohai/QT
void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ /* UPC E is a zero-compressed version of UPC A */
	unsigned int i, num_system;
	char emode, equivalent[12], check_digit, parity[8], temp[8];
	char hrt[9];

	/* Two number systems can be used - system 0 and system 1 */
	if(ustrlen(source) == 7) {
		switch(source[0]) {
			case '0': num_system = 0; break;
			case '1': num_system = 1; break;
			default: num_system = 0; source[0] = '0'; break;
		}
		strcpy(temp, (char*)source);
		strcpy(hrt, (char*)source);
		for(i = 1; i <= 7; i++) {
			source[i - 1] = temp[i];
		}
	}
	else {
		num_system = 0;
		hrt[0] = '0';
		hrt[1] = '\0';
		concat(hrt, (char*)source);
	}

	/* Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5) */
	emode = source[5];
	for(i = 0; i < 11; i++) {
		equivalent[i] = '0';
	}
	if(num_system == 1) { equivalent[0] = temp[0]; }
	equivalent[1] = source[0];
	equivalent[2] = source[1];
	equivalent[11] = '\0';

	switch(emode)
	{
		case '0':
		case '1':
		case '2':
			equivalent[3] = emode;
			equivalent[8] = source[2];
			equivalent[9] = source[3];
			equivalent[10] = source[4];
			break;
		case '3':
			equivalent[3] = source[2];
			equivalent[9] = source[3];
			equivalent[10] = source[4];
			if(((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
				/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
				strcpy(symbol->errtxt, "Invalid UPC-E data");
			}
			break;
		case '4':
			equivalent[3] = source[2];
			equivalent[4] = source[3];
			equivalent[10] = source[4];
			if(source[3] == '0') {
				/* Note 2 - "X4 shall not be equal to 0" */
				strcpy(symbol->errtxt, "Invalid UPC-E data");
			}
			break;
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			equivalent[3] = source[2];
			equivalent[4] = source[3];
			equivalent[5] = source[4];
			equivalent[10] = emode;
			if(source[4] == '0') {
				/* Note 3 - "X5 shall not be equal to 0" */
				strcpy(symbol->errtxt, "Invalid UPC-E data");
			}
			break;
	}

	/* Get the check digit from the expanded UPCA code */

	check_digit = upc_check(equivalent);

	/* Use the number system and check digit information to choose a parity scheme */
	if(num_system == 1) {
		strcpy(parity, UPCParity1[ctoi(check_digit)]);
	} else {
		strcpy(parity, UPCParity0[ctoi(check_digit)]);
	}

	/* Take all this information and make the barcode pattern */

	/* start character */
	concat (dest, "111");

	for(i = 0; i <= ustrlen(source); i++) {
		switch(parity[i]) {
			case 'A': lookup(NEON, EANsetA, source[i], dest); break;
			case 'B': lookup(NEON, EANsetB, source[i], dest); break;
		}
	}

	/* stop character */
	concat (dest, "111111");
	
	hrt[7] = check_digit;
	hrt[8] = '\0';
	ustrcpy(symbol->text, (unsigned char*)hrt);
}
示例#9
0
int main()
{

	int start_loc = 0, locctr = 0 , end_loc, program_length = 0, instr_length = 0;
	char program_name[8] = {'\0'}, filename[] = "fig2.5.txt";
	
	FILE *fptr;
	
	char accept[100] = {'\0'};
   	char label[30], opcode[30], operand[30];

	int A = 0, X = 0, L = 0,PC = 0, SW = 0, B = 0, S = 0, T = 0, F = 0;
	int n = 1, i = 1, x = 0, b = 0, p = 0, e = 0, address = 0;

/************************************ pass 1 ****************************************/  	
	if((fptr = fopen(filename, "r")) != NULL)
	{
        //printf("file found\n");
        
        fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

        if(strcmp(opcode,"START") == 0)
        {
			int k, six = 1, hvalue = 0;
			strcpy(program_name, label);
			if(isHexadecimal(operand) == 1)
			{
				for(k = strlen(operand) - 1, six ; k >= 0 ; k--, six *= 16)
				{
					int temp = (int)operand[k] - 48;
					if(temp > 9)
					{
						temp = 10 + (int)operand[k] - 65;
					}

					hvalue += temp * six;
				}
				start_loc = hvalue;
				locctr = hvalue;
			}
			else
			{
				sscanf(operand, "%d", &start_loc);
				sscanf(operand, "%d", &locctr);
			}
        }
		else
		{
			locctr = 0;
		}

		fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);


        while(!feof(fptr) && strcmp(opcode,"END") != 0)
        {
            if(isComment(accept) == 0) // not a comment
            {
				if(strlen(label) != 0)
				{
					if(inSymbol(label) != -1)
					{
						printf("error, duplicate symbol !!");
						return 0;
					}
					else
					{
						strcpy(SymbolTable[STindex].label, label);
						SymbolTable[STindex++].address = locctr; 
					}
				}

				if(isInstruction(opcode, "FORMAT") != 0)
				{
					if(opcode[0] == '+')
					{
						instr_length = 4;
					}
					else
					{
						instr_length = isInstruction(opcode, "FORMAT");
					}
				}
				else if(strcmp(opcode,"WORD") == 0)
				{
					instr_length = 3;
				}
				else if(strcmp(opcode,"RESW") == 0)
				{
					instr_length = 3 * ctoi(operand, "RESW");
				}
				else if(strcmp(opcode,"RESB") == 0)
				{
					instr_length = ctoi(operand, "RESB");
				}
				else if(strcmp(opcode,"BYTE") == 0)
				{
					instr_length = ctoi(operand, "BYTE");
				}
				else if(strcmp(opcode,"BASE") == 0)
				{
					instr_length = 0;
					int bp = inSymbol(operand);
					B = bp;
				}
				else if(strcmp(opcode,"END") == 0)
				{
					instr_length = 0;
				}
				else
				{
					printf("error, invaild operation code !!");
					return 0;
				}
            }

			locctr += instr_length;
			instr_length = 0;
			fgets(accept, 30, fptr);
			read(label, opcode, operand, accept);
        }

		end_loc = locctr;
		program_length =  end_loc - start_loc;
		fclose(fptr);
    }
    else
    {
        printf("file not found\n");
    }
/************************************ pass 2 ****************************************//*H T E M*/

	locctr = 0;
	instr_length = 0;

	if((fptr = fopen(filename, "r")) != NULL)
	{
        //printf("file found\n");

        fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

        if(strcmp(opcode,"START") == 0)
        {
			int k, six = 1, hvalue = 0;
			strcpy(program_name, label);
			if(isHexadecimal(operand) == 1)
			{
				for(k = strlen(operand) - 1, six ; k >= 0 ; k--, six *= 16)
				{
					int temp = (int)operand[k] - 48;
					if(temp > 9)
					{
						temp = 10 + (int)operand[k] - 65;
					}

					hvalue += temp * six;
				}
				locctr = hvalue;
			}
			else
			{
				sscanf(operand, "%d", &locctr);
			}
        }
		else
		{
			locctr = 0;
		}

		fgets(accept, 30, fptr);
		read(label, opcode, operand, accept);

		printf("H %-6s %06X %06X\n",program_name, start_loc, program_length);

        while(!feof(fptr) && strcmp(opcode,"END") != 0)
        {
			n = i = 1;
			x = b = p = e = 0;

			char object_code[50] = {'\0'};
            if(isComment(accept) == 0) // not a comment
            {
				if(strcmp(opcode,"WORD") == 0)
				{
					instr_length = 3;
					generate_objcode(object_code, operand, "WORD");
				}
				else if(strcmp(opcode,"RESW") == 0)
				{
					instr_length = 3 * ctoi(operand, "RESW");
				}
				else if(strcmp(opcode,"RESB") == 0)
				{
					instr_length = ctoi(operand, "RESB");
				}
				else if(strcmp(opcode,"BYTE") == 0)
				{
					instr_length = ctoi(operand, "BYTE");
					generate_objcode(object_code, operand, "BYTE");
				}
				else if(strcmp(opcode,"BASE") == 0)
				{
					instr_length = 0;
					noobj = 1;
				}
				else if(strcmp(opcode,"END") == 0)
				{
					instr_length = 0;
					noobj = 1;
				}
				else if(isInstruction(opcode, "FORMAT") != 0)
				{
					if(opcode[0] == '+')
					{			
						char temp[10] = {'\0'};
						strcpy(temp,strtok(operand,"#@"));
						if(inSymbol(temp) != -1)
						{
							Mrecord[Mindex++] = locctr + 1;  
						}

						instr_length = 4;
						e = 1;
						b = p = 0;
					}
					else
					{
						instr_length = isInstruction(opcode, "FORMAT");
					}
				}
				else
				{
					printf("error, invaild operation code !!");
					return 0;
				}
            }
/****************************************************************************************/			
			switch (operand[0])
			{
				case '@':
					n = 1; i = 0;
					break;
				case '#':
					n = 0; i = 1;
					break;
				default:
					n = i = 1;
					if(strstr(operand,",X")!=NULL)
					{
						x = 1;
						strtok(operand,",");
					}
					break;
			}

			if(inSymbol(operand) != -1)
			{
				b = 0; p = 1;
				if(opcode[0] == '+')
				{
					e = 1; b = p = 0;
				}
				address=inSymbol(operand);
			}
			else if(isdigit(operand[1])!=0)
			{
				sscanf(operand + 1,"%d",&address);
			}
			

			if(p == 1)
			{
				address = address - (locctr + instr_length);

				if(address > 2047 || address < -2048)
				{
					b = 1; p = 0;
					address = inSymbol(operand) - B;
				}
			}

			int format = isInstruction(opcode, "FORMAT"), op = isInstruction(opcode, "OPCODE");

			if(strcmp(opcode,"RSUB") == 0)
			{
				b = p = 0;
				address = 0;
			}
						
/******************************************************************************/
			char *head = (char*)malloc(4 * sizeof(char));
			if(format>=3)
			{
				op *= 16;	n *= 32;	i *= 16;	x *= 8;		b *= 4;		p *= 2;
				op += n + i + x + b + p + e;
				sprintf(object_code,"%03X",op);
			}
			else if(format==2)
				sprintf(object_code,"%02X",op);

			if(opcode[0]=='+')
				sprintf(object_code+3,"%05X",address);
			else if(format==3)
			{
				if(address<0)
				{
					sprintf(head,"%3hX",address);
					strcpy(object_code+3,head+1);
				}
				else
					sprintf(object_code+3,"%03X",address);
			}
			else if(format==2)
			{
				sprintf(object_code+2,"%1X",search_reg(operand[0]));
				if(strlen(operand) > 2)
					sprintf(object_code+3,"%1X",search_reg(operand[2]));
				else
					sprintf(object_code+3,"%1X",0);
			}

/*******************************************************************************/

			printf("T %06X %02X %s\n",locctr, strlen(object_code), object_code);

			locctr += instr_length;
			instr_length = 0;

			fgets(accept, 30, fptr);
			read(label, opcode, operand, accept);
        }
		printMrecord();
		printf("E %06X\n",start_loc);
		fclose(fptr);
    }
    else
    {
        printf("file not found\n");
    }

	//system("pause");
	return 0;	
}
示例#10
0
文件: telepen.c 项目: 383530895/zint
int telepen_num(struct zint_symbol *symbol, uint8_t source[], int src_len)
{
	unsigned int i, count, check_digit, glyph;
	int error_number, temp_length = src_len;
	char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
	uint8_t temp[64];

	error_number = 0;
	count = 0;

	if(temp_length > 60) {
		strcpy(symbol->errtxt, "Input too long");
		return ZERROR_TOO_LONG;
	}
	ustrcpy(temp, source);
	to_upper(temp);
	error_number = is_sane(NEON, temp, temp_length);
	if(error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}

	/* Add a leading zero if required */
	if (temp_length & 1)
	{
		memmove(temp + 1, temp, temp_length);
		temp[0] = '0';

		temp[++temp_length] = '\0';
	}

	/* Start character */
	strcpy(dest, TeleTable['_']);

	for (i = 0; i < temp_length; i += 2)
	{
		if(temp[i] == 'X') {
			strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
			return ZERROR_INVALID_DATA;
		}

		if(temp[i + 1] == 'X') {
			glyph = ctoi(temp[i]) + 17;
			count += glyph;
		} else {
			glyph = (10 * ctoi(temp[i])) + ctoi(temp[i + 1]);
			glyph += 27;
			count += glyph;
		}
		concat(dest, TeleTable[glyph]);
	}

	check_digit = 127 - (count % 127);
	if(check_digit == 127) { check_digit = 0; }
	concat(dest, TeleTable[check_digit]);

	/* Stop character */
	concat(dest, TeleTable['z']);

	expand(symbol, dest);
	ustrcpy(symbol->text, temp);
	return error_number;
}
void boardLoop()
{
    Board b;
    char inputOption;
    Coord source, dest;
    fillBoard(b);
    do {
        do {
            printGameScreen(b);
            inputOption = readValidOption("Ingrese la fila de origen", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            source.row = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la columna de origen", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            source.col = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la fila de destino", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            dest.row = ctoi(inputOption);

            printGameScreen(b);
            inputOption = readValidOption("Ingrese la columna de destino", VALID_OPTIONS);
            if (isProgramOption(inputOption, VALID_PROGRAM_OPTIONS)) {
                break;
            }
            dest.col = ctoi(inputOption);
        } while (0);

        switch (inputOption) {
            case 'q':
            case 'Q':
                if (readConfirmOption("¿Esta usted seguro?")) {
                    printf("Adios\n");
                } else {
                    inputOption = OPTION_NOTHING;
                }
                break;
            case 'h':
            case 'H':
                clearScreen();
                printInstruction();
                pauseMessage(NULL);
                break;
            case 'r':
            case 'R':
                fillBoard(b);
                break;
            case 'w':
            case 'W':
                printf("Win game step\n");
                break;
        }
    } while ('q' != inputOption);
}
示例#12
0
void GzRasterize(GzRender *render,GzCoord *triVertex)
{		

	//AfxMessageBox("Rasterize");				
		
		float x1 = triVertex[0][0];
		float x2 = triVertex[1][0];
		float x3 = triVertex[2][0];
		float y1 = triVertex[0][1];
		float y2 = triVertex[1][1];
		float y3 = triVertex[2][1];
		float z1 = triVertex[0][2];
		float z2 = triVertex[1][2];
		float z3 = triVertex[2][2];
		
		float xMin,yMin,xMax,yMax;
		float a1,b1,c1,a2,b2,c2,a3,b3,c3;
		float aX,bY,cZ,d;
		int xStart,yStart,xEnd,yEnd;
		
		/*	xMin, xMax, yMin, yMax are calculated for fixing the bounding box triangle	*/
		xMin = min(x1,min(x2,x3));
		xMax = max(x1,max(x2,x3));

		yMin = min(y1,min(y2,y3));
		yMax = max(y1,max(y2,y3));

		/*	Computing Line Equation coefficients */
		
		// First Edge (x1,y1) -> (x2,y2)
		a1 = y1 - y2;
		b1 = x2 - x1;
		c1 = ((x1 - x2) * y2) - ((y1 - y2) * x2);

		//Second Edge (x2,y2) -> (x3,y3)
		a2 = y2 - y3;
		b2 = x3 - x2;
		c2 = ((x2 - x3) * y3) - ((y2 - y3) * x3);

		//Third Edge (x3,y3) -> (x1,y1)
		a3 = y3 - y1;
		b3 = x1 - x3;
		c3 = ((x3 - x1) * y1) - ((y3 - y1) * x1);

		/*	Finding Crossproduct of 2 edges to obtain the plane equation for the triangle	*/
	
		aX = (((y1 - y2) * (z2 - z3)) - ((z1 - z2) * (y2 - y3)));
		bY = -(((x1 - x2) * (z2 - z3)) - ((z1 - z2) * (x2 - x3)));
		cZ = (((x1 - x2) * (y2 - y3)) - ((y1 - y2) * (x2 - x3)));
		d = -(aX * x1 + bY * y1 + cZ * z1);
				
		xStart = max(int(ceil((xMin))),0);
		yStart = max(int(ceil((yMin))),0);
	
		xEnd = min(int(floor((xMax))),render->display->xres);
		yEnd = min(int(floor((yMax))),render->display->yres);
				
		if(WIREFRAME)
		{
			line(x1,y1,x2,y2,render);
			line(x2,y2,x3,y3,render);
			line(x3,y3,x1,y1,render);
		}
		else{
		for(int y  = yStart; y <= yEnd; y++)
		{
			for(int x = xStart; x <= xEnd; x++)
			{				
				//check if x,y lies outside the line. If yes, skip triangle and move to next
				if (a1 * x + b1 * y + c1 < 0)
				{
						continue;
				}
				if(a2 * x + b2 * y + c2 < 0)
				{
						continue;
				}
				if(a3 * x + b3 * y + c3 < 0)
				{
						continue; 
				}													
					GzDepth newZ = (GzDepth)(-(aX * x + bY * y + d) / cZ);

					if(newZ > 0)
					{
						GzIntensity red,green,blue,alpha;
						GzDepth oldZ;				
					
						GzGetDisplay(render->display,x,y,&red,&green,&blue,&alpha,&oldZ);
				
						if(newZ < oldZ)
						{					
							GzPutDisplay(render->display,x,y,ctoi(render->flatcolor[0]),ctoi(render->flatcolor[1]),ctoi(render->flatcolor[2]),alpha,newZ);							
						}	
					}			
				}												
			
		}
		}
	}
示例#13
0
int setfont_main(int argc UNUSED_PARAM, char **argv)
{
	size_t len;
	unsigned opts;
	int fd;
	unsigned char *buffer;
	char *mapfilename;
	const char *tty_name = CURRENT_TTY;

	opt_complementary = "=1";
	opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
	argv += optind;

	fd = xopen_nonblocking(tty_name);

	if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
		if (*argv[0] != '/') {
			// goto default fonts location. don't die if doesn't exist
			chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
		}
	}
	// load font
	len = 32*1024; // can't be larger
	buffer = xmalloc_open_zipped_read_close(*argv, &len);
	if (!buffer)
		bb_simple_perror_msg_and_die(*argv);
	do_load(fd, buffer, len);

	// load the screen map, if any
	if (opts & 1) { // -m
		unsigned mode = PIO_SCRNMAP;
		void *map;

		if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
			if (mapfilename[0] != '/') {
				// goto default keymaps location
				chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
			}
		}
		// fetch keymap
		map = xmalloc_open_zipped_read_close(mapfilename, &len);
		if (!map)
			bb_simple_perror_msg_and_die(mapfilename);
		// file size is 256 or 512 bytes? -> assume binary map
		if (len == E_TABSZ || len == 2*E_TABSZ) {
			if (len == 2*E_TABSZ)
				mode = PIO_UNISCRNMAP;
		}
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
		// assume textual Unicode console maps:
		// 0x00 U+0000  #  NULL (NUL)
		// 0x01 U+0001  #  START OF HEADING (SOH)
		// 0x02 U+0002  #  START OF TEXT (STX)
		// 0x03 U+0003  #  END OF TEXT (ETX)
		else {
			int i;
			char *token[2];
			parser_t *parser;

			if (ENABLE_FEATURE_CLEAN_UP)
				free(map);
			map = xmalloc(E_TABSZ * sizeof(unsigned short));

#define unicodes ((unsigned short *)map)
			// fill vanilla map
			for (i = 0; i < E_TABSZ; i++)
				unicodes[i] = 0xf000 + i;

			parser = config_open(mapfilename);
			while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
				// parse code/value pair
				int a = ctoi(token[0]);
				int b = ctoi(token[1]);
				if (a < 0 || a >= E_TABSZ
				 || b < 0 || b > 65535
				) {
					bb_error_msg_and_die("map format");
				}
				// patch map
				unicodes[a] = b;
				// unicode character is met?
				if (b > 255)
					mode = PIO_UNISCRNMAP;
			}
			if (ENABLE_FEATURE_CLEAN_UP)
				config_close(parser);

			if (mode != PIO_UNISCRNMAP) {
#define asciis ((unsigned char *)map)
				for (i = 0; i < E_TABSZ; i++)
					asciis[i] = unicodes[i];
#undef asciis
			}
#undef unicodes
		}
#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP

		// do set screen map
		xioctl(fd, mode, map);

		if (ENABLE_FEATURE_CLEAN_UP)
			free(map);
	}

	return EXIT_SUCCESS;
}
int Gz_LEE_Rasterization(GzRender *render, GzCoord vertex[3])
{
	GzIntensity Red, Green, Blue, alpha;

	//bubble sort

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (vertex[j][Y] > vertex[j + 1][Y])
			{
				Gz_Swap_Vertex(vertex[j], vertex[j + 1]);
			}
		}
	}
	//I think there is no need to do clockwise, because I can use +/- common area 
	//Gz_Make_CW(vertex[0], vertex[1], vertex[2]);

	//After the CW, vectors and a rectangle enclousing the triangle in 2D map

	GzCoord Vector_1_to_2;
	GzCoord Vector_2_to_3;
	GzCoord Vector_3_to_1;

	Vector_1_to_2[X] = vertex[1][X] - vertex[0][X];
	Vector_1_to_2[Y] = vertex[1][Y] - vertex[0][Y];
	Vector_1_to_2[Z] = vertex[1][Z] - vertex[0][Z];

	Vector_2_to_3[X] = vertex[2][X] - vertex[1][X];
	Vector_2_to_3[Y] = vertex[2][Y] - vertex[1][Y];
	Vector_2_to_3[Z] = vertex[2][Z] - vertex[1][Z];

	Vector_3_to_1[X] = vertex[0][X] - vertex[2][X];
	Vector_3_to_1[Y] = vertex[0][Y] - vertex[2][Y];
	Vector_3_to_1[Z] = vertex[0][Z] - vertex[2][Z];
	//We use + area in this 3 vectors!
	//Because the coords may not be integer! But pixels are at integers! X grows right, Y grows down.
	int Xmin = floor(Find_x_min(vertex));
	int Xmax = ceil(Find_x_max(vertex));

	int Ymin = floor(vertex[0][Y]);
	int Ymax = ceil(vertex[2][Y]);

	//Calculate the Ax+By+Cz+D=0 A B C D use vectors

	float A;
	float B;
	float C;
	float D;

	A = Vector_1_to_2[Y] * (-Vector_3_to_1[Z]) - (-Vector_3_to_1[Y]) * Vector_1_to_2[Z];
	B = Vector_1_to_2[Z] * (-Vector_3_to_1[X]) - (-Vector_3_to_1[Z]) * Vector_1_to_2[X];
	C = Vector_1_to_2[X] * (-Vector_3_to_1[Y]) - (-Vector_3_to_1[X]) * Vector_1_to_2[Y];
	D = -(A * vertex[0][X] + B * vertex[0][Y] + C * vertex[0][Z]);

	//Scan the pixels and draw!
	float Pixel_z;
	for (int i = Xmin; i <= Xmax; i++)
	{
		if (i < 0 || i > render->display->xres)
			continue;
		for (int j = Ymin; j <= Ymax; j++)
		{
			if (j < 0 || j > render->display->yres)
				continue;

			Pixel_z = -(A * i + B * j + D) / C;
			GzDepth tempz = 0;  //get z from getdisplay
			/*
			Put point into the line fuctions: E1(x,y) E2(x,y) E3(x,y) the relationship with vectors in 2D map
			*/
			float Relationship_with_1_to_2 = Vector_1_to_2[Y] * (i - vertex[0][X]) - Vector_1_to_2[X] * (j - vertex[0][Y]);
			float Relationship_with_2_to_3 = Vector_2_to_3[Y] * (i - vertex[1][X]) - Vector_2_to_3[X] * (j - vertex[1][Y]);
			float Relationship_with_3_to_1 = Vector_3_to_1[Y] * (i - vertex[2][X]) - Vector_3_to_1[X] * (j - vertex[2][Y]);

			if (Relationship_with_1_to_2 == 0 || Relationship_with_2_to_3 == 0 || Relationship_with_3_to_1 == 0)
			{
				//one the line!
				GzGetDisplay(render->display, i, j, &Red, &Green, &Blue, &alpha, &tempz);
				if (Pixel_z < tempz)
				{
					Red = ctoi(render->flatcolor[0]);
					Green = ctoi(render->flatcolor[1]);
					Blue = ctoi(render->flatcolor[2]);
					GzPutDisplay(render->display, i, j, Red, Green, Blue, alpha, Pixel_z);
				}
			}
			else if ((Relationship_with_1_to_2 > 0 && Relationship_with_2_to_3 > 0 && Relationship_with_3_to_1 > 0) || (Relationship_with_1_to_2 < 0 && Relationship_with_2_to_3 < 0 && Relationship_with_3_to_1 < 0))
			{

				GzGetDisplay(render->display, i, j, &Red, &Green, &Blue, &alpha, &tempz);

				if (Pixel_z < tempz)
				{
					Red = ctoi(render->flatcolor[0]);
					Green = ctoi(render->flatcolor[1]);
					Blue = ctoi(render->flatcolor[2]);
					GzPutDisplay(render->display, i, j, Red, Green, Blue, alpha, Pixel_z);
				}
			}
		}
	}
	return GZ_SUCCESS;
}
示例#15
0
文件: ps.c 项目: haffmans/zint
int ps_plot(struct zint_symbol *symbol)
{
	int i, block_width, latch, r, this_row;
	float textpos, large_bar_height, preset_height, row_height, row_posn;
	FILE *feps;
	int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
	float red_ink, green_ink, blue_ink, red_paper, green_paper, blue_paper;
	int error_number = 0;
	int textoffset, xoffset, yoffset, textdone, main_width;
	char textpart[10], addon[6];
	int large_bar_count, comp_offset;
	float addon_text_posn;
	float scaler = symbol->scale;
	float default_text_posn;
	int plot_text = 1;
	const char *locale = NULL;

	row_height=0;
	textdone = 0;
	main_width = symbol->width;
	strcpy(addon, "");
	comp_offset = 0;
	addon_text_posn = 0.0;

	if((symbol->output_options & BARCODE_STDOUT) != 0) {
		feps = stdout;
	} else {
		feps = fopen(symbol->outfile, "w");
	}
	if(feps == NULL) {
		strcpy(symbol->errtxt, "Could not open output file");
		return ZERROR_FILE_ACCESS;
	}

	/* sort out colour options */
	to_upper((unsigned char*)symbol->fgcolour);
	to_upper((unsigned char*)symbol->bgcolour);

	if(strlen(symbol->fgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	if(strlen(symbol->bgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}
	error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
	if (error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
	if (error_number == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}
	locale = setlocale(LC_ALL, "C");

	fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
	fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
	fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
	bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
	bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
	bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
	red_ink = fgred / 256.0;
	green_ink = fggrn / 256.0;
	blue_ink = fgblu / 256.0;
	red_paper = bgred / 256.0;
	green_paper = bggrn / 256.0;
	blue_paper = bgblu / 256.0;

	if (symbol->height == 0) {
		symbol->height = 50;
	}

	large_bar_count = 0;
	preset_height = 0.0;
	for(i = 0; i < symbol->rows; i++) {
		preset_height += symbol->row_height[i];
		if(symbol->row_height[i] == 0) {
			large_bar_count++;
		}
	}
	large_bar_height = (symbol->height - preset_height) / large_bar_count;

	if (large_bar_count == 0) {
		symbol->height = preset_height;
	}

	while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) {
		comp_offset++;
	}

	/* Certain symbols need whitespace otherwise characters get chopped off the sides */
	if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC))
		|| (symbol->symbology == BARCODE_ISBNX)) {
		switch(ustrlen(symbol->text)) {
			case 13: /* EAN 13 */
			case 16:
			case 19:
				if(symbol->whitespace_width == 0) {
					symbol->whitespace_width = 10;
				}
				main_width = 96 + comp_offset;
				break;
			default:
				main_width = 68 + comp_offset;
		}
	}

	if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
		if(symbol->whitespace_width == 0) {
			symbol->whitespace_width = 10;
			main_width = 96 + comp_offset;
		}
	}

	if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
		if(symbol->whitespace_width == 0) {
			symbol->whitespace_width = 10;
			main_width = 51 + comp_offset;
		}
	}

	latch = 0;
	r = 0;
	/* Isolate add-on text */
	if(is_extendable(symbol->symbology)) {
		for(i = 0; i < ustrlen(symbol->text); i++) {
			if (latch == 1) {
				addon[r] = symbol->text[i];
				r++;
			}
			if (symbol->text[i] == '+') {
				latch = 1;
			}
		}
	}
	addon[r] = '\0';

	if((symbol->show_hrt == 0) || (ustrlen(symbol->text) == 0)) {
		plot_text = 0;
	}
	if(plot_text) {
		textoffset = 9;
	} else {
		textoffset = 0;
	}
	xoffset = symbol->border_width + symbol->whitespace_width;
	yoffset = symbol->border_width;

	/* Start writing the header */
	fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
	fprintf(feps, "%%%%Creator: Zint %s\n", ZINT_VERSION);
	if(ustrlen(symbol->text) != 0) {
		fprintf(feps, "%%%%Title: %s\n",symbol->text);
	} else {
		fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
	}
	fprintf(feps, "%%%%Pages: 0\n");
	if(symbol->symbology != BARCODE_MAXICODE) {
		fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((symbol->width + xoffset + xoffset) * scaler), roundup((symbol->height + textoffset + yoffset + yoffset) * scaler));
	} else {
		fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", roundup((74.0 + xoffset + xoffset) * scaler), roundup((72.0 + yoffset + yoffset) * scaler));
	}
	fprintf(feps, "%%%%EndComments\n");

	/* Definitions */
	fprintf(feps, "/TL { setlinewidth moveto lineto stroke } bind def\n");
	fprintf(feps, "/TC { moveto 0 360 arc 360 0 arcn fill } bind def\n");
	fprintf(feps, "/TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def\n");
	fprintf(feps, "/TB { 2 copy } bind def\n");
	fprintf(feps, "/TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def\n");
	fprintf(feps, "/TE { pop pop } bind def\n");

	fprintf(feps, "newpath\n");

	/* Now the actual representation */
	fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
	fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
	fprintf(feps, "%.2f 0.00 TB 0.00 %.2f TR\n", (symbol->height + textoffset + yoffset + yoffset) * scaler, (symbol->width + xoffset + xoffset) * scaler);

	if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
		default_text_posn = 0.5 * scaler;
	} else {
		default_text_posn = (symbol->border_width + 0.5) * scaler;
	}

	if(symbol->symbology == BARCODE_MAXICODE) {
		/* Maxicode uses hexagons */
		float ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy, mx, my;


		textoffset = 0.0;
		if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
			fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + 72.0 + symbol->border_width) * scaler, 0.0, (74.0 + xoffset + xoffset) * scaler);
		}
		if((symbol->output_options & BARCODE_BOX) != 0) {
			/* side bars */
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
			fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (72.0 + (2 * symbol->border_width)) * scaler, textoffset * scaler, (74.0 + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
		}

		fprintf(feps, "TE\n");
		fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
		fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
		fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 10.85 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 8.97 * scaler, (44.73 + xoffset) * scaler, (35.60 + yoffset) * scaler);
		fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 7.10 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 5.22 * scaler, (40.98 + xoffset) * scaler, (35.60 + yoffset) * scaler);
		fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TC\n", (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 3.31 * scaler, (35.76 + xoffset) * scaler, (35.60 + yoffset) * scaler, 1.43 * scaler, (37.19 + xoffset) * scaler, (35.60 + yoffset) * scaler);
		for(r = 0; r < symbol->rows; r++) {
			for(i = 0; i < symbol->width; i++) {
				if(module_is_set(symbol, r, i)) {
					/* Dump a hexagon */
					my = ((symbol->rows - r - 1)) * 2.135 + 1.43;
					ay = my + 1.0 + yoffset;
					by = my + 0.5 + yoffset;
					cy = my - 0.5 + yoffset;
					dy = my - 1.0 + yoffset;
					ey = my - 0.5 + yoffset;
					fy = my + 0.5 + yoffset;

					mx = 2.46 * i + 1.23 + (r & 1 ? 1.23 : 0);

					ax = mx + xoffset;
					bx = mx + 0.86 + xoffset;
					cx = mx + 0.86 + xoffset;
					dx = mx + xoffset;
					ex = mx - 0.86 + xoffset;
					fx = mx - 0.86 + xoffset;
					fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n", ax * scaler, ay * scaler, bx * scaler, by * scaler, cx * scaler, cy * scaler, dx * scaler, dy * scaler, ex * scaler, ey * scaler, fx * scaler, fy * scaler);
				}
			}
		}
	}

	if(symbol->symbology != BARCODE_MAXICODE) {
		/* everything else uses rectangles (or squares) */
		/* Works from the bottom of the symbol up */
		int addon_latch = 0;

		for(r = 0; r < symbol->rows; r++) {
			this_row = symbol->rows - r - 1; /* invert r otherwise plots upside down */
			if(symbol->row_height[this_row] == 0) {
				row_height = large_bar_height;
			} else {
				row_height = symbol->row_height[this_row];
			}
			row_posn = 0;
			for(i = 0; i < r; i++) {
				if(symbol->row_height[symbol->rows - i - 1] == 0) {
					row_posn += large_bar_height;
				} else {
					row_posn += symbol->row_height[symbol->rows - i - 1];
				}
			}
			row_posn += (textoffset + yoffset);

			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler);
			i = 0;
			if(module_is_set(symbol, this_row, 0)) {
				latch = 1;
			} else {
				latch = 0;
			}

			do {
				block_width = 0;
				do {
					block_width++;
				} while (module_is_set(symbol, this_row, i + block_width) == module_is_set(symbol, this_row, i));
				if((addon_latch == 0) && (r == 0) && (i > main_width)) {
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					fprintf(feps, "%.2f %.2f ", (row_height - 5.0) * scaler, (row_posn - 5.0) * scaler);
					addon_text_posn = row_posn + row_height - 8.0;
					addon_latch = 1;
				}
				if(latch == 1) {
					/* a bar */
					fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset) * scaler, block_width * scaler);
					latch = 0;
				} else {
					/* a space */
					latch = 1;
				}
				i += block_width;

			} while (i < symbol->width);
		}
	}
	/* That's done the actual data area, everything else is human-friendly */

	xoffset += comp_offset;

	if (plot_text) {
		if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) ||
			(symbol->symbology == BARCODE_ISBNX)) {
			/* guard bar extensions and text formatting for EAN8 and EAN13 */
			switch(ustrlen(symbol->text)) {
				case 8: /* EAN-8 */
				case 11:
				case 14:
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (0 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (2 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (32 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (34 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (64 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (66 + xoffset) * scaler, 1 * scaler);
					for(i = 0; i < 4; i++) {
						textpart[i] = symbol->text[i];
					}
					textpart[4] = '\0';
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = 17;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
					fprintf(feps, " (%s) stringwidth\n", textpart);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", textpart);
					fprintf(feps, "setmatrix\n");
					for(i = 0; i < 4; i++) {
						textpart[i] = symbol->text[i + 4];
					}
					textpart[4] = '\0';
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = 50;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
					fprintf(feps, " (%s) stringwidth\n", textpart);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", textpart);
					fprintf(feps, "setmatrix\n");
					textdone = 1;
					switch(strlen(addon)) {
						case 2:
							fprintf(feps, "matrix currentmatrix\n");
							fprintf(feps, "/Helvetica findfont\n");
							fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
							textpos = xoffset + 86;
							fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
							fprintf(feps, " (%s) stringwidth\n", addon);
							fprintf(feps, "pop\n");
							fprintf(feps, "-2 div 0 rmoveto\n");
							fprintf(feps, " (%s) show\n", addon);
							fprintf(feps, "setmatrix\n");
							break;
						case 5:
							fprintf(feps, "matrix currentmatrix\n");
							fprintf(feps, "/Helvetica findfont\n");
							fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
							textpos = xoffset + 100;
							fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
							fprintf(feps, " (%s) stringwidth\n", addon);
							fprintf(feps, "pop\n");
							fprintf(feps, "-2 div 0 rmoveto\n");
							fprintf(feps, " (%s) show\n", addon);
							fprintf(feps, "setmatrix\n");
							break;
					}

					break;
				case 13: /* EAN 13 */
				case 16:
				case 19:
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (0 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (2 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (46 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (48 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (92 + xoffset) * scaler, 1 * scaler);
					fprintf(feps, "TB %.2f %.2f TR\n", (94 + xoffset) * scaler, 1 * scaler);
					textpart[0] = symbol->text[0];
					textpart[1] = '\0';
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = -7;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
					fprintf(feps, " (%s) stringwidth\n", textpart);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", textpart);
					fprintf(feps, "setmatrix\n");
					for(i = 0; i < 6; i++) {
						textpart[i] = symbol->text[i + 1];
					}
					textpart[6] = '\0';
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = 24;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
					fprintf(feps, " (%s) stringwidth\n", textpart);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", textpart);
					fprintf(feps, "setmatrix\n");
					for(i = 0; i < 6; i++) {
						textpart[i] = symbol->text[i + 7];
					}
					textpart[6] = '\0';
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = 71;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
					fprintf(feps, " (%s) stringwidth\n", textpart);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", textpart);
					fprintf(feps, "setmatrix\n");
					textdone = 1;
					switch(strlen(addon)) {
						case 2:
							fprintf(feps, "matrix currentmatrix\n");
							fprintf(feps, "/Helvetica findfont\n");
							fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
							textpos = xoffset + 114;
							fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
							fprintf(feps, " (%s) stringwidth\n", addon);
							fprintf(feps, "pop\n");
							fprintf(feps, "-2 div 0 rmoveto\n");
							fprintf(feps, " (%s) show\n", addon);
							fprintf(feps, "setmatrix\n");
							break;
						case 5:
							fprintf(feps, "matrix currentmatrix\n");
							fprintf(feps, "/Helvetica findfont\n");
							fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
							textpos = xoffset + 128;
							fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
							fprintf(feps, " (%s) stringwidth\n", addon);
							fprintf(feps, "pop\n");
							fprintf(feps, "-2 div 0 rmoveto\n");
							fprintf(feps, " (%s) show\n", addon);
							fprintf(feps, "setmatrix\n");
							break;
					}
					break;

			}
		}

		if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) {
			/* guard bar extensions and text formatting for UPCA */
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler);
			latch = 1;

			i = 0 + comp_offset;
			do {
				block_width = 0;
				do {
					block_width++;
				} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
				if(latch == 1) {
					/* a bar */
					fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
					latch = 0;
				} else {
					/* a space */
					latch = 1;
				}
				i += block_width;
			} while (i < 11 + comp_offset);
			fprintf(feps, "TB %.2f %.2f TR\n", (46 + xoffset) * scaler, 1 * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (48 + xoffset) * scaler, 1 * scaler);
			latch = 1;
			i = 85 + comp_offset;
			do {
				block_width = 0;
				do {
					block_width++;
				} while (module_is_set(symbol, symbol->rows - 1, i + block_width) == module_is_set(symbol, symbol->rows - 1, i));
				if(latch == 1) {
					/* a bar */
					fprintf(feps, "TB %.2f %.2f TR\n", (i + xoffset - comp_offset) * scaler, block_width * scaler);
					latch = 0;
				} else {
					/* a space */
					latch = 1;
				}
				i += block_width;
			} while (i < 96 + comp_offset);
			textpart[0] = symbol->text[0];
			textpart[1] = '\0';
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
			textpos = -5;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			for(i = 0; i < 5; i++) {
				textpart[i] = symbol->text[i + 1];
			}
			textpart[5] = '\0';
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
			textpos = 27;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			for(i = 0; i < 5; i++) {
				textpart[i] = symbol->text[i + 6];
			}
			textpart[6] = '\0';
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
			textpos = 68;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			textpart[0] = symbol->text[11];
			textpart[1] = '\0';
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
			textpos = 100;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			textdone = 1;
			switch(strlen(addon)) {
				case 2:
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = xoffset + 116;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
					fprintf(feps, " (%s) stringwidth\n", addon);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", addon);
					fprintf(feps, "setmatrix\n");
					break;
				case 5:
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = xoffset + 130;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
					fprintf(feps, " (%s) stringwidth\n", addon);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", addon);
					fprintf(feps, "setmatrix\n");
					break;
			}

		}

		if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) {
			/* guard bar extensions and text formatting for UPCE */
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "%.2f %.2f ", 5.0 * scaler, (4.0 + yoffset) * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (0 + xoffset) * scaler, 1 * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (2 + xoffset) * scaler, 1 * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (46 + xoffset) * scaler, 1 * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (48 + xoffset) * scaler, 1 * scaler);
			fprintf(feps, "TB %.2f %.2f TR\n", (50 + xoffset) * scaler, 1 * scaler);
			textpart[0] = symbol->text[0];
			textpart[1] = '\0';
			fprintf(feps, "TE\n");
			fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
			textpos = -5;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			for(i = 0; i < 6; i++) {
				textpart[i] = symbol->text[i + 1];
			}
			textpart[6] = '\0';
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
			textpos = 24;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			textpart[0] = symbol->text[7];
			textpart[1] = '\0';
			fprintf(feps, "matrix currentmatrix\n");
			fprintf(feps, "/Helvetica findfont\n");
			fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
			textpos = 55;
			fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
			fprintf(feps, " (%s) stringwidth\n", textpart);
			fprintf(feps, "pop\n");
			fprintf(feps, "-2 div 0 rmoveto\n");
			fprintf(feps, " (%s) show\n", textpart);
			fprintf(feps, "setmatrix\n");
			textdone = 1;
			switch(strlen(addon)) {
				case 2:
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = xoffset + 70;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
					fprintf(feps, " (%s) stringwidth\n", addon);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", addon);
					fprintf(feps, "setmatrix\n");
					break;
				case 5:
					fprintf(feps, "matrix currentmatrix\n");
					fprintf(feps, "/Helvetica findfont\n");
					fprintf(feps, "%.2f scalefont setfont\n", 11.0 * scaler);
					textpos = xoffset + 84;
					fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", textpos * scaler, addon_text_posn * scaler);
					fprintf(feps, " (%s) stringwidth\n", addon);
					fprintf(feps, "pop\n");
					fprintf(feps, "-2 div 0 rmoveto\n");
					fprintf(feps, " (%s) show\n", addon);
					fprintf(feps, "setmatrix\n");
					break;
			}

		}
	} /* if (plot_text) */

	xoffset -= comp_offset;

	switch(symbol->symbology) {
		case BARCODE_MAXICODE:
			/* Do nothing! (It's already been done) */
			break;
		default:
			if((symbol->output_options & BARCODE_BIND) != 0) {
				if((symbol->rows > 1) && (is_stackable(symbol->symbology) == 1)) {
					/* row binding */
					fprintf(feps, "TE\n");
					fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
					for(r = 1; r < symbol->rows; r++) {
						fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", 2.0 * scaler, ((r * row_height) + textoffset + yoffset - 1) * scaler, xoffset * scaler, symbol->width * scaler);
					}
				}
			}
			if (((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) {
				fprintf(feps, "TE\n");
				fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
				fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, textoffset * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
				fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", symbol->border_width * scaler, (textoffset + symbol->height + symbol->border_width) * scaler, 0.0, (symbol->width + xoffset + xoffset) * scaler);
			}
			if((symbol->output_options & BARCODE_BOX) != 0) {
				/* side bars */
				fprintf(feps, "TE\n");
				fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
				fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, 0.0, symbol->border_width * scaler);
				fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", (symbol->height + (2 * symbol->border_width)) * scaler, textoffset * scaler, (symbol->width + xoffset + xoffset - symbol->border_width) * scaler, symbol->border_width * scaler);
			}
			break;
	}

	/* Put the human readable text at the bottom */
	if(plot_text && (textdone == 0)) {
		fprintf(feps, "TE\n");
		fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
		fprintf(feps, "matrix currentmatrix\n");
		fprintf(feps, "/Helvetica findfont\n");
		fprintf(feps, "%.2f scalefont setfont\n", 8.0 * scaler);
		textpos = symbol->width / 2.0;
		fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", (textpos + xoffset) * scaler, default_text_posn);
		fprintf(feps, " (%s) stringwidth\n", symbol->text);
		fprintf(feps, "pop\n");
		fprintf(feps, "-2 div 0 rmoveto\n");
		fprintf(feps, " (%s) show\n", symbol->text);
		fprintf(feps, "setmatrix\n");
	}
	fprintf(feps, "\nshowpage\n");

	if(symbol->output_options & BARCODE_STDOUT) {
		fflush(feps);
    }
    else {
        fclose(feps);
    }

	if (locale)
		setlocale(LC_ALL, locale);

	return error_number;
}
示例#16
0
void scanLinePhong(GzRender *render, float x_begin, float x_end, int y, float* norm, float d, float* norm1, float* norm2, float* TexPoint1, float* TexPoint2) { // Span line method

	int index; // used to find index within triangles
	float z;

	if (!(x_begin > render->display->xres - 1 || x_end < 0)) { // checks and see if line is within the screen

		// prevents same line from being drawn twice for later triangles
		int x = ceilf(x_begin);
		if (x == x_begin)
			++x;

		float x_s = x_begin;
		float total = x_end - x_begin;

		// Clamps the value between 0 and xres
		if (x_begin < 0)
			x = 0.0;
		if (x_end > render->display->xres - 1)
			x_end = render->display->xres - 1;

		float t;
		float newNormal[3];
		float newColor[3];

		for (x; x <= x_end; ++x) { // begins spanning line
			index = (render->display->xres * y) + x;

			// interpolates z at that point
			z = -((norm[0] * (float)x) + (norm[1] * (float)y) + d) / norm[2];

			if (z < render->display->fbuf[index].z && z >= 0) { // if the object is in front of what's on fbuf

				t = (x - x_s) / total;
				for (int n = 0; n < 3; ++n)
					newNormal[n] = (norm1[n] * (1 - t) + norm2[n] * t);
				normalize(newNormal);
				colorPixel(render, newNormal, newColor); // gets color based on normal

				if (render->tex_fun == NULL) {
					render->display->fbuf[index].red = ctoi(newColor[0]);
					render->display->fbuf[index].green = ctoi(newColor[1]);
					render->display->fbuf[index].blue = ctoi(newColor[2]);
				}
				else {
					// look up kd and ka
					float newTex[2];
					for (int n = 0; n < 2; ++n) // interpolate u and v
						newTex[n] = (TexPoint1[n] * (1 - t) + TexPoint2[n] * t);

					for (int n = 0; n < 2; ++n) // revert the interpolated value back to screen space
						newTex[n] *= ((z / ((float)MAXINT - z)) + 1);

					float texColor[3];
					float newTexColor[3];
					render->tex_fun(newTex[0], newTex[1], texColor); // grab color from texture
					colorPixelTex(render, newNormal, newTexColor, render->Ks, texColor, texColor); // get color for Phong
					
					render->display->fbuf[index].red = ctoi(newTexColor[0]);
					render->display->fbuf[index].green = ctoi(newTexColor[1]);
					render->display->fbuf[index].blue = ctoi(newTexColor[2]);
				}
				render->display->fbuf[index].z = z;
			}
		}
	}
}
int GzPutTriangle(GzRender *render, int	numParts, GzToken *nameList,
                  GzPointer *valueList)
/* numParts - how many names and values */
{
    /*
    - pass in a triangle description with tokens and values corresponding to
          GZ_NULL_TOKEN:		do nothing - no values
          GZ_POSITION:		3 vert positions
    - Invoke the scan converter and return an error code
    */
    if (NULL != nameList && NULL != render && NULL != valueList)
    {

        int nLowestY = 0;

        for (int i = 0; i < numParts; i++)
        {
            if (nameList[i] == GZ_POSITION)
            {
                // get points
                GzCoord* gzPoints = (GzCoord*)valueList[i];

                // sort the vertices by Y using bubble sort technique
                for (int i = 0; i <= 1; i++)
                {
                    nLowestY = i;
                    for (int j = i + 1; j <= 2; j++)
                    {
                        if (gzPoints[nLowestY][Y] > gzPoints[j][Y])
                        {
                            nLowestY = j;
                        }
                    }

                    if (nLowestY != i)
                    {
                        SwapVertices(gzPoints, nLowestY, i);
                    }
                }

                if (gzPoints[0][Y] == gzPoints[1][Y])
                {
                    if (gzPoints[0][X] > gzPoints[1][X])
                    {
                        SwapVertices(gzPoints, 0, 1);
                    }
                }

                else if (gzPoints[1][Y] == gzPoints[2][Y])
                {
                    if (gzPoints[1][X] < gzPoints[2][X])
                    {
                        SwapVertices(gzPoints, 2, 1);
                    }
                }

                // Find two Edges of the triangle to compute the normal vector
                GzCoord Triedge12;
                Triedge12[X] = gzPoints[1][X] - gzPoints[0][X];
                Triedge12[Y] = gzPoints[1][Y] - gzPoints[0][Y];
                Triedge12[Z] = gzPoints[1][Z] - gzPoints[0][Z];

                GzCoord Triedge23;
                Triedge23[X] = gzPoints[2][X] - gzPoints[1][X];
                Triedge23[Y] = gzPoints[2][Y] - gzPoints[1][Y];
                Triedge23[Z] = gzPoints[2][Z] - gzPoints[1][Z];

                // compute the normal vector by doing the cross product of two edges
                float fOutvectorX = Triedge12[Y] * Triedge23[Z] - Triedge12[Z] * Triedge23[Y];
                float fOutvectorY = Triedge12[Z] * Triedge23[X] - Triedge12[X] * Triedge23[Z];
                float fOutvectorZ = Triedge12[X] * Triedge23[Y] - Triedge12[Y] * Triedge23[X];

                //Ax + By + Cz + D = 0   ------- [1]
                float D = -(fOutvectorX * gzPoints[0][X]) - (fOutvectorY * gzPoints[0][Y]) - (fOutvectorZ *	gzPoints[0][Z]);

                int nLeft = 0, nRight = 0;
                GetBoundingBoxWidth(nLeft, nRight, gzPoints);

                // get the T/B from the sorted Y vertices
                int nTop = (int)floor(gzPoints[0][Y]);
                int nBottom = (int)ceil(gzPoints[2][Y]);

                float interpolatedZ = 0.0f;
                // for each pixel(x,y) in the bounding box evaluate equation [1]
                for (int x = nLeft; x < nRight; x++)
                {
                    for (int y = nTop; y < nBottom; y++)
                    {
                        float Edge12 = 0.0f, Edge23 = 0.0f, Edge31 = 0.0f;

                        Edge12 = (gzPoints[1][Y] - gzPoints[0][Y])*((float)x - gzPoints[0][X]) - (gzPoints[1][X] - gzPoints[0][X])*((float)y - gzPoints[0][Y]);

                        Edge23 = (gzPoints[2][Y] - gzPoints[1][Y])*((float)x - gzPoints[1][X]) - (gzPoints[2][X] - gzPoints[1][X])*((float)y - gzPoints[1][Y]);

                        Edge31 = (gzPoints[0][Y] - gzPoints[2][Y])*((float)x - gzPoints[2][X]) - (gzPoints[0][X] - gzPoints[2][X])*((float)y - gzPoints[2][Y]);

                        if (((Edge12 > 0) && (Edge23 > 0) && (Edge31 > 0)) || ((Edge12 < 0) && (Edge23 < 0) && (Edge31 < 0))
                                || (Edge12 == 0 || Edge23 == 0 || Edge31 == 0))
                        {
                            // Z - buffer to remove hidden surfaces
                            interpolatedZ = (- (fOutvectorX * x) - (fOutvectorY * y) - D) / fOutvectorZ;
                            GzDepth zCurrentValFb = 0;
                            GzIntensity red   = 0;
                            GzIntensity green = 0;
                            GzIntensity blue  = 0;
                            GzIntensity alpha = 0;

                            // get the current values from the frambuffer
                            GzGetDisplay(render->display, x, y, &red, &green, &blue, &alpha, &zCurrentValFb);

                            // Compare between computed Zpix versus framebuffer Z value. If lesser write new pixel color, else dont do anything
                            if (interpolatedZ < zCurrentValFb)
                            {
                                zCurrentValFb = interpolatedZ;

                                red   = (GzIntensity)ctoi((float)render->flatcolor[Red]);
                                green = (GzIntensity)ctoi((float)render->flatcolor[Green]);
                                blue  = (GzIntensity)ctoi((float)render->flatcolor[Blue]);

                                //Writing new pixel value to the framebuffer
                                GzPutDisplay(render->display, x, y, red, green, blue, alpha, zCurrentValFb);
                            }
                        }
                    }
                }
            }

            if (nameList[i] == GZ_NULL_TOKEN)
            {
                //Do nothing
                continue;
            }
        }
        return GZ_SUCCESS;
    }

    else
    {
        return GZ_FAILURE;
    }

}
示例#18
0
int GzPutTriangle(GzRender	*render, int numParts, GzToken *nameList, GzPointer	*valueList)
/* numParts : how many names and values */
{
/*  
- pass in a triangle description with tokens and values corresponding to 
      GZ_POSITION:3 vert positions in model space 
- Xform positions of verts using matrix on top of stack 
- Clip - just discard any triangle with any vert(s) behind view plane 
       - optional: test for triangles with all three verts off-screen (trivial frustum cull)
- invoke triangle rasterizer  
*/ 
	if ((NULL == render) || (NULL == nameList) || (NULL == valueList))
	{
		return GZ_FAILURE;
	}
	for (int nCnt = 0; nCnt < numParts; nCnt++)
	{
		if (nameList[nCnt] == GZ_POSITION)
		{
			GzCoord* acGzCoord;
			acGzCoord = (GzCoord*)(valueList[nCnt]);
			GzMatrix topMat;
			int top = render->matlevel;
			memcpy(topMat, render->Ximage[top], sizeof(GzMatrix));
			float aCoordMat[4][4] = { { acGzCoord[0][0], acGzCoord[1][0], acGzCoord[2][0], 0 }, { acGzCoord[0][1], acGzCoord[1][1], acGzCoord[2][1], 0 }, { acGzCoord[0][2], acGzCoord[1][2], acGzCoord[2][2], 0 }, { 1, 1, 1, 0 } };
			float aCoordMatProduct[4][4];
			MatrixProduct(topMat, aCoordMat, aCoordMatProduct);
			if ((aCoordMatProduct[3][0] == 0) || (aCoordMatProduct[3][1] == 0) || (aCoordMatProduct[3][2] == 0))
			{
				continue;
			}
#if 1
			GzCoord asGzCoordX = { aCoordMatProduct[0][0] / aCoordMatProduct[3][0], aCoordMatProduct[0][1] / aCoordMatProduct[3][1], aCoordMatProduct[0][2] / aCoordMatProduct[3][2] };
			GzCoord asGzCoordY = { aCoordMatProduct[1][0] / aCoordMatProduct[3][0], aCoordMatProduct[1][1] / aCoordMatProduct[3][1], aCoordMatProduct[1][2] / aCoordMatProduct[3][2] };
			GzCoord asGzCoordZ = { aCoordMatProduct[2][0] / aCoordMatProduct[3][0], aCoordMatProduct[2][1] / aCoordMatProduct[3][1], aCoordMatProduct[2][2] / aCoordMatProduct[3][2] };
			// clipping part
			if ((asGzCoordX[X] < 0 || asGzCoordX[X] > (render->display->xres)) && (asGzCoordX[Y] < 0 || asGzCoordX[Y] > (render->display->xres)) && (asGzCoordX[Z] < 0 || asGzCoordX[Z] > (render->display->xres)))
			{
				return GZ_FAILURE;
			}

			if ((asGzCoordY[X] < 0 || asGzCoordY[X] > (render->display->yres)) && (asGzCoordY[Y] < 0 || asGzCoordY[Y] > (render->display->yres)) && (asGzCoordY[Z] < 0 || asGzCoordY[Z] > (render->display->yres)))
			{
				return GZ_FAILURE;
			}

			if (asGzCoordZ[X] < 0 && asGzCoordZ[Y] < 0 && asGzCoordZ[Z] < 0)
			{
				return GZ_FAILURE;
			}
#else 

			GzCoord asGzCoordX = { acGzCoord[0][0], acGzCoord[1][0], acGzCoord[2][0] };
			GzCoord asGzCoordY = { acGzCoord[0][1], acGzCoord[1][1], acGzCoord[2][1] };
			GzCoord asGzCoordZ = { acGzCoord[0][2], acGzCoord[1][2], acGzCoord[2][2] };
#endif
			//Sort the matrix according to Y
			for (int anSortYCnt = 1; anSortYCnt < 3; anSortYCnt++)
			{
				if (asGzCoordY[anSortYCnt - 1] > asGzCoordY[anSortYCnt])
				{
					float afSortTemmp;
					afSortTemmp = asGzCoordX[anSortYCnt - 1];
					asGzCoordX[anSortYCnt - 1] = asGzCoordX[anSortYCnt];
					asGzCoordX[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordY[anSortYCnt - 1];
					asGzCoordY[anSortYCnt - 1] = asGzCoordY[anSortYCnt];
					asGzCoordY[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordZ[anSortYCnt - 1];
					asGzCoordZ[anSortYCnt - 1] = asGzCoordZ[anSortYCnt];
					asGzCoordZ[anSortYCnt] = afSortTemmp;
				}
			}
			float afGzCoordY_Min = asGzCoordY[0];			// find min y 
			float afGzCoordY_Max = asGzCoordY[2];			// find max y
			float tmp;
			for (int anSortYCnt = 1; anSortYCnt < 3; anSortYCnt++)
			{
				if ((asGzCoordY[anSortYCnt - 1] == asGzCoordY[anSortYCnt]) && (asGzCoordX[anSortYCnt - 1] > asGzCoordX[anSortYCnt]))
				{
					float afSortTemmp;
					afSortTemmp = asGzCoordX[anSortYCnt - 1];
					asGzCoordX[anSortYCnt - 1] = asGzCoordX[anSortYCnt];
					asGzCoordX[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordY[anSortYCnt - 1];
					asGzCoordY[anSortYCnt - 1] = asGzCoordY[anSortYCnt];
					asGzCoordY[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordZ[anSortYCnt - 1];
					asGzCoordZ[anSortYCnt - 1] = asGzCoordZ[anSortYCnt];
					asGzCoordZ[anSortYCnt] = afSortTemmp;
				}
			}
			float afCoefA = asGzCoordY[2] - asGzCoordY[0];
			float afCoefB = asGzCoordX[0] - asGzCoordX[2];
			float afCoefC = -afCoefB*asGzCoordY[0] - afCoefA * asGzCoordX[0];
			float acTestX = -(afCoefB*asGzCoordY[1] + afCoefC) / afCoefA;
			if (acTestX < asGzCoordX[1])
			{
				tmp = asGzCoordY[2];
				asGzCoordY[2] = asGzCoordY[1];
				asGzCoordY[1] = tmp;
				tmp = asGzCoordX[2];
				asGzCoordX[2] = asGzCoordX[1];
				asGzCoordX[1] = tmp;
				tmp = asGzCoordZ[2];
				asGzCoordZ[2] = asGzCoordZ[1];
				asGzCoordZ[1] = tmp;
			}
			//find the max and min for X and Y
			float afMaxX, afMinX, afMaxY, afMinY;
			afMaxX = asGzCoordX[0];
			afMinX = asGzCoordX[0];
			afMaxY = asGzCoordY[0];
			afMinY = asGzCoordY[0];
			for (int anCntMinMaxCnt = 1; anCntMinMaxCnt < 3; anCntMinMaxCnt++)
			{
				if (afMaxX <= asGzCoordX[anCntMinMaxCnt])
				{
					afMaxX = asGzCoordX[anCntMinMaxCnt];
				}
				if (afMinX >= asGzCoordX[anCntMinMaxCnt])
				{
					afMinX = asGzCoordX[anCntMinMaxCnt];
				}
				if (afMaxY <= asGzCoordY[anCntMinMaxCnt])
				{
					afMaxY = asGzCoordY[anCntMinMaxCnt];
				}
				if (afMinY >= asGzCoordY[anCntMinMaxCnt])
				{
					afMinY = asGzCoordY[anCntMinMaxCnt];
				}
			}
			//set the boundary of x and y
			if (afMinX < 0)
			{
				afMinX = 0;
			}
			else if (afMinX > 255)
			{
				afMinX = 255;
			}
			if (afMaxX < 0){
				afMaxX = 0;
			}
			else if (afMaxX > 255)
			{
				afMaxX = 255;
			}
			if (afMinY < 0){
				afMinY = 0;
			}
			else if (afMinY > 255)
			{
				afMinY = 255;
			}
			if (afMaxY < 0){
				afMaxY = 0;
			}
			else if (afMaxY > 255)
			{
				afMaxY = 255;
			}
			//set the variants of vertex Ax + By + C = 0
			float afCoefA1, afCoefA2, afCoefA3, afCoefB1, afCoefB2, afCoefB3, afCoefC1, afCoefC2, afCoefC3;
			float AfDiff1, AfDiff2, AfDiff3;
			float afVar1, afVar2, afVar3, afVar4;
			GzIntensity asR, asG, asB, asAlpha;
			GzDepth anZ;
			int anInterZ;
			afCoefA1 = asGzCoordY[1] - asGzCoordY[0];
			afCoefA2 = asGzCoordY[2] - asGzCoordY[1];
			afCoefA3 = asGzCoordY[0] - asGzCoordY[2];
			afCoefB1 = -(asGzCoordX[1] - asGzCoordX[0]);
			afCoefB2 = -(asGzCoordX[2] - asGzCoordX[1]);
			afCoefB3 = -(asGzCoordX[0] - asGzCoordX[2]);
			afCoefC1 = ((-(afCoefB1)*asGzCoordY[1]) - (afCoefA1 * asGzCoordX[1]));
			afCoefC2 = ((-(afCoefB2)*asGzCoordY[2]) - (afCoefA2 * asGzCoordX[2]));
			afCoefC3 = ((-(afCoefB3)*asGzCoordY[0]) - (afCoefA3 * asGzCoordX[0]));
			afVar1 = (((asGzCoordY[1] - asGzCoordY[0])*(asGzCoordZ[2] - asGzCoordZ[0])) - ((asGzCoordY[2] - asGzCoordY[0])*(asGzCoordZ[1] - asGzCoordZ[0])));
			afVar2 = (((asGzCoordX[2] - asGzCoordX[0])*(asGzCoordZ[1] - asGzCoordZ[0])) - ((asGzCoordX[1] - asGzCoordX[0])*(asGzCoordZ[2] - asGzCoordZ[0])));
			afVar3 = (((asGzCoordX[1] - asGzCoordX[0])*(asGzCoordY[2] - asGzCoordY[0])) - ((asGzCoordX[2] - asGzCoordX[0])*(asGzCoordY[1] - asGzCoordY[0])));
			afVar4 = -((asGzCoordY[0] * (afVar2)) + (asGzCoordX[0] * (afVar1)) + (asGzCoordZ[0] * (afVar3)));
			for (int anCntRangeX = int(afMinX); (float)anCntRangeX < (afMaxX); anCntRangeX++){
				for (int anCntRangeY = int(afMinY); (float)anCntRangeY < (afMaxY); anCntRangeY++){
					AfDiff1 = (afCoefA1*anCntRangeX) + (afCoefB1*anCntRangeY) + afCoefC1;
					AfDiff2 = (afCoefA2*anCntRangeX) + (afCoefB2*anCntRangeY) + afCoefC2;
					AfDiff3 = (afCoefA3*anCntRangeX) + (afCoefB3*anCntRangeY) + afCoefC3;
					anInterZ = -(afVar1*anCntRangeX + afVar2*anCntRangeY + afVar4) / afVar3;
					if (!(AfDiff1 < 0 || AfDiff2 < 0 || AfDiff3 < 0)){
						asR = 0;
						asG = 0;
						asB = 0;
						asAlpha = 0;
						anZ = 0;
						if (GZ_FAILURE == GzGetDisplay(render->display, anCntRangeX, anCntRangeY, &asR, &asG, &asB, &asAlpha, &anZ))
						{
							return GZ_FAILURE;
						}
						if (anZ == 0 || anInterZ < anZ)
						{
							if (GZ_FAILURE == GzPutDisplay(render->display, anCntRangeX, anCntRangeY, ctoi(render->flatcolor[RED]), ctoi(render->flatcolor[GREEN]), ctoi(render->flatcolor[BLUE]), asAlpha, anInterZ))
							{
								return GZ_FAILURE;
							}
						}
					}
				}
			}
		}
		else if (nameList[nCnt] == GZ_NULL_TOKEN)
		{
			continue;
		}
	}
	return GZ_SUCCESS;
}
示例#19
0
文件: upcean.c 项目: Jinxiaohai/QT
void add_on(unsigned char source[], char dest[], int mode)
{ /* EAN-2 and EAN-5 add-on codes */
	char parity[6];
	unsigned int i, code_type;

	/* If an add-on then append with space */
	if (mode != 0)
	{
		concat(dest, "9");
	}

	/* Start character */
	concat (dest, "112");

	/* Determine EAN2 or EAN5 add-on */
	if(ustrlen(source) == 2)
	{
		code_type = EAN2;
	}
	else
	{
		code_type = EAN5;
	}

	/* Calculate parity for EAN2 */
	if(code_type == EAN2)
	{
		int code_value, parity_bit;

		code_value = (10 * ctoi(source[0])) + ctoi(source[1]);
		parity_bit = code_value%4;
		strcpy(parity, EAN2Parity[parity_bit]);
	}

	if(code_type == EAN5)
	{
		int values[6], parity_sum, parity_bit;

		for(i = 0; i < 6; i++)
		{
			values[i] = ctoi(source[i]);
		}

		parity_sum = (3 * (values[0] + values[2] + values[4]));
		parity_sum += (9 * (values[1] + values[3]));

		parity_bit = parity_sum%10;
		strcpy(parity, EAN5Parity[parity_bit]);
	}

	for(i = 0; i < ustrlen(source); i++)
	{
		switch(parity[i]) {
			case 'A': lookup(NEON, EANsetA, source[i], dest); break;
			case 'B': lookup(NEON, EANsetB, source[i], dest); break;
		}

		/* Glyph separator */
		if(i != (ustrlen(source) - 1))
		{
			concat (dest, "11");
		}
	}
}
示例#20
0
//------------------------------------------------------------------------------
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, GzPointer *valueList) {
    /* numParts : how many names and values */

    // Do some sanity checking    
    if(NULL == render || NULL == nameList || NULL == valueList || numParts != 3)
    {
        return GZ_FAILURE;
    } 
    
        
    Matrix *Xsm = render->xStack.leftMulMatricesOnStack();
    if (Xsm == NULL)
    {
        fprintf(stderr, "Got NULL from stack in GzPutTriangle.\n");
    } 
    
    
    
    
    GzCoord *c_old;
    GzCoord *n;
    GzColor triEdgeColors[3];
    GzTextureIndex *triTextures;
    
    for (int i = 0; i < numParts; i++)
    {
        int name = nameList[i];
        switch(name)
        {
            case GZ_POSITION:
            {
                // Get ready to read coordinates
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                c_old = static_cast<GzCoord *> (l2[i]);
                
                break;
            }
            
            case GZ_NORMAL:
            {
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                
                n = static_cast<GzCoord *> (l2[i]);
                
                
                if (render->interp_mode == GZ_COLOR) 
                {
                    for (int k = 0; k < 3; k++)
                        calc_color(render, n[k], triEdgeColors[k], (render->tex_fun == false));

                }

                break;
            }
            
            case GZ_TEXTURE_INDEX:
            {
                void *l1 = valueList;
                GzTextureIndex **l2 = static_cast<GzTextureIndex**> (l1);
                triTextures = l2[i];             
                
                break;
            }
            
            default:
                return GZ_FAILURE;            
        }// end of switch statement
    }//end of for loop
    
    
    
   

    GzCoord c[3];
    // Transform triangle coordinates into screen coordinates
    for(int i = 0; i < 3 ; i++)
    {
        float array[4] = {c_old[i][0], c_old[i][1], c_old[i][2], 1};
        float rMulResult[4] ={0, 0, 0, 0};
        Xsm->rightMultiply(array, 4, rMulResult);
        c[i][X] = rMulResult[0] + render->aa_delta_x;
        c[i][Y] = rMulResult[1] + render->aa_delta_y;
        c[i][Z] = rMulResult[2];           
    }

    // Lets see if all 3 triangle coordinates are viewable or not.
    if(isBehindViewPlane(render, c) || isClipped(render, c))
        return GZ_FAILURE;   

    // Find bounding box
    int x_min = floor(findMin(c, 0, 3));
    int x_max = ceil (findMax(c, 0, 3));
    int y_min = floor(findMin(c, 1, 3));
    int y_max = ceil (findMax(c, 1, 3));


    // Iterate over every pixel in the bounding box
    for(int j = y_min; j <= y_max; j++)        
        for(int i = x_min; i <= x_max; i++)
        {
            // Calculate Barycentric coordinates
            GzCoord p = {float(i), float(j), 0};
            float alpha = f(c[1], c[2], p) / f(c[1], c[2], c[0]);
            float beta  = f(c[2], c[0], p) / f(c[2], c[0], c[1]);
            float gamma = f(c[0], c[1], p) / f(c[0], c[1], c[2]);

            // Litmus Test: Is pixel (i,j) inside triangle?
            if ( alpha > 0 && beta > 0 && gamma > 0)                
            {
                //interpolate z value
                float newZ = alpha*(c[0][2]) + beta*(c[1][2]) + gamma*(c[2][2]);


                // Get current Z value for this specific pixel (i,j)
                GzIntensity dummy;
                GzDepth oldZ;
                GzGetDisplay(render->display, i, j, &dummy, &dummy, &dummy, &dummy, &oldZ);


                // Check will this pixel be displayed or not
                if(newZ < oldZ)
                {

                    GzColor interpColor = {0, 0, 0};                    
                    GzColor color = {1.0f, 1.0f, 1.0f}; // color coming from texture
                    if(render->tex_fun != false)
                        calcTexture(render, triTextures, c, newZ, alpha, beta, gamma, color);


                    
                    
                    
                    if(render->interp_mode == GZ_NORMALS) // Phong Shading
                    {
                        GzCoord interpN = {0,0,0};
                        for (int k = 0; k < 3; k++)
                            interpN[k] = alpha*n[0][k] + beta*n[1][k] + gamma*n[2][k];
                        
                        if(render->tex_fun != false)
                        {
                                memcpy(render->Ka, color, sizeof (GzColor));
                                memcpy(render->Kd, color, sizeof (GzColor));
                        }
                
                        

                          
                        calc_color(render, interpN, interpColor, true);
                        
                        GzPutDisplay(render->display, i, j, ctoi(interpColor[X]), ctoi(interpColor[Y]), ctoi(interpColor[Z]), 1, newZ);
                        
                    }
                    else if(render->interp_mode == GZ_COLOR) // Gouraud Shading
                    {
                        float r = alpha * triEdgeColors[0][X] + beta * triEdgeColors[1][X] + gamma * triEdgeColors[2][X];
                        float g = alpha * triEdgeColors[0][Y] + beta * triEdgeColors[1][Y] + gamma * triEdgeColors[2][Y];
                        float b = alpha * triEdgeColors[0][Z] + beta * triEdgeColors[1][Z] + gamma * triEdgeColors[2][Z];
                        
                        // Multiply by Kt which is in color due to earlier texture calculation
                        r *= color[RED];
                        g *= color[GREEN];
                        b *= color[BLUE];



                        GzPutDisplay(render->display, i, j, ctoi(r), ctoi(g), ctoi(b), 1, newZ);
                        
                    }
                    
                    
                    // FLAT Shading 
                                            
                        //GzPutDisplay(render->display, i, j, ctoi(render->flatcolor[0]), 
                        //ctoi(render->flatcolor[1]), ctoi(render->flatcolor[2]), 1, newZ);                   

                }


            }// end of litmus test if
        }   
    
    return GZ_SUCCESS;
}
示例#21
0
void process_channel_gain(uint8 idx){
	ADC_SetGain(idx, ctoi(value, valuelen));
}
示例#22
0
static char keyToASCII(KEY_t key)
{
    uint8_t retchar = 0; // The character that returns the scan code to ASCII code

    bool shift = pressedKeys[KEY_LSHIFT] || pressedKeys[KEY_RSHIFT];
    if(capsLock)
        shift = !shift;

    // Fallback mechanism
    if (pressedKeys[KEY_ALTGR])
    {
        if (shift)
        {
            retchar = keyToASCII_shiftAltGr[key];
        }
        if (!shift || retchar == 0) // if shift is not pressed or if there is no key specified for ShiftAltGr (so retchar is still 0)
        {
            retchar = keyToASCII_altGr[key];
        }
    }
    if (!pressedKeys[KEY_ALTGR] || retchar == 0) // if AltGr is not pressed or if retchar is still 0
    {
        if (shift)
        {
            retchar = keyToASCII_shift[key];
        }
        if (!shift || retchar == 0) // if shift is not pressed or if retchar is still 0
        {
            retchar = keyToASCII_default[key];
        }
    }

    // filter special key combinations
    if (pressedKeys[KEY_LALT]) // Console-Switching
    {
        if (retchar == 'm')
        {
            console_display(KERNELCONSOLE_ID);
            return (0);
        }
        if (ctoi(retchar) != -1)
        {
            console_display(1+ctoi(retchar));
            return (0);
        }
    }
    if (pressedKeys[KEY_RCTRL] || pressedKeys[KEY_LCTRL])
    {
        if(key == KEY_ESC || retchar == 'e')
        {
            list_t* list = console_displayed->tasks;
            for(dlelement_t* e = list->head; e != 0;)
            {
                task_t* task = e->data;

                if(task->pid != 0)
                {
                    kill(task);
                    e = list->head; // Restart at beginning, because list has been modified by kill()
                }
                else
                {
                    e = e->next;
                }
            }

            return (0);
        }
    }

    if (key == KEY_PRINT || key == KEY_F12) // Save content of video memory. F12 is alias for PrintScreen due to problems in some emulators
    {
        takeScreenshot();
    }

    return (retchar);
}
示例#23
0
文件: escape.c 项目: tidatida/alarmd
int
escape_getline(FILE *file, char **pbuff, size_t *psize)
{
    int    err  = -1;
    char  *buff = *pbuff;
    size_t size = *psize;

    int n,l,h;

    if( (n = getline(&buff, &size, file)) == -1 )
    {
        goto cleanup;
    }

    while( (n > 0) && (buff[n-1] <= 32u) )
    {
        buff[--n] = 0;
    }

    char *src = buff;
    char *dst = buff;

    while( (n = *src++) != 0 )
    {
        if( n != '\\' )
        {
            *dst++ = n;
            continue;
        }

        switch( (n = *src++) )
        {
        case '\\':
            *dst++ = '\\';
            break;
        case 'b':
            *dst++ = '\b';
            break;
        case 'n':
            *dst++ = '\n';
            break;
        case 'r':
            *dst++ = '\r';
            break;
        case 't':
            *dst++ = '\t';
            break;

        case 'x':
            if( (h = ctoi(*src++)) == -1 ) goto cleanup;
            if( (l = ctoi(*src++)) == -1 ) goto cleanup;
            *dst++ = (h << 4) | (l << 0);
            break;

        default:
            goto cleanup;
        }

    }

    *dst = 0;
    err = 0;

cleanup:

    *pbuff = buff;
    *psize = size;

    return err;
}
示例#24
0
文件: imail.c 项目: DroiDev/zint
int imail(struct zint_symbol *symbol, unsigned char source[], int length)
{
	char data_pattern[200];
	int error_number;
        int i, j, read;
        char zip[35], tracker[35], zip_adder[11], temp[2];
        short int accum[112], x_reg[112], y_reg[112];
        unsigned char byte_array[13];
        unsigned short usps_crc;
        int codeword[10];
        unsigned short characters[10];
        short int bit_pattern[13], bar_map[130];

	error_number = 0;

	if(length > 32) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	error_number = is_sane(SODIUM, source, length);
	if(error_number == ERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Invalid characters in data");
		return error_number;
	}
	
        strcpy(zip, "");
        strcpy(tracker, "");

        /* separate the tracking code from the routing code */
	
	read = 0;
	j = 0;
	for(i = 0; i < length; i++) {
		if(source[i] == '-') {
			tracker[read] = '\0';
			j = 1;
			read = 0;
		} else {
			if(j == 0) {
				/* reading tracker */
				tracker[read] = source[i];
				read++;
			} else {
				/* reading zip code */
				zip[read] = source[i];
				read++;
			}
		}
	}
	if(j == 0) {
		tracker[read] = '\0';
	} else {
		zip[read] = '\0';
	}
	
	if(strlen(tracker) != 20) {
		strcpy(symbol->errtxt, "Invalid length tracking code");
		return ERROR_INVALID_DATA;
	}
	if(strlen(zip) > 11) {
		strcpy(symbol->errtxt, "Invalid ZIP code");
		return ERROR_INVALID_DATA;
	}
	
	/* *** Step 1 - Conversion of Data Fields into Binary Data *** */
	
	/* Routing code first */
	
	for(i = 0; i < 112; i++) {
		accum[i] = 0;
	}
	
	for(read = 0; read < strlen(zip); read++) {

		for(i = 0; i < 112; i++) {
			x_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, x_reg);
		}
		
		x_reg[0] = BCD[ctoi(zip[read]) * 4];
		x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1];
		x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2];
		x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			x_reg[i] = 0;
		}
		
		binary_add(accum, x_reg);
	}
	
	/* add weight to routing code */
	
	for(i = 0; i < 112; i++) {
		x_reg[i] = accum[i];
	}
	
	if(strlen(zip) > 9) {
		strcpy(zip_adder, "1000100001");
	} else {
		if(strlen(zip) > 5) {
			strcpy(zip_adder, "100001");
		} else {
			if(strlen(zip) > 0) {
				strcpy(zip_adder, "1");
			} else {
				strcpy(zip_adder, "0");
			}
		}
	}
	
	for(i = 0; i < 112; i++) {
		accum[i] = 0;
	}
	
	for(read = 0; read < strlen(zip_adder); read++) {

		for(i = 0; i < 112; i++) {
			y_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, y_reg);
		}
		
		y_reg[0] = BCD[ctoi(zip_adder[read]) * 4];
		y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1];
		y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2];
		y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			y_reg[i] = 0;
		}
		
		binary_add(accum, y_reg);
	}

	binary_add(accum, x_reg);
	
	/* tracking code */

	/* multiply by 10 */
	for(i = 0; i < 112; i++) {
		y_reg[i] = accum[i];
	}
		
	for(i = 0; i < 9; i++) {
		binary_add(accum, y_reg);
	}
	
	/* add first digit of tracker */
	y_reg[0] = BCD[ctoi(tracker[0]) * 4];
	y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1];
	y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2];
	y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3];
	for(i = 4; i < 112; i++) {
		y_reg[i] = 0;
	}
		
	binary_add(accum, y_reg);
	
	/* multiply by 5 */
	for(i = 0; i < 112; i++) {
		y_reg[i] = accum[i];
	}
		
	for(i = 0; i < 4; i++) {
		binary_add(accum, y_reg);
	}
	
	/* add second digit */
	y_reg[0] = BCD[ctoi(tracker[1]) * 4];
	y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1];
	y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2];
	y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3];
	for(i = 4; i < 112; i++) {
		y_reg[i] = 0;
	}
	
	binary_add(accum, y_reg);
	
	/* and then the rest */

	for(read = 2; read < strlen(tracker); read++) {

		for(i = 0; i < 112; i++) {
			y_reg[i] = accum[i];
		}
		
		for(i = 0; i < 9; i++) {
			binary_add(accum, y_reg);
		}
		
		y_reg[0] = BCD[ctoi(tracker[read]) * 4];
		y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1];
		y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2];
		y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3];
		for(i = 4; i < 112; i++) {
			y_reg[i] = 0;
		}
		
		binary_add(accum, y_reg);
	}

	/* printf("Binary data 1: ");
	hex_dump(accum); */
	
	/* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */

	accum[103] = 0;
	accum[102] = 0;
	
	memset(byte_array, 0, 13);
	for(j = 0; j < 13; j++) {
		i = 96 - (8 * j);
		byte_array[j] = 0;
		byte_array[j] += accum[i];
		byte_array[j] += 2 * accum[i + 1];
		byte_array[j] += 4 * accum[i + 2];
		byte_array[j] += 8 * accum[i + 3];
		byte_array[j] += 16 * accum[i + 4];
		byte_array[j] += 32 * accum[i + 5];
		byte_array[j] += 64 * accum[i + 6];
		byte_array[j] += 128 * accum[i + 7];
	}
	
	usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array);
	/* printf("FCS 2: %4.4X\n", usps_crc); */
	
	/* *** Step 3 - Conversion from Binary Data to Codewords *** */
	
	/* start with codeword J which is base 636 */
	for(i = 0; i < 112; i++) {
		x_reg[i] = 0;
		y_reg[i] = 0;
	}
	
	x_reg[101] = 1;
	x_reg[98] = 1;
	x_reg[97] = 1;
	x_reg[96] = 1;
	x_reg[95] = 1;
	x_reg[94] = 1;
	
	for(i = 92; i >= 0; i--) {
		y_reg[i] = islarger(accum, x_reg);
		if(y_reg[i] == 1) {
			binary_subtract(accum, x_reg);
		}
		shiftdown(x_reg);
	}
	
	codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) +
			(accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
			(accum[1] * 2) + accum[0];
	
	/* then codewords I to B with base 1365 */
	
	for(j = 8; j > 0; j--) {
		for(i = 0; i < 112; i++) {
			accum[i] = y_reg[i];
			y_reg[i] = 0;
			x_reg[i] = 0;
		}
		x_reg[101] = 1;
		x_reg[99] = 1;
		x_reg[97] = 1;
		x_reg[95] = 1;
		x_reg[93] = 1;
		x_reg[91] = 1;
		for(i = 91; i >= 0; i--) {
			y_reg[i] = islarger(accum, x_reg);
			if(y_reg[i] == 1) {
				binary_subtract(accum, x_reg);
			}
			shiftdown(x_reg);
		}
	
		codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) +
				(accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) +
				(accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) +
				(accum[1] * 2) + accum[0];
	}
	
	codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) +
			(y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) +
			(y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) +
			(y_reg[1] * 2) + y_reg[0];
	
	for(i = 0; i < 8; i++) {
		if(codeword[i] == 1365) {
			codeword[i] = 0;
			codeword[i + 1]++;
		}
	}

	/* printf("Codewords  3: ");
	for(i = 0; i < 10; i++) {
		printf("%d ", codeword[i]);
	}
	printf("\n"); */
	
	/* *** Step 4 - Inserting Additional Information into Codewords *** */
	
	codeword[9] = codeword[9] * 2;
	
	if(usps_crc >= 1024) {
		codeword[0] += 659;
	}
	
	/* printf("Codewords 4b: ");
	for(i = 0; i < 10; i++) {
		printf("%d ", codeword[i]);
	}
	printf("\n"); */
	
	/* *** Step 5 - Conversion from Codewords to Characters *** */
	
	for(i = 0; i < 10; i++) {
		if(codeword[i] < 1287) {
			characters[i] = AppxD_I[codeword[i]];
		} else {
			characters[i] = AppxD_II[codeword[i] - 1287];
		}
	}
	
	/* printf("Characters 5a: ");
	for(i = 0; i < 10; i++) {
		printf("%4.4X ", characters[i]);
	}
	printf("\n"); */

	breakup(bit_pattern, usps_crc);

	for(i = 0; i < 10; i++) {
		if(bit_pattern[i] == 1) {
			characters[i] = 0x1FFF - characters[i];
		}
	}
	
	/* printf("Characters 5b: ");
	for(i = 0; i < 10; i++) {
		printf("%4.4X ", characters[i]);
	}
	printf("\n"); */

	/* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */
	
	for(i = 0; i < 10; i++) {
		breakup(bit_pattern, characters[i]);
		for(j = 0; j < 13; j++) {
			bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j];
		}
	}
	
	strcpy(data_pattern, "");
	temp[1] = '\0';
	for(i = 0; i < 65; i++) {
		j = 0;
		if(bar_map[i] == 0)
			j += 1;
		if(bar_map[i + 65] == 0)
			j += 2;
		temp[0] = itoc(j);
		concat(data_pattern, temp);
	}
	
	/* Translate 4-state data pattern to symbol */
	read = 0;
	for(i = 0; i < strlen(data_pattern); i++)
	{
		if((data_pattern[i] == '1') || (data_pattern[i] == '0'))
		{
			set_module(symbol, 0, read);
		}
		set_module(symbol, 1, read);
		if((data_pattern[i] == '2') || (data_pattern[i] == '0'))
		{
			set_module(symbol, 2, read);
		}
		read += 2;
	}

	symbol->row_height[0] = 3;
	symbol->row_height[1] = 2;
	symbol->row_height[2] = 3;

	symbol->rows = 3;
	symbol->width = read - 1;
	return error_number;
}
示例#25
0
文件: png.c 项目: domribaut/zint
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{
	int i, row, column, errn;
	int fgred, fggrn, fgblu, bgred, bggrn, bgblu;

	switch(rotate_angle) {
		case 0:
		case 180:
			symbol->bitmap_width = image_width;
			symbol->bitmap_height = image_height;
			break;
		case 90:
		case 270:
			symbol->bitmap_width = image_height;
			symbol->bitmap_height = image_width;
			break;
	}

	if (symbol->bitmap != NULL)
		free(symbol->bitmap);

    symbol->bitmap = (char *) malloc(image_width * image_height * 3);


	/* sort out colour options */
	to_upper((unsigned char*)symbol->fgcolour);
	to_upper((unsigned char*)symbol->bgcolour);

	if(strlen(symbol->fgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	if(strlen(symbol->bgcolour) != 6) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}
	errn = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
	if (errn == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed foreground colour target");
		return ZERROR_INVALID_OPTION;
	}
	errn = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->fgcolour));
	if (errn == ZERROR_INVALID_DATA) {
		strcpy(symbol->errtxt, "Malformed background colour target");
		return ZERROR_INVALID_OPTION;
	}

	fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
	fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
	fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]);
	bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
	bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
	bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);

	/* Pixel Plotting */
	i = 0;
	switch(rotate_angle) {
		case 0: /* Plot the right way up */
			for(row = 0; row < image_height; row++) {
				for(column = 0; column < image_width; column++) {
					switch(*(pixelbuf + (image_width * row) + column))
					{
						case '1':
							symbol->bitmap[i++] = fgred;
							symbol->bitmap[i++] = fggrn;
							symbol->bitmap[i++] = fgblu;
							break;
						default:
							symbol->bitmap[i++] = bgred;
							symbol->bitmap[i++] = bggrn;
							symbol->bitmap[i++] = bgblu;
							break;

					}
				}
			}
			break;
		case 90: /* Plot 90 degrees clockwise */
			for(row = 0; row < image_width; row++) {
				for(column = 0; column < image_height; column++) {
					switch(*(pixelbuf + (image_width * (image_height - column - 1)) + row))
					{
						case '1':
							symbol->bitmap[i++] = fgred;
							symbol->bitmap[i++] = fggrn;
							symbol->bitmap[i++] = fgblu;
							break;
						default:
							symbol->bitmap[i++] = bgred;
							symbol->bitmap[i++] = bggrn;
							symbol->bitmap[i++] = bgblu;
							break;

					}
				}
			}
			break;
		case 180: /* Plot upside down */
			for(row = 0; row < image_height; row++) {
				for(column = 0; column < image_width; column++) {
					switch(*(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1)))
					{
						case '1':
							symbol->bitmap[i++] = fgred;
							symbol->bitmap[i++] = fggrn;
							symbol->bitmap[i++] = fgblu;
							break;
						default:
							symbol->bitmap[i++] = bgred;
							symbol->bitmap[i++] = bggrn;
							symbol->bitmap[i++] = bgblu;
							break;

					}
				}
			}
			break;
		case 270: /* Plot 90 degrees anti-clockwise */
			for(row = 0; row < image_width; row++) {
				for(column = 0; column < image_height; column++) {
					switch(*(pixelbuf + (image_width * column) + (image_width - row - 1)))
					{
						case '1':
							symbol->bitmap[i++] = fgred;
							symbol->bitmap[i++] = fggrn;
							symbol->bitmap[i++] = fgblu;
							break;
						default:
							symbol->bitmap[i++] = bgred;
							symbol->bitmap[i++] = bggrn;
							symbol->bitmap[i++] = bgblu;
							break;

					}
				}
			}
			break;
	}

	return 0;
}
示例#26
0
文件: code49.c 项目: DroiDev/zint
int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
{
	int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
	char intermediate[170];
	int codewords[170], codeword_count;
	int c_grid[8][8]; /* Refers to table 3 */
	int w_grid[8][4]; /* Refets to table 2 */
	int pad_count = 0;
	char pattern[40];
	int gs1;

	if(length > 81) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }

	strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */
	for(i = 0; i < length; i++) {
		if(source[i] > 127) {
			strcpy(symbol->errtxt, "Invalid characters in input data");
			return ERROR_INVALID_DATA;
		}
		if(gs1 && (source[i] == '['))
			concat(intermediate, "*"); /* FNC1 */
		else
			concat(intermediate, c49_table7[source[i]]);
	}

	codeword_count = 0;
	i = 0;
	h = strlen(intermediate);
	do {
		if((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
			/* Numeric data */
			for(j = 0; (intermediate[i + j] >= '0') && (intermediate[i + j] <= '9'); j++);
			if(j >= 5) {
				/* Use Numeric Encodation Method */
				int block_count, c;
				int block_remain;
				int block_value;
				
				codewords[codeword_count] = 48; /* Numeric Shift */
				codeword_count++;
				
				block_count = j / 5;
				block_remain = j % 5;
				
				for(c = 0; c < block_count; c++) {
					if((c == block_count - 1) && (block_remain == 2)) {
						/* Rule (d) */
						block_value = 100000;
						block_value += ctoi(intermediate[i]) * 1000;
						block_value += ctoi(intermediate[i + 1]) * 100;
						block_value += ctoi(intermediate[i + 2]) * 10;
						block_value += ctoi(intermediate[i + 3]);
					
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 4;
						block_value = ctoi(intermediate[i]) * 100;
						block_value += ctoi(intermediate[i + 1]) * 10;
						block_value += ctoi(intermediate[i + 2]);
						
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 3;
					} else {	
						block_value = ctoi(intermediate[i]) * 10000;
						block_value += ctoi(intermediate[i + 1]) * 1000;
						block_value += ctoi(intermediate[i + 2]) * 100;
						block_value += ctoi(intermediate[i + 3]) * 10;
						block_value += ctoi(intermediate[i + 4]);
						
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 5;
					}
				}
				
				switch(block_remain) {
					case 1:
						/* Rule (a) */
						codewords[codeword_count] = posn(INSET, intermediate[i]);
						codeword_count++;
						i++;
						break;
					case 3:
						/* Rule (b) */
						block_value = ctoi(intermediate[i]) * 100;
						block_value += ctoi(intermediate[i + 1]) * 10;
						block_value += ctoi(intermediate[i + 2]);
						
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 3;
						break;
					case 4:
						/* Rule (c) */
						block_value = 100000;
						block_value += ctoi(intermediate[i]) * 1000;
						block_value += ctoi(intermediate[i + 1]) * 100;
						block_value += ctoi(intermediate[i + 2]) * 10;
						block_value += ctoi(intermediate[i + 3]);
					
						codewords[codeword_count] = block_value / (48 * 48);
						block_value = block_value - (48 * 48) * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value / 48;
						block_value = block_value - 48 * codewords[codeword_count];
						codeword_count++;
						codewords[codeword_count] = block_value;
						codeword_count++;
						i += 4;
						break;
				}
				if(i < h) {
					/* There is more to add */
					codewords[codeword_count] = 48; /* Numeric Shift */
					codeword_count++;
				}
			} else {
				codewords[codeword_count] = posn(INSET, intermediate[i]);
				codeword_count++;
				i++;
			}
		} else {
			codewords[codeword_count] = posn(INSET, intermediate[i]);
			codeword_count++;
			i++;
		}
	} while(i < h);
	
	switch(codewords[0]) { /* Set starting mode value */
		case 48: M = 2;
		case 43: M = 4;
		case 44: M = 5;
		default: M = 0;
	}
	
	if(M != 0) {
		for(i = 0; i < codeword_count; i++) {
			codewords[i] = codewords[i + 1];
		}
		codeword_count--;
	}
	
	if(codeword_count > 49) {
		strcpy(symbol->errtxt, "Input too long");
		return ERROR_TOO_LONG;
	}
	
	/* Place codewords in code character array (c grid) */
	rows = 0;
	do{
		for(i = 0; i < 7; i++) {
			if(((rows * 7) + i) < codeword_count) {
				c_grid[rows][i] = codewords[(rows * 7) + i];
			} else {
				c_grid[rows][i] = 48; /* Pad */
				pad_count++;
			}
		}
		rows++;
	} while ((rows * 7) < codeword_count);
	
	if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
		/* Add a row */
		for(i = 0; i < 7; i++) {
			c_grid[rows][i] = 48; /* Pad */
		}
		rows++;
	}
	
	/* Add row count and mode character */
	c_grid[rows - 1][6] = (7 * (rows - 2)) + M;
	
	/* Add row check character */
	for(i = 0; i < rows - 1; i++) {
		int row_sum = 0;
		
		for(j = 0; j < 7; j++) {
			row_sum += c_grid[i][j];
		}
		c_grid[i][7] = row_sum % 49;
	}
	
	/* Calculate Symbol Check Characters */
	posn_val = 0;
	x_count = c_grid[rows - 1][6] * 20;
	y_count = c_grid[rows - 1][6] * 16;
	z_count = c_grid[rows - 1][6] * 38;
	for(i = 0; i < rows - 1; i++) {
		for(j = 0; j < 4; j++) {
			local_value = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
			x_count += c49_x_weight[posn_val] * local_value;
			y_count += c49_y_weight[posn_val] * local_value;
			z_count += c49_z_weight[posn_val] * local_value;
			posn_val++;
		}
	}
	
	if(rows > 6) {
		/* Add Z Symbol Check */
		c_grid[rows - 1][0] = (z_count % 2401) / 49;
		c_grid[rows - 1][1] = (z_count % 2401) % 49;
	}
	
	local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1];
	x_count += c49_x_weight[posn_val] * local_value;
	y_count += c49_y_weight[posn_val] * local_value;
	posn_val++;
	
	/* Add Y Symbol Check */
	c_grid[rows - 1][2] = (y_count % 2401) / 49;
	c_grid[rows - 1][3] = (y_count % 2401) % 49;
	
	local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3];
	x_count += c49_x_weight[posn_val] * local_value;
	
	/* Add X Symbol Check */
	c_grid[rows - 1][4] = (x_count % 2401) / 49;
	c_grid[rows - 1][5] = (x_count % 2401) % 49;
	
	/* Add last row check character */
	j = 0;
	for(i = 0; i < 7; i++) {
		j += c_grid[rows - 1][i];
	}
	c_grid[rows - 1][7] = j % 49;
	
	/* Transfer data to symbol character array (w grid) */
	for(i = 0; i < rows; i++) {
		for(j = 0; j < 4; j ++) {
			w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1];
		}
	}
	
	for(i = 0; i < rows; i++) {
		strcpy(pattern, "11"); /* Start character */
		for(j = 0; j < 4; j++) {
			if(i != (rows - 1)) {
				if(c49_table4[i][j] == 'E') {
					/* Even Parity */
					concat(pattern, c49_appxe_even[w_grid[i][j]]);
				} else {
					/* Odd Parity */
					concat(pattern, c49_appxe_odd[w_grid[i][j]]);
				}
			} else {
				/* Last row uses all even parity */
				concat(pattern, c49_appxe_even[w_grid[i][j]]);
			}
		}
		concat(pattern, "4"); /* Stop character */
		
		/* Expand into symbol */
		symbol->row_height[i] = 10;
		expand(symbol, pattern);
	}
	
	symbol->whitespace_width = 10;
	symbol->output_options = BARCODE_BIND;
	symbol->border_width = 2;

	return 0;
}
示例#27
0
int GzPutTriangle(GzRender *render, int	numParts, GzToken *nameList,
	GzPointer *valueList)
	/* numParts - how many names and values */
{
	/*
	- pass in a triangle description with tokens and values corresponding to
	GZ_NULL_TOKEN:		do nothing - no values
	GZ_POSITION:		3 vert positions
	- Invoke the scan converter and return an error code
	*/
	if ((NULL == render) || (NULL == nameList) || (NULL == valueList))
	{
		return GZ_FAILURE;
	}
	for (int nCnt = 0; nCnt < numParts; nCnt++)
	{
		if (nameList[nCnt] == GZ_POSITION)
		{
			GzCoord* acGzCoord;
			acGzCoord = (GzCoord*)(valueList[nCnt]);
			GzCoord asGzCoordX = { acGzCoord[0][0], acGzCoord[1][0], acGzCoord[2][0] };
			GzCoord asGzCoordY = { acGzCoord[0][1], acGzCoord[1][1], acGzCoord[2][1] };
			GzCoord asGzCoordZ = { acGzCoord[0][2], acGzCoord[1][2], acGzCoord[2][2] };
			//Sort the matrix according to Y
			for (int anSortYCnt = 1; anSortYCnt < 3; anSortYCnt++)
			{
				if (asGzCoordY[anSortYCnt - 1] > asGzCoordY[anSortYCnt])
				{
					float afSortTemmp;
					afSortTemmp = asGzCoordX[anSortYCnt - 1];
					asGzCoordX[anSortYCnt - 1] = asGzCoordX[anSortYCnt];
					asGzCoordX[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordY[anSortYCnt - 1];
					asGzCoordY[anSortYCnt - 1] = asGzCoordY[anSortYCnt];
					asGzCoordY[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordZ[anSortYCnt - 1];
					asGzCoordZ[anSortYCnt - 1] = asGzCoordZ[anSortYCnt];
					asGzCoordZ[anSortYCnt] = afSortTemmp;
				}
			}
			float afGzCoordY_Min = asGzCoordY[0];			// find min y 
			float afGzCoordY_Max = asGzCoordY[2];			// find max y
			float tmp;
			for (int anSortYCnt = 1; anSortYCnt < 3; anSortYCnt++)
			{
				if ((asGzCoordY[anSortYCnt - 1] == asGzCoordY[anSortYCnt]) && (asGzCoordX[anSortYCnt - 1] > asGzCoordX[anSortYCnt]))
				{
					float afSortTemmp;
					afSortTemmp = asGzCoordX[anSortYCnt - 1];
					asGzCoordX[anSortYCnt - 1] = asGzCoordX[anSortYCnt];
					asGzCoordX[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordY[anSortYCnt - 1];
					asGzCoordY[anSortYCnt - 1] = asGzCoordY[anSortYCnt];
					asGzCoordY[anSortYCnt] = afSortTemmp;
					afSortTemmp = asGzCoordZ[anSortYCnt - 1];
					asGzCoordZ[anSortYCnt - 1] = asGzCoordZ[anSortYCnt];
					asGzCoordZ[anSortYCnt] = afSortTemmp;
				}
			}
			float afCoefA = asGzCoordY[2] - asGzCoordY[0];
			float afCoefB = asGzCoordX[0] - asGzCoordX[2];
			float afCoefC = -afCoefB*asGzCoordY[0] - afCoefA * asGzCoordX[0];
			float acTestX = -(afCoefB*asGzCoordY[1] + afCoefC) / afCoefA;
			if (acTestX < asGzCoordX[1])
			{
				tmp = asGzCoordY[2];
				asGzCoordY[2] = asGzCoordY[1];
				asGzCoordY[1] = tmp;
				tmp = asGzCoordX[2];
				asGzCoordX[2] = asGzCoordX[1];
				asGzCoordX[1] = tmp;
				tmp = asGzCoordZ[2];
				asGzCoordZ[2] = asGzCoordZ[1];
				asGzCoordZ[1] = tmp;
			}
			//find the max and min for X and Y
			float afMaxX, afMinX, afMaxY, afMinY;
			afMaxX = asGzCoordX[0];
			afMinX = asGzCoordX[0];
			afMaxY = asGzCoordY[0];
			afMinY = asGzCoordY[0];
			for (int anCntMinMaxCnt = 1; anCntMinMaxCnt < 3; anCntMinMaxCnt++)
			{
				if (afMaxX <= asGzCoordX[anCntMinMaxCnt])
				{
					afMaxX = asGzCoordX[anCntMinMaxCnt];
				}
				if (afMinX >= asGzCoordX[anCntMinMaxCnt])
				{
					afMinX = asGzCoordX[anCntMinMaxCnt];
				}
				if (afMaxY <= asGzCoordY[anCntMinMaxCnt])
				{
					afMaxY = asGzCoordY[anCntMinMaxCnt];
				}
				if (afMinY >= asGzCoordY[anCntMinMaxCnt])
				{
					afMinY = asGzCoordY[anCntMinMaxCnt];
				}
			}
			//set the boundary of x and y
			if (afMinX < 0)
			{
				afMinX = 0;
			}
			else if (afMinX > 255)
			{
				afMinX = 255;
			}
			if (afMaxX < 0){
				afMaxX = 0;
			}
			else if (afMaxX > 255)
			{
				afMaxX = 255;
			}
			if (afMinY < 0){
				afMinY = 0;
			}
			else if (afMinY > 255)
			{
				afMinY = 255;
			}
			if (afMaxY < 0){
				afMaxY = 0;
			}
			else if (afMaxY > 255)
			{
				afMaxY = 255;
			}
			//set the variants of vertex Ax + By + C = 0
			float afCoefA1, afCoefA2, afCoefA3, afCoefB1, afCoefB2, afCoefB3, afCoefC1, afCoefC2, afCoefC3;
			float AfDiff1, AfDiff2, AfDiff3;
			float afVar1, afVar2, afVar3, afVar4;
			GzIntensity asR, asG, asB, asAlpha;
			GzDepth anZ;
			int anInterZ;
			afCoefA1 = asGzCoordY[1] - asGzCoordY[0];
			afCoefA2 = asGzCoordY[2] - asGzCoordY[1];
			afCoefA3 = asGzCoordY[0] - asGzCoordY[2];
			afCoefB1 = -(asGzCoordX[1] - asGzCoordX[0]);
			afCoefB2 = -(asGzCoordX[2] - asGzCoordX[1]);
			afCoefB3 = -(asGzCoordX[0] - asGzCoordX[2]);
			afCoefC1 = ((-(afCoefB1)*asGzCoordY[1]) - (afCoefA1 * asGzCoordX[1]));
			afCoefC2 = ((-(afCoefB2)*asGzCoordY[2]) - (afCoefA2 * asGzCoordX[2]));
			afCoefC3 = ((-(afCoefB3)*asGzCoordY[0]) - (afCoefA3 * asGzCoordX[0]));
			afVar1 = (((asGzCoordY[1] - asGzCoordY[0])*(asGzCoordZ[2] - asGzCoordZ[0])) - ((asGzCoordY[2] - asGzCoordY[0])*(asGzCoordZ[1] - asGzCoordZ[0])));
			afVar2 = (((asGzCoordX[2] - asGzCoordX[0])*(asGzCoordZ[1] - asGzCoordZ[0])) - ((asGzCoordX[1] - asGzCoordX[0])*(asGzCoordZ[2] - asGzCoordZ[0])));
			afVar3 = (((asGzCoordX[1] - asGzCoordX[0])*(asGzCoordY[2] - asGzCoordY[0])) - ((asGzCoordX[2] - asGzCoordX[0])*(asGzCoordY[1] - asGzCoordY[0])));
			afVar4 = -((asGzCoordY[0] * (afVar2)) + (asGzCoordX[0] * (afVar1)) + (asGzCoordZ[0] * (afVar3)));
			for (int anCntRangeX = int(afMinX); (float)anCntRangeX < (afMaxX); anCntRangeX++){
				for (int anCntRangeY = int(afMinY); (float)anCntRangeY < (afMaxY); anCntRangeY++){
					AfDiff1 = (afCoefA1*anCntRangeX) + (afCoefB1*anCntRangeY) + afCoefC1;
					AfDiff2 = (afCoefA2*anCntRangeX) + (afCoefB2*anCntRangeY) + afCoefC2;
					AfDiff3 = (afCoefA3*anCntRangeX) + (afCoefB3*anCntRangeY) + afCoefC3;
					anInterZ = -(afVar1*anCntRangeX + afVar2*anCntRangeY + afVar4) / afVar3;
					if (!(AfDiff1 < 0 || AfDiff2 < 0 || AfDiff3 < 0)){
						asR = 0;
						asG = 0;
						asB = 0;
						asAlpha = 0;
						anZ = 0;
						if (GZ_FAILURE == GzGetDisplay(render->display, anCntRangeX, anCntRangeY, &asR, &asG, &asB, &asAlpha, &anZ))
						{
							return GZ_FAILURE;
						}
						if (anZ == 0||anInterZ < anZ)
						{
							if (GZ_FAILURE == GzPutDisplay(render->display, anCntRangeX, anCntRangeY, ctoi(render->flatcolor[RED]), ctoi(render->flatcolor[GREEN]), ctoi(render->flatcolor[BLUE]), asAlpha, anInterZ))
							{
								return GZ_FAILURE;
							}
						}
					}
				}
			}
		}
		else if (nameList[nCnt] == GZ_NULL_TOKEN)
		{
			continue;
		}
	}
	return GZ_SUCCESS;
}
示例#28
0
int GzPutAttribute(GzRender	*render, int numAttributes, GzToken	*nameList, 
	GzPointer	*valueList) /* void** valuelist */
{
/*
- set renderer attribute states (e.g.: GZ_RGB_COLOR default color)
- later set shaders, interpolaters, texture maps, and lights
*/
	for (int i = 0; i < numAttributes; ++i) {
		if (nameList[i] == GZ_RGB_COLOR) { // command for coloring in RGB
			float *color = (float*)valueList[i];

			// Assigns the color from float to GzIntensity
			for (int j = 0; j < 3; ++j) {
				if (color[j] > 1.0) color[j] = 1.0; // Clamps to 1.0
				else if (color[j] < 0.0) color[j] = 0.0; // Clamps to 0.0

				render->flatcolor[j] = ctoi(color[j]); // Put color for render*/
			}
		}
		else if (nameList[i] == GZ_DIRECTIONAL_LIGHT) {
			GzLight *dLight = (GzLight*)valueList[i];
			render->lights[i] = *dLight;
			render->numlights = numAttributes;
		}
		else if (nameList[i] == GZ_AMBIENT_LIGHT) { // gets ambient light
			GzLight *aLight = (GzLight*)valueList[i];
			render->ambientlight = *aLight;
		}

		else if (nameList[i] == GZ_INTERPOLATE) { // gets interpolation mode
			int *interp = (int*)valueList[i];
			render->interp_mode = *interp;
		}

		else if (nameList[i] == GZ_DIFFUSE_COEFFICIENT) { // gets diffuse coefficient
			float *color = (float*)valueList[i];
			for (int i = 0; i < 3; ++i)
				render->Kd[i] = color[i];

		}		
		else if (nameList[i] == GZ_AMBIENT_COEFFICIENT) { // gets ambient coefficient
			float *color = (float*)valueList[i];
			for (int i = 0; i < 3; ++i)
				render->Ka[i] = color[i];
		}
		else if (nameList[i] == GZ_SPECULAR_COEFFICIENT) { // gets specular coefficient
			float *color = (float*)valueList[i];
			for (int i = 0; i < 3; ++i)
				render->Ks[i] = color[i];
		}
		else if (nameList[i] == GZ_DISTRIBUTION_COEFFICIENT) { // gets specular color
			float *specolor = (float*)valueList[i];
			render->spec = *specolor;
		}

		else if (nameList[i] == GZ_TEXTURE_MAP) { // gets texture pixel
			GzTexture tex = (GzTexture)valueList[i];
			if (tex == NULL)
				render->tex_fun = NULL;
			else render->tex_fun = tex;
		}

	}
	return GZ_SUCCESS;
}
示例#29
0
文件: code1.c 项目: Jinxiaohai/QT
int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int target[], int length)
{
	int current_mode, next_mode;
	int sp, tp, gs1, i, j, latch;
	int c40_buffer[6], c40_p;
	int text_buffer[6], text_p;
	int edi_buffer[6], edi_p;
	char decimal_binary[40];
	int byte_start = 0;
	
	sp = 0;
	tp = 0;
	latch = 0;
	memset(c40_buffer, 0, 6);
	c40_p = 0;
	memset(text_buffer, 0, 6);
	text_p = 0;
	memset(edi_buffer, 0, 6);
	edi_p = 0;
	strcpy(decimal_binary, "");
	
	if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
	if(gs1) { target[tp] = 232; tp++; } /* FNC1 */
	
	/* Step A */
	current_mode = C1_ASCII;
	next_mode = C1_ASCII;
	
	do {
		if(current_mode != next_mode) {
			/* Change mode */
			switch(next_mode) {
				case C1_C40: target[tp] = 230; tp++; break;
				case C1_TEXT: target[tp] = 239; tp++; break;
				case C1_EDI: target[tp] = 238; tp++; break;
				case C1_BYTE: target[tp] = 231; tp++; break;
			}
		}
		
		if((current_mode != C1_BYTE) && (next_mode == C1_BYTE)) { byte_start = tp; }
		current_mode = next_mode;
		
		if(current_mode == C1_ASCII) { /* Step B - ASCII encodation */
			next_mode = C1_ASCII;
			
			if((length - sp) >= 21) { /* Step B1 */
				j = 0;
				
				for(i = 0; i < 21; i++) {
					if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
				}
				
				if (j == 21) { 
					next_mode = C1_DECIMAL; 
					strcpy(decimal_binary, "1111");
				}
			}
			
			if((next_mode == C1_ASCII) && ((length - sp) >= 13)) { /* Step B2 */
				j = 0;
				
				for(i = 0; i < 13; i++) {
					if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
				}
				
				if (j == 13) {
					latch = 0;
					for(i = sp + 13; i < length; i++) {
						if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; }
					}
					
					if(!(latch)) {
						next_mode = C1_DECIMAL;
						strcpy(decimal_binary, "1111");
					}
				}
			}
			
			if(next_mode == C1_ASCII) { /* Step B3 */
				if(istwodigits(source, sp) && ((sp + 1) != length)) {
					target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130;
					tp++;
					sp += 2;
				} else {
					if((gs1) && (source[sp] == '[')) {
						if((length - sp) >= 15) { /* Step B4 */
							j = 0;
				
							for(i = 0; i < 15; i++) {
								if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
							}
				
							if (j == 15) { 
								target[tp] = 236; /* FNC1 and change to Decimal */
								tp++; sp++;
								next_mode = C1_DECIMAL; 
							}
						}
						
						if((length - sp) >= 7) { /* Step B5 */
							j = 0;
				
							for(i = 0; i < 7; i++) {
								if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
							}
				
							if (j == 7) {
								latch = 0;
								for(i = sp + 7; i < length; i++) {
									if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; }
								}
					
								if(!(latch)) {
									target[tp] = 236; /* FNC1 and change to Decimal */
									tp++; sp++;
									next_mode = C1_DECIMAL;
								}
							}
						}
					}
					
					if(next_mode == C1_ASCII) {
					
						/* Step B6 */
						next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
						
						if(next_mode == C1_ASCII) {
							if(source[sp] > 127) {
								/* Step B7 */
								target[tp] = 235; tp++; /* FNC4 */
								target[tp] = (source[sp] - 128) + 1; tp++; sp++;
							} else {
								/* Step B8 */
								if((gs1) && (source[sp] == '[')) {
									target[tp] = 232; tp++; sp++; /* FNC1 */
								} else {
									target[tp] = source[sp] + 1; tp++; sp++;
								}
							}
						}
					}
				}
			}
		}
		
		if(current_mode == C1_C40) { /* Step C - C40 encodation */
			int shift_set, value, done = 0, latch = 0;
			
			next_mode = C1_C40;
			if(c40_p == 0) {
				if((length - sp) >= 12) {
					j = 0;
				
					for(i = 0; i < 12; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
				
					if (j == 12) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if((length - sp) >= 8) {
					j = 0;
				
					for(i = 0; i < 8; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
					
					if((length - sp) == 8) {
						latch = 1;
					} else {
						latch = 1;
						for(j = sp + 8; j < length; j++) {
							if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; }
						}
					}
				
					if ((j == 8) && latch) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if(!(done)) {
					next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
				}
			}
			
			if(next_mode != C1_C40) {
				target[tp] = 255; tp++; /* Unlatch */
			} else {
				if(source[sp] > 127) {
					c40_buffer[c40_p] = 1; c40_p++;
					c40_buffer[c40_p] = 30; c40_p++; /* Upper Shift */
					shift_set = c40_shift[source[sp] - 128];
					value = c40_value[source[sp] - 128];
				} else {
					shift_set = c40_shift[source[sp]];
					value = c40_value[source[sp]];
				}
				
				if(gs1 && (source[sp] == '[')) {
					shift_set = 2;
					value = 27; /* FNC1 */
				}
				
				if(shift_set != 0) {
					c40_buffer[c40_p] = shift_set - 1; c40_p++;
				}
				c40_buffer[c40_p] = value; c40_p++;
				
				if(c40_p >= 3) {
					int iv;
					
					iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
					target[tp] = iv / 256; tp++;
					target[tp] = iv % 256; tp++;
					
					c40_buffer[0] = c40_buffer[3];
					c40_buffer[1] = c40_buffer[4];
					c40_buffer[2] = c40_buffer[5];
					c40_buffer[3] = 0;
					c40_buffer[4] = 0;
					c40_buffer[5] = 0;
					c40_p -= 3;
				}
				sp++;
			}
		}
		
		if(current_mode == C1_TEXT) { /* Step D - Text encodation */
			int shift_set, value, done = 0, latch = 0;
			
			next_mode = C1_TEXT;
			if(text_p == 0) {
				if((length - sp) >= 12) {
					j = 0;
				
					for(i = 0; i < 12; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
				
					if (j == 12) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if((length - sp) >= 8) {
					j = 0;
				
					for(i = 0; i < 8; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
					
					if((length - sp) == 8) {
						latch = 1;
					} else {
						latch = 1;
						for(j = sp + 8; j < length; j++) {
							if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; }
						}
					}
				
					if ((j == 8) && latch) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if(!(done)) {
					next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
				}
			}
			
			if(next_mode != C1_TEXT) {
				target[tp] = 255; tp++; /* Unlatch */
			} else {
				if(source[sp] > 127) {
					text_buffer[text_p] = 1; text_p++;
					text_buffer[text_p] = 30; text_p++; /* Upper Shift */
					shift_set = text_shift[source[sp] - 128];
					value = text_value[source[sp] - 128];
				} else {
					shift_set = text_shift[source[sp]];
					value = text_value[source[sp]];
				}
				
				if(gs1 && (source[sp] == '[')) {
					shift_set = 2;
					value = 27; /* FNC1 */
				}
				
				if(shift_set != 0) {
					text_buffer[text_p] = shift_set - 1; text_p++;
				}
				text_buffer[text_p] = value; text_p++;
				
				if(text_p >= 3) {
					int iv;
					
					iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
					target[tp] = iv / 256; tp++;
					target[tp] = iv % 256; tp++;
					
					text_buffer[0] = text_buffer[3];
					text_buffer[1] = text_buffer[4];
					text_buffer[2] = text_buffer[5];
					text_buffer[3] = 0;
					text_buffer[4] = 0;
					text_buffer[5] = 0;
					text_p -= 3;
				}
				sp++;
			}
		}
		
		if(current_mode == C1_EDI) { /* Step E - EDI Encodation */
			int value = 0, done = 0, latch = 0;
			
			next_mode = C1_EDI;
			if(edi_p == 0) {
				if((length - sp) >= 12) {
					j = 0;
				
					for(i = 0; i < 12; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
				
					if (j == 12) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if((length - sp) >= 8) {
					j = 0;
				
					for(i = 0; i < 8; i++) {
						if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; }
					}
					
					if((length - sp) == 8) {
						latch = 1;
					} else {
						latch = 1;
						for(j = sp + 8; j < length; j++) {
							if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; }
						}
					}
				
					if ((j == 8) && latch) { 
						next_mode = C1_ASCII; done = 1;
					}
				}
				
				if(!((isedi(source[sp]) && isedi(source[sp + 1])) && isedi(source[sp + 2]))) {
					next_mode = C1_ASCII;
				}
			}
				
			if(next_mode != C1_EDI) {
				target[tp] = 255; tp++; /* Unlatch */
			} else {
				if(source[sp] == 13) { value = 0; }
				if(source[sp] == '*') { value = 1; }
				if(source[sp] == '>') { value = 2; }
				if(source[sp] == ' ') { value = 3; }
				if((source[sp] >= '0') && (source[sp] <= '9')) { value = source[sp] - '0' + 4; }
				if((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = source[sp] - 'A' + 14; }
				
				edi_buffer[edi_p] = value; edi_p++;
				
				if(edi_p >= 3) {
					int iv;
					
					iv = (1600 * edi_buffer[0]) + (40 * edi_buffer[1]) + (edi_buffer[2]) + 1;
					target[tp] = iv / 256; tp++;
					target[tp] = iv % 256; tp++;
					
					edi_buffer[0] = edi_buffer[3];
					edi_buffer[1] = edi_buffer[4];
					edi_buffer[2] = edi_buffer[5];
					edi_buffer[3] = 0;
					edi_buffer[4] = 0;
					edi_buffer[5] = 0;
					edi_p -= 3;
				}
				sp++;
			}
		}
		
		if(current_mode == C1_DECIMAL) { /* Step F - Decimal encodation */
			int value, decimal_count, data_left;
			
			next_mode = C1_DECIMAL;
			
			data_left = length - sp;
			decimal_count = 0;
			
			if(data_left >= 1) {
				if((source[sp] >= '0') && (source[sp] <= '9')) { decimal_count = 1; } 
			}
			if(data_left >= 2) {
				if((decimal_count == 1) && ((source[sp + 1] >= '0') && (source[sp + 1] <= '9'))) { decimal_count = 2; }
			}
			if(data_left >= 3) {
				if((decimal_count == 2) && ((source[sp + 2] >= '0') && (source[sp + 2] <= '9'))) { decimal_count = 3; }
			}
				
			if(decimal_count != 3) {
				int bits_left_in_byte, target_count;
				int sub_target;
				/* Finish Decimal mode and go back to ASCII */
				
				concat(decimal_binary, "111111"); /* Unlatch */
				
				target_count = 3;
				if(strlen(decimal_binary) <= 16) { target_count = 2; }
				if(strlen(decimal_binary) <= 8) { target_count = 1; }
				bits_left_in_byte = (8 * target_count) - strlen(decimal_binary);
				if(bits_left_in_byte == 8) { bits_left_in_byte = 0; }
				
				if(bits_left_in_byte == 2) {
					concat(decimal_binary, "01");
				}
				
				if((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
					if(decimal_count >= 1) {
						int sub_value = ctoi(source[sp]) + 1;
						
						if(sub_value & 0x08) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
						if(sub_value & 0x04) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
						if(sub_value & 0x02) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
						if(sub_value & 0x01) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
						sp++;
					} else {
						concat(decimal_binary, "1111");
					}
				}
				
				if(bits_left_in_byte == 6) {
					concat(decimal_binary, "01");
				}
				
				/* Binary buffer is full - transfer to target */
				if(target_count >= 1) {
					sub_target = 0;
					if(decimal_binary[0] == '1') { sub_target += 128; }
					if(decimal_binary[1] == '1') { sub_target += 64; }
					if(decimal_binary[2] == '1') { sub_target += 32; }
					if(decimal_binary[3] == '1') { sub_target += 16; }
					if(decimal_binary[4] == '1') { sub_target += 8; }
					if(decimal_binary[5] == '1') { sub_target += 4; }
					if(decimal_binary[6] == '1') { sub_target += 2; }
					if(decimal_binary[7] == '1') { sub_target += 1; }
					target[tp] = sub_target; tp++;
				}
				if(target_count >= 2) {
					sub_target = 0;
					if(decimal_binary[8] == '1') { sub_target += 128; }
					if(decimal_binary[9] == '1') { sub_target += 64; }
					if(decimal_binary[10] == '1') { sub_target += 32; }
					if(decimal_binary[11] == '1') { sub_target += 16; }
					if(decimal_binary[12] == '1') { sub_target += 8; }
					if(decimal_binary[13] == '1') { sub_target += 4; }
					if(decimal_binary[14] == '1') { sub_target += 2; }
					if(decimal_binary[15] == '1') { sub_target += 1; }
					target[tp] = sub_target; tp++;
				}
				if(target_count == 3) {
					sub_target = 0;
					if(decimal_binary[16] == '1') { sub_target += 128; }
					if(decimal_binary[17] == '1') { sub_target += 64; }
					if(decimal_binary[18] == '1') { sub_target += 32; }
					if(decimal_binary[19] == '1') { sub_target += 16; }
					if(decimal_binary[20] == '1') { sub_target += 8; }
					if(decimal_binary[21] == '1') { sub_target += 4; }
					if(decimal_binary[22] == '1') { sub_target += 2; }
					if(decimal_binary[23] == '1') { sub_target += 1; }
					target[tp] = sub_target; tp++;
				}
				
				next_mode = C1_ASCII;
			} else {
				/* There are three digits - convert the value to binary */
				value = (100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1;
			
				if(value & 0x200) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x100) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x80) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x40) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x20) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x10) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x08) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x04) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x02) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				if(value & 0x01) { concat(decimal_binary, "1"); } else { concat(decimal_binary, "0"); }
				
				sp+= 3;
			}
			
			if(strlen(decimal_binary) >= 24) {
				int target1 = 0, target2 = 0, target3 = 0;
				char temp_binary[40];
				
				/* Binary buffer is full - transfer to target */
				if(decimal_binary[0] == '1') { target1 += 128; }
				if(decimal_binary[1] == '1') { target1 += 64; }
				if(decimal_binary[2] == '1') { target1 += 32; }
				if(decimal_binary[3] == '1') { target1 += 16; }
				if(decimal_binary[4] == '1') { target1 += 8; }
				if(decimal_binary[5] == '1') { target1 += 4; }
				if(decimal_binary[6] == '1') { target1 += 2; }
				if(decimal_binary[7] == '1') { target1 += 1; }
				if(decimal_binary[8] == '1') { target2 += 128; }
				if(decimal_binary[9] == '1') { target2 += 64; }
				if(decimal_binary[10] == '1') { target2 += 32; }
				if(decimal_binary[11] == '1') { target2 += 16; }
				if(decimal_binary[12] == '1') { target2 += 8; }
				if(decimal_binary[13] == '1') { target2 += 4; }
				if(decimal_binary[14] == '1') { target2 += 2; }
				if(decimal_binary[15] == '1') { target2 += 1; }
				if(decimal_binary[16] == '1') { target3 += 128; }
				if(decimal_binary[17] == '1') { target3 += 64; }
				if(decimal_binary[18] == '1') { target3 += 32; }
				if(decimal_binary[19] == '1') { target3 += 16; }
				if(decimal_binary[20] == '1') { target3 += 8; }
				if(decimal_binary[21] == '1') { target3 += 4; }
				if(decimal_binary[22] == '1') { target3 += 2; }
				if(decimal_binary[23] == '1') { target3 += 1; }
				target[tp] = target1; tp++;
				target[tp] = target2; tp++;
				target[tp] = target3; tp++;
				
				strcpy(temp_binary, "");
				if(strlen(decimal_binary) > 24) { 
					for(i = 0; i <= (strlen(decimal_binary) - 24); i++) {
						temp_binary[i] = decimal_binary[i + 24];
					}
					strcpy(decimal_binary, temp_binary);
				}
			}
		}
		
		if(current_mode == C1_BYTE) {
			next_mode = C1_BYTE;
			
			if(gs1 && (source[sp] == '[')) {
				next_mode = C1_ASCII;
			} else {
				if(source[sp] <= 127) {
					next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1);
				}
			}
			
			if(next_mode != C1_BYTE) {
				/* Insert byte field length */
				if((tp - byte_start) <= 249) {
					for(i = tp; i >= byte_start; i--) {
						target[i + 1] = target[i];
					}
					target[byte_start] = (tp - byte_start);
					tp++;
				} else {
					for(i = tp; i >= byte_start; i--) {
						target[i + 2] = target[i];
					}
					target[byte_start] = 249 + ((tp - byte_start) / 250);
					target[byte_start + 1] = ((tp - byte_start) % 250);
					tp += 2;
				}
			} else {
				target[tp] = source[sp];
				tp++;
				sp++;
			}
		}
		
		if(tp > 1480) {
			/* Data is too large for symbol */
			strcpy(symbol->errtxt, "Input data too long");
			return 0;
		}
	} while (sp < length);
	
	/* Empty buffers */
	if(c40_p == 2) {
		int iv;
		
		c40_buffer[2] = 1;
		iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
		target[tp] = iv / 256; tp++;
		target[tp] = iv % 256; tp++;
		target[tp] = 255; tp++; /* Unlatch */
	}
	if(c40_p == 1) {
		int iv;
		
		c40_buffer[1] = 1;
		c40_buffer[2] = 31; /* Pad */
		iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1;
		target[tp] = iv / 256; tp++;
		target[tp] = iv % 256; tp++;
		target[tp] = 255; tp++; /* Unlatch */
	}
	if(text_p == 2) {
		int iv;
		
		text_buffer[2] = 1;
		iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
		target[tp] = iv / 256; tp++;
		target[tp] = iv % 256; tp++;
		target[tp] = 255; tp++; /* Unlatch */
	}
	if(text_p == 1) {
		int iv;
		
		text_buffer[1] = 1;
		text_buffer[2] = 31; /* Pad */
		iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1;
		target[tp] = iv / 256; tp++;
		target[tp] = iv % 256; tp++;
		target[tp] = 255; tp++; /* Unlatch */
	}
	
	if(current_mode == C1_DECIMAL) {
		int bits_left_in_byte, target_count;
		int sub_target;
		/* Finish Decimal mode and go back to ASCII */
				
		concat(decimal_binary, "111111"); /* Unlatch */
				
		target_count = 3;
		if(strlen(decimal_binary) <= 16) { target_count = 2; }
		if(strlen(decimal_binary) <= 8) { target_count = 1; }
		bits_left_in_byte = (8 * target_count) - strlen(decimal_binary);
		if(bits_left_in_byte == 8) { bits_left_in_byte = 0; }
				
		if(bits_left_in_byte == 2) {
			concat(decimal_binary, "01");
		}
				
		if((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
			concat(decimal_binary, "1111");
		}
				
		if(bits_left_in_byte == 6) {
			concat(decimal_binary, "01");
		}
				
		/* Binary buffer is full - transfer to target */
		if(target_count >= 1) {
			sub_target = 0;
			if(decimal_binary[0] == '1') { sub_target += 128; }
			if(decimal_binary[1] == '1') { sub_target += 64; }
			if(decimal_binary[2] == '1') { sub_target += 32; }
			if(decimal_binary[3] == '1') { sub_target += 16; }
			if(decimal_binary[4] == '1') { sub_target += 8; }
			if(decimal_binary[5] == '1') { sub_target += 4; }
			if(decimal_binary[6] == '1') { sub_target += 2; }
			if(decimal_binary[7] == '1') { sub_target += 1; }
			target[tp] = sub_target; tp++;
		}
		if(target_count >= 2) {
			sub_target = 0;
			if(decimal_binary[8] == '1') { sub_target += 128; }
			if(decimal_binary[9] == '1') { sub_target += 64; }
			if(decimal_binary[10] == '1') { sub_target += 32; }
			if(decimal_binary[11] == '1') { sub_target += 16; }
			if(decimal_binary[12] == '1') { sub_target += 8; }
			if(decimal_binary[13] == '1') { sub_target += 4; }
			if(decimal_binary[14] == '1') { sub_target += 2; }
			if(decimal_binary[15] == '1') { sub_target += 1; }
			target[tp] = sub_target; tp++;
		}
		if(target_count == 3) {
			sub_target = 0;
			if(decimal_binary[16] == '1') { sub_target += 128; }
			if(decimal_binary[17] == '1') { sub_target += 64; }
			if(decimal_binary[18] == '1') { sub_target += 32; }
			if(decimal_binary[19] == '1') { sub_target += 16; }
			if(decimal_binary[20] == '1') { sub_target += 8; }
			if(decimal_binary[21] == '1') { sub_target += 4; }
			if(decimal_binary[22] == '1') { sub_target += 2; }
			if(decimal_binary[23] == '1') { sub_target += 1; }
			target[tp] = sub_target; tp++;
		}
	}
	
	if(current_mode == C1_BYTE) {
		/* Insert byte field length */
		if((tp - byte_start) <= 249) {
			for(i = tp; i >= byte_start; i--) {
				target[i + 1] = target[i];
			}
			target[byte_start] = (tp - byte_start);
			tp++;
		} else {
			for(i = tp; i >= byte_start; i--) {
				target[i + 2] = target[i];
			}
			target[byte_start] = 249 + ((tp - byte_start) / 250);
			target[byte_start + 1] = ((tp - byte_start) % 250);
			tp += 2;
		}
	}

	/* Re-check length of data */
	if(tp > 1480) {
		/* Data is too large for symbol */
		strcpy(symbol->errtxt, "Input data too long");
		return 0;
	}
	/* 
	printf("targets:\n");
	for(i = 0; i < tp; i++) {
		printf("[%d]", target[i]);
	}
	printf("\n");
	*/
	return tp;
}
示例#30
0
void scanLineGouraud(GzRender *render, float x_begin, float x_end, int y, float* norm, float d, float *color1, float *color2, float* TexPoint1, float* TexPoint2) { // Span line method

	int index; // used to find index within triangles
	float z;

	if (!(x_begin > render->display->xres - 1 || x_end < 0)) { // checks and see if line is within the screen

		// prevents same line from being drawn twice for later triangles
		int x = ceilf(x_begin);
		if (x == x_begin)
			++x;

		float x_s = x_begin;
		float total = x_end - x_begin;

		// Clamps the value between 0 and xres
		if (x_begin < 0)
			x = 0.0;
		if (x_end > render->display->xres - 1)
			x_end = render->display->xres - 1;

		float t;

		for (x; x <= x_end; ++x) { // begins spanning line
			index = (render->display->xres * y) + x;

			t = (x - x_s) / total;

			// interpolates z at that point
			z = -((norm[0] * (float)x) + (norm[1] * (float)y) + d) / norm[2];

			if (z < render->display->fbuf[index].z && z >= 0) { // if the object is in front of what's on fbuf
				if (render->tex_fun == NULL) {
					render->display->fbuf[index].red = ctoi((color1[0] * (1 - t) + color2[0] * t));
					render->display->fbuf[index].green = ctoi((color1[1] * (1 - t) + color2[1] * t));
					render->display->fbuf[index].blue = ctoi((color1[2] * (1 - t) + color2[2] * t));
				}
				else {
					// look up kd and ka
					float newTex[2];
					for (int n = 0; n < 2; ++n) // interpolate u and v
						newTex[n] = (TexPoint1[n] * (1 - t) + TexPoint2[n] * t);

					for (int n = 0; n < 2; ++n) // revert the interpolated value back to screen space
						newTex[n] *= ((z / ((float)MAXINT - z)) + 1);

					float texColor[3];
					render->tex_fun(newTex[0], newTex[1], texColor); // grab color from texture

					float rgb[3];
					for (int c = 0; c < 3; ++c) { // multiply by Ktexture and clamp
						rgb[c] = ((color1[c] * (1 - t) + color2[c] * t) * texColor[c]);
						if (rgb[c] > 1)
							rgb[c] = 1;
						if (rgb[c] < 0)
							rgb[c] = 0;
					}
					render->display->fbuf[index].red = ctoi(rgb[0]);
					render->display->fbuf[index].green = ctoi(rgb[1]);
					render->display->fbuf[index].blue = ctoi(rgb[2]);
				}
				render->display->fbuf[index].z = z;
			}
		}
	}
}