示例#1
0
int pat_info() {
	FILE *fp;
	fp = fopen("patient.txt", "rb+");
	if(fp == NULL) {
		perror(" file cannot be accessed:");
		return errno;
	}
	int op, n;
	char err[32];
	while(1) {
		printpatmenu();
		b:printf("\n\n\n\tEnter the option number:");
		n = scanf("%d", &op);
		if(n == 0) {
			op = 7;
			readline(err, 32);
		}
		switch(op) {
			case 1:system("clear");
				printheader();
				new_pat(fp);
				break;
			case 2:system("clear");
				printheader();
				edit_pat(fp);
				break;
			case 3:system("clear");
				printheader();
				search_pat(fp);
				break;
			case 4:system("clear");
				printheader();
				list_pat(fp);
				break;
			case 5:system("clear");
				printheader();
				close_pat(fp);
				break;
			case 6:system("clear");
				fclose(fp);
				printheader();
				printmainmenu();
				break;
			default:printf("\n\n\t***Invalid entry***");
				goto b;		
				break;		
		}
	}
	return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
	int i;
	int fa,nfa;				/* current argument we're looking at */
	int verb = 0;
	int limit = -1;
	static char tarname[200] = { 0 };		/* optional 928 patch reference file */
	static char inname[200] = { 0 };		/* Input .pat file base name */
	static char outname[200] = { 0 };		/* Output cgats .ti3 file base name */
	FILE *d928_fp = NULL;
	FILE *pat_fp;
	cgats *ocg;			/* output cgats structure */
	time_t clk = time(0);
	struct tm *tsp = localtime(&clk);
	char *atm = asctime(tsp); /* Ascii time */

	error_program = "kodak2ti3";

	if (argc <= 1)
		usage();

	/* Process the arguments */
	for(fa = 1;fa < argc;fa++)
		{
		nfa = fa;					/* skip to nfa if next argument is used */
		if (argv[fa][0] == '-')		/* Look for any flags */
			{
			char *na = NULL;		/* next argument after flag, null if none */

			if (argv[fa][2] != '\000')
				na = &argv[fa][2];		/* next is directly after flag */
			else
				{
				if ((fa+1) < argc)
					{
					if (argv[fa+1][0] != '-')
						{
						nfa = fa + 1;
						na = argv[nfa];		/* next is seperate non-flag argument */
						}
					}
				}

			if (argv[fa][1] == '?')
				usage();

			else if (argv[fa][1] == 'l') {
				if (na == NULL) usage();
				fa = nfa;
				limit = atoi(na);
				if (limit < 1)
					limit = 1;
			}

			else if (argv[fa][1] == 'r') {
				if (na == NULL) usage();
				fa = nfa;
				strcpy(tarname, na);
			}

			else if (argv[fa][1] == 'v')
				verb = 1;
			else 
				usage();
			}
		else
			break;
		}

	/* Get the file name argument */
	if (fa >= argc || argv[fa][0] == '-') usage();

	strcpy(inname,argv[fa++]);
	strcat(inname,".pat");

	if (fa >= argc || argv[fa][0] == '-') usage();
	strcpy(outname, argv[fa++]);
	strcat(outname,".ti3");

	/* Open up the Test chart reference file if we were given one */
	if (tarname[0] != '\000') {
		if (verb)
			printf("Using alternate reference file '%s'\n",tarname);
		if ((d928_fp = open_928(tarname)) == NULL)
			error ("Read: Can't open file '%s'",tarname);
	}

	if ((pat_fp = open_pat(inname)) == NULL)
		error ("Read: Can't open file '%s'",inname);

	/* Setup output cgats file */
	ocg = new_cgats();	/* Create a CGATS structure */
	ocg->add_other(ocg, "CTI3"); 	/* our special type is Calibration Target Information 3 */
	ocg->add_table(ocg, tt_other, 0);	/* Start the first table */

	ocg->add_kword(ocg, 0, "DESCRIPTOR", "Argyll Calibration Target chart information 3",NULL);
	ocg->add_kword(ocg, 0, "ORIGINATOR", "Argyll target", NULL);
	atm[strlen(atm)-1] = '\000';	/* Remove \n from end */
	ocg->add_kword(ocg, 0, "CREATED",atm, NULL);
	ocg->add_kword(ocg, 0, "DEVICE_CLASS","OUTPUT", NULL);	/* What sort of device this is */

	/* Fields we want */
	ocg->add_field(ocg, 0, "SAMPLE_ID", nqcs_t);

	if (limit > 0) {
		char buf[100];
		sprintf(buf, "%d", limit);
		ocg->add_kword(ocg, 0, "TOTAL_INK_LIMIT", buf, NULL);
	}

	ocg->add_field(ocg, 0, "CMYK_C", r_t);
	ocg->add_field(ocg, 0, "CMYK_M", r_t);
	ocg->add_field(ocg, 0, "CMYK_Y", r_t);
	ocg->add_field(ocg, 0, "CMYK_K", r_t);
	ocg->add_kword(ocg, 0, "COLOR_REP","CMYK_LAB", NULL);
	ocg->add_field(ocg, 0, "LAB_L", r_t);
	ocg->add_field(ocg, 0, "LAB_A", r_t);
	ocg->add_field(ocg, 0, "LAB_B", r_t);

	/* Write out the patch info to the output CGATS file */
	for (i = 0; i < NPAT; i++) {
		char id[100];
		double cmykv[4]; 
		double labv[3]; 

		if (next_928(d928_fp, i, cmykv) != 0)
			error("Error reading reference information from '%s' file",tarname);

		if (next_pat(pat_fp, labv) != 0)
			error("Error reading Kodak .pat file");

		sprintf(id, "%d", i+1);
		ocg->add_set(ocg, 0, id, 100.0 * cmykv[0], 100.0 * cmykv[1],
		                         100.0 * cmykv[2], 100.0 * cmykv[3],
		                         labv[0], labv[1], labv[2]);
	}

	{
		double wp[3];			/* Paper white XYZ */
		double D50wp[3] 		/* D50 white point Kodak uses */
		    = { 0.9642, 1.0000, 0.8249 };
		double tt[3];
		int li;

		/* Get offset of Lab values in cgats file */
		if ((li = ocg->find_field(ocg, 0, "LAB_L")) < 0)
			error("Internal - cgats doesn't field LAB_L");

		/* Get last line of pat file - this is the paper white in XYZ */
		if (next_pat(pat_fp, wp) != 0)
			error("Error reading Kodak .pat file");

//printf("~1 white point is XYZ %f %f %f\n",wp[0],wp[1],wp[2]);

		/* Run through all the data points, and adjust them back to the absolute */
		/* white point. */

		for (i = 0; i < NPAT; i++) {
			double in[3], out[3];
	
			tt[0] = *((double *)ocg->t[0].fdata[i][li+0]);
			tt[1] = *((double *)ocg->t[0].fdata[i][li+1]);
			tt[2] = *((double *)ocg->t[0].fdata[i][li+2]);

			icmLab2XYZ(&icmD50, in, tt);

			/* Undo Kodak's D50->paper white point adjustment */
			out[0] = in[0] * (D50wp[1] * wp[0])/(D50wp[0] * wp[1]);
			out[1] = in[1];		/* Y remains unchanged */
			out[2] = in[2] * (D50wp[1] * wp[2])/(D50wp[2] * wp[1]);

			icmXYZ2Lab(&icmD50, tt, out);

			*((double *)ocg->t[0].fdata[i][li+0]) = tt[0];
			*((double *)ocg->t[0].fdata[i][li+1]) = tt[1];
			*((double *)ocg->t[0].fdata[i][li+2]) = tt[2];
		}


	}

	if (ocg->write_name(ocg, outname))
		error("Write error : %s",ocg->err);

	ocg->del(ocg);		/* Clean up */

	if (d928_fp != NULL)
		close_928(d928_fp);
	close_pat(pat_fp);

	return 0;
}