Example #1
0
File: lsc.c Project: wcheswick/ex
int
process_command(Point mouse) {
	button *bp = buttons;

	while (bp && (bp->state == Hidden || !ptinrect(mouse, bp->r)))
		bp = bp->next;
	if (!bp)
		return 0;

	if (bp == undo_button) {
		if (nhist > 0) {
			nhist--;
			show_hist();
		}
	} else if (bp == startover_button) {
		unfreeze();
		nhist = 0;
		show_hist();
	} else if (bp == freeze_button) {
		switch (state) {
		case Live:
			state = Frozen;
			freeze_button->state = On;
			paint_fancy_button(freeze_button);
			break;
		case Frozen:
			unfreeze();
			break;
		default:
			break;
		}
		flush_screen();
	} else if (bp == primary_buttons[Cat_change_color].b ||
	   bp == primary_buttons[Cat_change_look].b ||
	   bp == primary_buttons[Cat_change_shape].b) {
		set_category(bp);
	} else {
		if (bp && nhist < MAXHIST) {
			history[nhist++] = bp;
			show_hist();
		}
	}
	flush_screen();
	return 1;
}
Example #2
0
File: lsc.c Project: wcheswick/ex
/*
 * Draw the current screen.
 */
void
draw_screen(void) {
	button *bp = buttons;

	clear_screen_to_background();
	while (bp) {
		if (bp->state != Hidden  && bp->category == Cat_none) {
			paint_fancy_button(bp);
			flush_screen();
		}
		bp = bp->next;
	}

	set_category(current_primary_button);
	show_hist();
	write_video_frame_zoom(video_r.min, &frames[nhist], VIDEO_ZOOM);
	show_cursor();
	flush_screen();
}
Example #3
0
int
main(int argc, char **argv)
{
    int i, n;
    double d;
    long num_pixels;
    unsigned char *bp;
    long sum, partial_sum;
    int max, min, mode, median;
    double mean, var, skew;
    FILE *fp;

    if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?"))
	bu_exit(1, "%s", Usage);

    /* check for verbose flag */
    if (argc > 1 && BU_STR_EQUAL(argv[1], "-v")) {
	verbose++;
	argv++;
	argc--;
    }

    /* look for optional input file */
    if (argc > 1) {
	if ((fp = fopen(argv[1], "r")) == 0) {
	    bu_exit(1, "bwstat: can't open \"%s\"\n", argv[1]);
	}
	argv++;
	argc--;
    } else
	fp = stdin;

    /* check usage */
    if (argc > 1 || isatty(fileno(fp))) {
	bu_exit(1, "%s", Usage);
    }

    /*
     * Build the histogram.
     */
    num_pixels = 0;
    while ((n = fread(buf, sizeof(*buf), IBUFSIZE, fp)) > 0) {
	num_pixels += n;
	bp = &buf[0];
	for (i = 0; i < n; i++)
	    bin[ *bp++ ]++;
    }

    /*
     * Find sum, min, max, mode.
     */
    sum = 0;
    min = 256;
    max = -1;
    mode = 0;
    for (i = 0; i < 256; i++) {
	sum += i * bin[i];
	if (i < min && bin[i] != 0)
	    min = i;
	if (i > max && bin[i] != 0)
	    max = i;
	if (bin[i] > bin[mode]) {
	    mode = i;
	}
    }
    mean = (double)sum/(double)num_pixels;

    /*
     * Now do a second pass to compute median,
     * variance and skew.
     */
    partial_sum = 0;
    median = 0;
    var = skew = 0.0;
    for (i = 0; i < 256; i++) {
	if (partial_sum < sum/2.0) {
	    partial_sum += i * bin[i];
	    median = i;
	}
	d = (double)i - mean;
	var += bin[i] * d * d;
	skew += bin[i] * d * d * d;
    }
    var /= (double)num_pixels;
    skew /= (double)num_pixels;

    /*
     * Display the results.
     */
    printf("Pixels  %14ld (%.0f x %.0f)\n", num_pixels,
	   sqrt((double)num_pixels), sqrt((double)num_pixels));
    printf("Min     %14d\n", min);
    printf("Max     %14d\n", max);
    printf("Mode    %14d (%ld pixels)\n", mode, bin[mode]);
    printf("Median  %14d\n", median);
    printf("Mean    %14.3f\n", mean);
    printf("s.d.    %14.3f\n", sqrt(var));
    printf("Var     %14.3f\n", var);
    printf("Skew    %14.3f\n", skew);

    if (verbose)
	show_hist(bin, sum);

    return 0;
}