Example #1
0
int
main(int  argc, char  *argv[])
{
	int  i;
	double	d;
	
	progname = argv[0];

	for (i = 1; i < argc; i++)
		if (argv[i][0] == '-')
			switch (argv[i][1]) {
			case 'b':		/* produce b&w PostScript */
				docolor = 0;
				break;
			case 'c':		/* produce color PostScript */
				docolor = 1;
				break;
			case 'A':		/* standard ASCII encoding */
				putprim = Aputprim;
				break;
			case 'B':		/* standard binary encoding */
				putprim = Bputprim;
				break;
			case 'C':		/* compressed ASCII encoding */
				putprim = Cputprim;
				break;
			case 'd':		/* print density */
				dpi = atof(argv[++i]);
				break;
			case 'g':		/* device gamma adjustment */
				devgam = atof(argv[++i]);
				break;
			case 'p':		/* paper size */
				parsepaper(argv[++i]);
				break;
			case 'm':		/* margin */
				d = atof(argv[i+1]);
				d *= unit2inch(argv[i+1]);
				switch (argv[i][2]) {
				case '\0':
					hmarg = vmarg = d;
					break;
				case 'h':
					hmarg = d;
					break;
				case 'v':
					vmarg = d;
					break;
				default:
					goto userr;
				}
				i++;
				break;
			case 'e':		/* exposure adjustment */
				if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
					goto userr;
				bradj = atoi(argv[++i]);
				break;
			case 'n':		/* number of copies */
				ncopies = atoi(argv[++i]);
				break;
			default:
				goto userr;
			}
		else
			break;

	if (i < argc-2)
		goto userr;
	if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
		fprintf(stderr, "%s: can't open input \"%s\"\n",
				progname, argv[i]);
		exit(1);
	}
	if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
		fprintf(stderr, "%s: can't open output \"%s\"\n",
				progname, argv[i+1]);
		exit(1);
	}
	SET_FILE_BINARY(stdin);
				/* get our header */
	getheader(stdin, headline, NULL);
	if (wrongformat || fgetresolu(&xmax, &ymax, stdin) < 0)
		quiterr("bad picture format");
				/* gamma compression */
	if (devgam <= 0.05)
		devgam = docolor ? DEFCGAM : DEFGGAM;
	if (putprim == Cputprim)
		setcolrgam(CODE6GAM);
	else if (devgam != 1.)
		setcolrgam(devgam);
				/* write header */
	PSheader(argc, argv);
				/* convert file */
	ra2ps();
				/* write trailer */
	PStrailer();
	exit(0);
userr:
	fprintf(stderr,
"Usage: %s [-b|c][-A|B|C][-e +/-stops][-p paper][-m[h|v] margin][-d dpi][-g gamma] [input [output]]\n",
			progname);
	exit(1);
}
Example #2
0
int
main(int  argc, char  *argv[])
{
	int  bitsperpix;
	int  i;
	SET_DEFAULT_BINARY();
	SET_FILE_BINARY(stdin);
	SET_FILE_BINARY(stdout);
	progname = argv[0];
	samplefac = 0;

	for (i = 1; i < argc; i++)
		if (argv[i][0] == '-')
			switch (argv[i][1]) {
			case 'g':
				gamv = atof(argv[++i]);
				break;
			case 'b':
				greyscale = 1;
				break;
			case 'd':
				dither = !dither;
				break;
			case 'c':
				ncolors = atoi(argv[++i]);
				break;
			case 'e':
				if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
					goto userr;
				bradj = atoi(argv[++i]);
				break;
			case 'n':
				samplefac = atoi(argv[++i]);
				break;
			default:
				goto userr;
			}
		else
			break;

	if (i < argc-2)
		goto userr;
	if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
		fprintf(stderr, "%s: cannot open input \"%s\"\n",
				progname, argv[i]);
		exit(1);
	}
	if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
		fprintf(stderr, "%s: cannot open output \"%s\"\n",
				progname, argv[i+1]);
		exit(1);
	}
	if (checkheader(stdin, COLRFMT, NULL) < 0 ||
			fgetresolu(&xmax, &ymax, stdin) < 0) {
		fprintf(stderr, "%s: bad picture format\n", progname);
		exit(1);
	}
	picstart = ftell(stdin);
	currow = -1;
	scanln = (COLR *)malloc(xmax*sizeof(COLR));
	if (scanln == NULL) {
		fprintf(stderr, "%s: out of memory\n", progname);
		exit(1);
	}
				/* set up gamma correction */
	setcolrgam(gamv);
				/* figure out the bits per pixel */
	if ((ncolors < 2) | (ncolors > MAXCOLORS))
		ncolors = MAXCOLORS;
	for (bitsperpix = 1; ncolors > 1<<bitsperpix; bitsperpix++)
		;
				/* compute color map */
	if (greyscale)
		mkgrymap(ncolors);
	else
		mkclrmap(ncolors);
				/* convert image */
	GIFEncode(stdout, xmax, ymax, 0, 0, bitsperpix,
			rmap, gmap, bmap, getgifpix);
	exit(0);
userr:
	fprintf(stderr,
	"Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n",
			progname);
	exit(1);
}
Example #3
0
int
main(
	int  argc,
	char  *argv[]
)
{
	char  inpbuf[2];
	int  gryflag = 0;
	int  binflag = 1;
	int  reverse = 0;
	int  ptype;
	int  i;
	
	progname = argv[0];

	for (i = 1; i < argc; i++)
		if (argv[i][0] == '-')
			switch (argv[i][1]) {
			case 's':
				maxval = atoi(argv[++i]) & 0xffff;
				break;
			case 'b':
				gryflag = 1;
				break;
			case 'g':
				gamcor = atof(argv[++i]);
				break;
			case 'e':
				if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
					goto userr;
				bradj = atoi(argv[++i]);
				break;
			case 'a':
				binflag = 0;
				break;
			case 'r':
				reverse = !reverse;
				break;
			default:
				goto userr;
			}
		else
			break;

	if (i < argc-2)
		goto userr;
	if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
		fprintf(stderr, "%s: can't open input \"%s\"\n",
				progname, argv[i]);
		exit(1);
	}
	if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
		fprintf(stderr, "%s: can't open output \"%s\"\n",
				progname, argv[i+1]);
		exit(1);
	}
	if (maxval < 256)
		setcolrgam(gamcor);
	if (reverse) {
					/* get header */
		if (read(fileno(stdin), inpbuf, 2) != 2 || inpbuf[0] != 'P')
			quiterr("input not a Poskanzer Pixmap");
		ptype = inpbuf[1];
#ifdef _WIN32
		if (ptype > 4)
			SET_FILE_BINARY(stdin);
		SET_FILE_BINARY(stdout);
#endif
		xmax = scanint(stdin);
		ymax = scanint(stdin);
		maxval = scanint(stdin);
					/* put header */
		newheader("RADIANCE", stdout);
		printargs(i, argv, stdout);
		fputformat(COLRFMT, stdout);
		putchar('\n');
		fprtresolu(xmax, ymax, stdout);
					/* convert file */
		if (maxval >= 256)
			switch (ptype) {
			case '2':
				ppm2ra2(agryscan2);
				break;
			case '5':
				ppm2ra2(bgryscan2);
				break;
			case '3':
				ppm2ra2(aclrscan2);
				break;
			case '6':
				ppm2ra2(bclrscan2);
				break;
			default:
				quiterr("unsupported Pixmap type");
			}
		else
			switch (ptype) {
			case '2':
				ppm2ra(agryscan);
				break;
			case '5':
				ppm2ra(bgryscan);
				break;
			case '3':
				ppm2ra(aclrscan);
				break;
			case '6':
				ppm2ra(bclrscan);
				break;
			default:
				quiterr("unsupported Pixmap type");
			}
	} else {
#ifdef _WIN32
		SET_FILE_BINARY(stdin);
		if (binflag)
			SET_FILE_BINARY(stdout);
#endif
					/* get header info. */
		if (checkheader(stdin, COLRFMT, NULL) < 0 ||
				fgetresolu(&xmax, &ymax, stdin) < 0)
			quiterr("bad picture format");
					/* write PPM header */
		printf("P%1d\n%d %d\n%u\n", (gryflag?2:3)+(binflag?3:0),
				xmax, ymax, maxval);
					/* convert file */
		if (maxval >= 256)
			ra2ppm2(binflag, gryflag);
		else
			ra2ppm(binflag, gryflag);
	}
	exit(0);
userr:
	fprintf(stderr,
		"Usage: %s [-r][-a][-b][-s maxv][-g gamma][-e +/-stops] [input [output]]\n",
			progname);
	exit(1);
}