示例#1
0
static int testcolorproc()
{
	int result = 0;
	const int xres = 100;
	const int yres = 10;
	unsigned char bitmap[xres*yres*3];

	int i;
	for (i=0; i<xres*yres*3;)
	{
		bitmap[i++] = 255;
		bitmap[i++] = 127;
		bitmap[i++] = 0;
	}

	int colors[5];
	getcolors(colors, bitmap, xres, yres);

	for (i=0; i<5; ++i)
	{
		if (colors[i] != 0x00ff7f00)
		{
			printf("Wrong color at %d: %06x\n", i, colors[i]);
			result = 1;
		}
	}
	return result;
}
示例#2
0
void comfirm_box(int x, int y, int type, int covercolor, const char *msg)
{
	int len = strlen(msg),
		c,
		fcolor, bcolor, mode;

	getcolors(&fcolor, &bcolor);
	getcntmode(&mode);
	
	if (len < 10) len = 10;
	if (type == WARNMSG) setcolor(F_GRAY, B_RED);
	else setcolor(F_YELLOW, B_BLUE);

	setcntmode(ATTR_HIGHLIGHT);
	draw3Dwindow(x, y, x+7, y+3+len, type == WARNMSG ? B_RED : B_BLUE);
	cprintfxy(x, y+1, type == WARNMSG ? "-| WARN |-" :  "-| NOTE|-");
	cprintfxy(x+2, y+2, msg);
	resetcntmode();

	if (type == WARNMSG) setcolor(F_BLUE, B_RED);
	else setcolor(F_GREEN, B_BLUE);

	drawbox(x+4, y+(len+2)/2-5, x+6, y+(len+2)/2+4);
	setcolor(F_BLACK, B_WHITE);
	cprintfxy(x+5, y+len/2-3, "   OK   ");
	gotoxy(0, 0);
	fflush(stdout);
	while (c = getchar(), c != '\n' && c != 'q') putchar('\a');
	fillrectangle(x, y, x+7+1, y+3+len+1, ' ', covercolor);
	setcolor(fcolor, bcolor);
	setcntmode(mode);
}
示例#3
0
int askbox(int x, int y, int type, int covercolor, const char *ask)
{
	int 	len = strlen(ask),
			choice, oldchoice,
			fcolor, bcolor, mode,
			doneflg = 0;
	char 	c;

	getcolors(&fcolor, &bcolor);
	getcntmode(&mode);

	if (len < 10) len = 10;
	if (type == WARNASK) setcolor(F_GRAY, B_RED);
	else setcolor(F_YELLOW, B_BLUE);

	setcntmode(ATTR_HIGHLIGHT);
	draw3Dwindow(x, y, x+5, y+3+len, type == WARNASK ? B_RED : B_BLUE);
	cprintfxy(x, y+1, type == WARNASK ? "-| WARNASK |-" :  "-| NOTEASK |-");
	cprintfxy(x+2, y+2, ask);
	resetcntmode();
	setcolor(F_GRAY, B_BLACK);
	cprintfxy(x+4, y+1+len/4-2, " YES ");
	setcolor(F_BLACK, type == WARNASK ? B_RED : B_BLUE);
	cprintfxy(x+4, y+1+3*len/4-2, " NO ");
	gotoxy(0, 0);
	setcolor(fcolor, bcolor);
	choice = 0;
	for ( ; ; ) {
		oldchoice = choice;
		while (c = getchar(),
			   c != 'j' && c != 'l' && c != 'q' && c != '\n')
			putchar('\a');
		switch (c) {
			case 'j': choice = choice == 0 ? 1 : choice - 1;	break;
			case 'l': choice = choice == 1 ? 0 : choice + 1;	break;
			case 'q': choice = 1;
			case '\n': doneflg = 1;	break;
		}
		setcolor(F_BLACK, type == WARNASK ? B_RED : B_BLUE);
		cprintfxy(x+4, oldchoice == 0 ? y+1+len/4-2 : y+1+3*len/4-2,
				  oldchoice == 0 ? " YES " : " NO ");
		setcolor(F_GRAY, B_BLACK);
		cprintfxy(x+4, choice == 0 ? y+1+len/4-2 : y+1+3*len/4-2,
				  choice == 0 ? " YES " : " NO ");
		if (doneflg) break;
		gotoxy(0, 0);
		fflush(stdout);
	}
	fillrectangle(x, y, x+5+1, y+3+len+1, ' ', covercolor);
	setcolor(fcolor, bcolor);
	setcntmode(mode);
	return choice;
}
示例#4
0
void fillrectangle(int x1, int y1, int x2, int y2, char ch, int fillcolor)
{
	int		i, j;
	int		tmp_fnt_color, tmp_bak_color;

	if (x1 > x2) chg_num(&x1, &x2);
	if (y1 > y2) chg_num(&y1, &y2);

	getcolors(&tmp_fnt_color, &tmp_bak_color);
	setcolor(tmp_fnt_color, fillcolor);
	for (i = x1; i <= x2; ++i) {
		gotoxy(x1+i-x1, y1);
		for (j = y1; j <= y2; ++j)
			cputchar(ch);
	}
	setcolor(tmp_fnt_color, tmp_bak_color);
	gotoxy(x1, y1);
}
示例#5
0
int openwindow(int swidth,int sheight)

{
    
    static int firsttime = 1;
    
    void initX(),beep();
    
    int createGC(Window,GC*);
    
    XSetWindowAttributes    theWindowAttributes;
    XSizeHints              theSizeHints;
    unsigned        long    theWindowMask;
    
    if(firsttime) {
	firsttime = 0;
	initX();
    }
    ww = swidth;
    wh = sheight;
    
    if(swidth <= 0) swidth = 10;
    if(sheight <= 0) sheight = 10;
    
    theWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect;
    
    theWindowAttributes.border_pixel = theBlackPixel
    = BlackPixel( theDisplay,theScreen );
    theWindowAttributes.background_pixel = theWhitePixel
    = WhitePixel( theDisplay,theScreen );
    theWindowAttributes.override_redirect = False;
    
    
    theWindow = XCreateWindow(theDisplay,
			      RootWindow(theDisplay,theScreen),
			      orgx,orgy,
			      swidth,sheight,
			      BORDER_WIDTH,
			      theDepth,
			      InputOutput,
			      CopyFromParent,
			      theWindowMask,
			      &theWindowAttributes);
    
    theSizeHints.flags      =       PPosition | PSize;
    theSizeHints.x          =       orgx;
    theSizeHints.y          =       orgy;
    theSizeHints.width      =       swidth;
    theSizeHints.height     =       sheight;
    
    XSetNormalHints( theDisplay, theWindow, &theSizeHints );
    
    if (createGC(theWindow, &theGC) == 0 ) {
	XDestroyWindow(theDisplay, theWindow);
	beep();
	return(0);
    }
    
    XMapWindow( theDisplay, theWindow );
    
    XFlush( theDisplay );
    getcolors();
    return( 1 );
}
int
main(
	int	argc,
	char	**argv
)
{
	int	i;

	progname = argv[0];
	for (i = 1; i < argc && argv[i][0] == '-'; i++)
		switch (argv[i][1]) {
		case 'd':				/* debug output */
			i++;
			if (badarg(argc-i, argv+i, "s"))
				goto userr;
			if ((debugfp = fopen(argv[i], "w")) == NULL) {
				perror(argv[i]);
				exit(1);
			}
			SET_FILE_BINARY(debugfp);
			newheader("RADIANCE", debugfp);		/* start */
			printargs(argc, argv, debugfp);		/* header */
			break;
		case 'p':				/* picture position */
			if (badarg(argc-i-1, argv+i+1, "iiiiiiii"))
				goto userr;
			bounds[0][0] = atoi(argv[++i]);
			bounds[0][1] = atoi(argv[++i]);
			bounds[1][0] = atoi(argv[++i]);
			bounds[1][1] = atoi(argv[++i]);
			bounds[2][0] = atoi(argv[++i]);
			bounds[2][1] = atoi(argv[++i]);
			bounds[3][0] = atoi(argv[++i]);
			bounds[3][1] = atoi(argv[++i]);
			scanning = 2;
			break;
		case 'P':				/* pick position */
			scanning = 3;
			break;
		case 'i':				/* irradiance factor */
			i++;
			if (badarg(argc-i, argv+i, "f"))
				goto userr;
			irrad = atof(argv[i]);
			break;
		case 'm':				/* raw map output */
			rawmap = 1;
			break;
		case 'c':				/* color input */
			scanning = 0;
			break;
		default:
			goto userr;
		}
							/* open files */
	if (i < argc && freopen(argv[i], "r", stdin) == NULL) {
		perror(argv[i]);
		exit(1);
	}
	if (i+1 < argc && freopen(argv[i+1], "w", stdout) == NULL) {
		perror(argv[i+1]);
		exit(1);
	}
	if (scanning) {			/* load input picture header */
		SET_FILE_BINARY(stdin);
		if (checkheader(stdin, COLRFMT, NULL) < 0 ||
				fgetresolu(&xmax, &ymax, stdin) < 0) {
			fprintf(stderr, "%s: bad input picture\n", progname);
			exit(1);
		}
		if (scanning == 3) {
			if (i >= argc)
				goto userr;
			pickchartpos(argv[i]);
			scanning = 2;
		}
	} else {			/* else set default xmax and ymax */
		xmax = 512;
		ymax = 2*512/3;
	}
	if (scanning != 2) {		/* use default boundaries */
		bounds[0][0] = bounds[2][0] = .029*xmax + .5;
		bounds[0][1] = bounds[1][1] = .956*ymax + .5;
		bounds[1][0] = bounds[3][0] = .971*xmax + .5;
		bounds[2][1] = bounds[3][1] = .056*ymax + .5;
	}
	init();				/* initialize */
	if (scanning)			/* get picture colors */
		getpicture();
	else
		getcolors();
	compute();			/* compute color mapping */
	if (rawmap) {			/* print out raw correspondence */
		register int	j;

		printf("# Color correspondence produced by:\n#\t\t");
		printargs(argc, argv, stdout);
		printf("#\tUsage: pcwarp %s uncorrected.hdr > corrected.hdr\n",
				i+1 < argc ? argv[i+1] : "{this_file}");
		printf("#\t   Or: pcond [options] -m %s orig.hdr > output.hdr\n",
				i+1 < argc ? argv[i+1] : "{this_file}");
		for (j = 0; j < 24; j++)
			printf("%f %f %f    %f %f %f\n",
				colval(inpRGB[j],RED), colval(inpRGB[j],GRN),
				colval(inpRGB[j],BLU), colval(mbRGB[j],RED),
				colval(mbRGB[j],GRN), colval(mbRGB[j],BLU));
		if (scanning && debugfp != NULL)
			cwarp();		/* color warp for debugging */
	} else {			/* print color mapping */
						/* print header */
		printf("{\n\tColor correction file computed by:\n\t\t");
		printargs(argc, argv, stdout);
		printf("\n\tUsage: pcomb -f %s uncorrected.hdr > corrected.hdr\n",
				i+1 < argc ? argv[i+1] : "{this_file}");
		if (!scanning)
			printf("\t   Or: pcond [options] -f %s orig.hdr > output.hdr\n",
					i+1 < argc ? argv[i+1] : "{this_file}");
		printf("}\n");
		putmapping();			/* put out color mapping */
	}
	if (debugfp != NULL) {		/* put out debug picture */
		if (scanning)
			picdebug();
		else
			clrdebug();
	}
	exit(0);
userr:
	fprintf(stderr,
"Usage: %s [-d dbg.hdr][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.hdr [output.{cal|cwp}]\n",
			progname);
	fprintf(stderr, "   or: %s [-d dbg.hdr][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n",
			progname);
	exit(1);
	return 1; /* pro forma return */
}