示例#1
0
/*
 * R T _ T A B L E _ M A K E _ V I S I B L E _ A N D _ U N I F O R M
 *
 * A quick hack to make sure there are enough samples in the visible band.
 */
struct bn_table *
bn_table_make_visible_and_uniform(int num, double first, double last, int vis_nsamp)
{
    struct bn_table *newtab;
    struct bn_table *uniform;
    struct bn_table *vis;

    if (vis_nsamp < 10) vis_nsamp = 10;
    uniform = bn_table_make_uniform(num, first, last);
    vis = bn_table_make_uniform(vis_nsamp, 340.0, 700.0);

    newtab = bn_table_merge2(uniform, vis);
    bn_ck_table(newtab);

    bn_table_free(uniform);
    bn_table_free(vis);

    return newtab;
}
示例#2
0
int
main(int ac, char **av)
{
    unsigned char rgb[4];
    float src[3];
    point_t dest;
    point_t xyz;
    size_t ret;

    if (ac > 1)
	bu_log("Usage: %s\n", av[0]);

    spectrum = bn_table_make_uniform(nsamp, min_nm, max_nm);
    BN_GET_TABDATA(curve, spectrum);

    rt_spect_make_CIE_XYZ(&cie_x, &cie_y, &cie_z, spectrum);
    make_ntsc_xyz2rgb(xyz2rgb);

    for (;;) {
	if (fread(rgb, 1, 3, stdin) != 3) break;
	if (feof(stdin)) break;

	VSET(src, rgb[0]/255., rgb[1]/255., rgb[2]/255.);

	rt_spect_reflectance_rgb(curve, src);

	spect_curve_to_xyz(xyz, curve, cie_x, cie_y, cie_z);

	MAT3X3VEC(dest, xyz2rgb, xyz);

	if (dest[0] > 1 || dest[1] > 1 || dest[2] > 1 ||
	    dest[0] < 0 || dest[1] < 0 || dest[2] < 0) {
	    VPRINT("src ", src);
	    VPRINT("dest", dest);
	}

	if (dest[0] > 1) dest[0] = 1;
	if (dest[1] > 1) dest[1] = 1;
	if (dest[2] > 1) dest[2] = 1;
	if (dest[0] < 0) dest[0] = 0;
	if (dest[1] < 0) dest[1] = 0;
	if (dest[2] < 0) dest[2] = 0;

	VSCALE(rgb, dest, 255.0);

	ret = fwrite(rgb, 1, 3, stdout);
	if (ret != 3)
	    perror("fwrite");
    }

    return 0;
}
示例#3
0
static int
test_bn_table_make_uniform(int argc, char *argv[])
{
    struct bn_table *expected;
    struct bn_table *actual;
    double first, last;
    unsigned int num;

    if (argc != 6) {
	bu_exit(1, "<args> format: first last num expected [%s]\n", argv[0]);
    }

    sscanf(argv[2], "%lf", &first);
    sscanf(argv[3], "%lf", &last);
    sscanf(argv[4], "%u", &num);
    scan_tab_args(argv[5], &expected);

    actual = bn_table_make_uniform(num, first, last);

    bn_pr_table("Result", actual);

    return !tab_equal(expected, actual);
}