예제 #1
0
파일: fbcmrot.c 프로젝트: cciechad/brlcad
int
main(int argc, char **argv)
{
    register int i;
    struct timeval tv;

    if ( !get_args( argc, argv ) )  {
	(void)fputs(usage, stderr);
	bu_exit( 1, NULL );
    }

    if ( fps > 0.0 ) {
	tv.tv_sec = (long) (1.0 / fps);
	tv.tv_usec = (long) (((1.0 / fps) - tv.tv_sec) * 1000000);
    }

    if ( (fbp = fb_open( NULL, size, size)) == FBIO_NULL )  {
	fprintf(stderr, "fbcmrot:  fb_open failed\n");
	return	1;
    }

    local_inp = &cm1;
    local_outp = &cm2;
    fb_rmap( fbp, local_inp );

    while (1)  {
	register int from;
	ColorMap *tp;

	/* Build color map for current value */
	for ( i=0, from = increment; i < 256; i++, from++ ) {
	    if ( from < 0 )
		from += 256;
	    else if ( from > 255 )
		from -= 256;
	    local_outp->cm_red[i]   = local_inp->cm_red[from];
	    local_outp->cm_green[i] = local_inp->cm_green[from];
	    local_outp->cm_blue[i]  = local_inp->cm_blue[from];
	}

	fb_wmap( fbp, local_outp );
	tp = local_outp;
	local_outp = local_inp;
	local_inp = tp;

	if ( fps > 0.0 )  {
	    fd_set readfds;

	    FD_ZERO(&readfds);
	    FD_SET(fileno(stdin), &readfds);
	    select(fileno(stdin)+1, &readfds, (fd_set *)0, (fd_set *)0, &tv);
	}
	if ( onestep )
	    break;
    }
    fb_close( fbp );
    return	0;
}
int
main(int argc, char **argv)
{
    fb *fbp;
    FILE *fp;
    int fbsize = 512;
    int i;

    while (argc > 1) {
	if (BU_STR_EQUAL(argv[1], "-H")) {
	    fbsize = 1024;
	} else if (argv[1][0] == '-') {
	    if ( (!BU_STR_EQUAL(argv[1], "-?")) && (!BU_STR_EQUAL(argv[1], "-h")) )
		fprintf(stderr, "fb-cmap: unknown flag %s\n", argv[1]);
	    bu_exit(1, "%s", usage);
	} else
	    break;	/* must be a filename */
	argc--;
	argv++;
    }

    if (argc > 1) {
	if ((fp = fopen(argv[1], "wb")) == NULL) {
	    fprintf(stderr, "fb-cmap: can't open \"%s\"\n", argv[1]);
	    bu_exit(2, "%s", usage);
	}
    } else {
	fp = stdout;
	if (isatty(fileno(fp)))
	    fprintf(stderr, "%s       Program continues running:\n", usage);
    }

    if ((fbp = fb_open(NULL, fbsize, fbsize)) == FB_NULL)
	bu_exit(2, "Unable to open framebuffer\n");

    i = fb_rmap(fbp, &cm);
    fb_close(fbp);
    if (i < 0) {
	bu_exit(3, "fb-cmap: can't read colormap\n");
    }

    for (i = 0; i <= 255; i++) {
	fprintf(fp, "%d\t%04x %04x %04x\n", i,
		cm.cm_red[i], cm.cm_green[i], cm.cm_blue[i]);
    }

    return 0;
}
예제 #3
0
파일: fb-rle.c 프로젝트: kanzure/brlcad
int
main(int argc, char **argv)
{
    FBIO *fbp;
    unsigned char *scan_buf;
    int y;
    int cm_save_needed;

    outrle.rle_file = stdout;
    if (!get_args(argc, argv)) {
	(void)fputs(usage, stderr);
	bu_exit(1, NULL);
    }

    /* If screen size = default & file size is given, track file size */
    if (screen_width == 0 && file_width > 0)
	screen_width = file_width;
    if (screen_height == 0 && file_height > 0)
	screen_height = file_height;

    if ((fbp = fb_open(framebuffer, screen_width, screen_height)) == FBIO_NULL)
	bu_exit(12, NULL);

    /* Honor original screen size desires, if set, unless they shrank */
    if (screen_width == 0 || fb_getwidth(fbp) < screen_width)
	screen_width = fb_getwidth(fbp);
    if (screen_height == 0 || fb_getheight(fbp) < screen_height)
	screen_height = fb_getheight(fbp);

    /* If not specified, output file size tracks screen size */
    if (file_width == 0)
	file_width = screen_width;
    if (file_height == 0)
	file_height = screen_height;

    /* Clip below and to left of (0, 0) */
    if (screen_xoff < 0) {
	file_width += screen_xoff;
	screen_xoff = 0;
    }
    if (screen_yoff < 0) {
	file_height += screen_yoff;
	screen_yoff = 0;
    }

    /* Clip up and to the right */
    if (screen_xoff + file_width > screen_width)
	file_width = screen_width - screen_xoff;
    if (screen_yoff + file_height > screen_height)
	file_height = screen_height - screen_yoff;

    if (file_width <= 0 || file_height <= 0) {
	fprintf(stderr,
		"fb-rle: Error: image rectangle entirely off screen\n");
	bu_exit(1, NULL);
    }

    /* Read color map, see if it is linear */
    cm_save_needed = 1;
    if (fb_rmap(fbp, &cmap) == -1)
	cm_save_needed = 0;
    if (cm_save_needed && fb_is_linear_cmap(&cmap))
	cm_save_needed = 0;
    if (crunch && (cm_save_needed == 0))
	crunch = 0;

    /* Convert to Utah format */
    if (cm_save_needed) for (y=0; y<256; y++) {
	    rlemap[y+0*256] = cmap.cm_red[y];
	    rlemap[y+1*256] = cmap.cm_green[y];
	    rlemap[y+2*256] = cmap.cm_blue[y];
	}

    scan_buf = (unsigned char *)malloc(sizeof(RGBpixel) * screen_width);

    /* Build RLE header */
    outrle.ncolors = 3;
    RLE_SET_BIT(outrle, RLE_RED);
    RLE_SET_BIT(outrle, RLE_GREEN);
    RLE_SET_BIT(outrle, RLE_BLUE);
    outrle.background = 2;		/* use background */
    outrle.bg_color = background;
    outrle.alpha = 0;			/* no alpha channel */
    if (cm_save_needed && !crunch) {
	outrle.ncmap = 3;
	outrle.cmaplen = 8;		/* 1<<8 = 256 */
	outrle.cmap = rlemap;
    } else {
	outrle.ncmap = 0;		/* no color map */
	outrle.cmaplen = 0;
	outrle.cmap = (rle_map *)0;
    }
    outrle.xmin = screen_xoff;
    outrle.ymin = screen_yoff;
    outrle.xmax = screen_xoff + file_width - 1;
    outrle.ymax = screen_yoff + file_height - 1;
    outrle.comments = (const char **)0;

    /* Add comments to the header file, since we have one */
    if (framebuffer == (char *)0)
	framebuffer = fbp->if_name;
    snprintf(comment, COMMENT_SIZE, "encoded_from=%s", framebuffer);
    rle_putcom(bu_strdup(comment), &outrle);
    now = time(0);
    snprintf(comment, COMMENT_SIZE, "encoded_date=%24.24s", ctime(&now));
    rle_putcom(bu_strdup(comment), &outrle);
    if ((who = getenv("USER")) != (char *)0) {
	snprintf(comment, COMMENT_SIZE, "encoded_by=%s", who);
	rle_putcom(bu_strdup(comment), &outrle);
    }
# if HAVE_GETHOSTNAME
    gethostname(host, sizeof(host));
    snprintf(comment, COMMENT_SIZE, "encoded_host=%s", host);
    rle_putcom(bu_strdup(comment), &outrle);
# endif

    rle_put_setup(&outrle);
    rle_row_alloc(&outrle, &rows);

    /* Read the image a scanline at a time, and encode it */
    for (y = 0; y < file_height; y++) {
	if (fb_read(fbp, screen_xoff, y+screen_yoff, scan_buf,
		    file_width) == -1) {
	    (void) fprintf(stderr,
			   "fb-rle: read of %d pixels on line %d failed!\n",
			   file_width, y+screen_yoff);
	    bu_exit(1, NULL);
	}

	if (crunch)
	    cmap_crunch((RGBpixel *)scan_buf, file_width, &cmap);

	/* Grumble, convert to Utah layout */
	{
	    unsigned char *pp = (unsigned char *)scan_buf;
	    rle_pixel *rp = rows[0];
	    rle_pixel *gp = rows[1];
	    rle_pixel *bp = rows[2];
	    int i;

	    for (i=0; i<file_width; i++) {
		*rp++ = *pp++;
		*gp++ = *pp++;
		*bp++ = *pp++;
	    }
	}
	rle_putrow(rows, file_width, &outrle);
    }
    rle_puteof(&outrle);

    fb_close(fbp);
    fclose(outrle.rle_file);
    return 0;
}
예제 #4
0
파일: if_mem.c 프로젝트: kanzure/brlcad
HIDDEN int
mem_open(FBIO *ifp, const char *file, int width, int height)
{
    int mode;
    const char *cp;
    FBIO *fbp;
    char modebuf[80];
    char *mp;
    int alpha;
    struct modeflags *mfp;

    FB_CK_FBIO(ifp);

    /* This function doesn't look like it will work if file
     * is NULL - stop before we start, if that's the case.*/
    if (file == NULL) return -1;

    /*
     * First, attempt to determine operating mode for this open,
     * based upon the "unit number" or flags.
     * file = "/dev/mem###"
     * The default mode is zero.
     */
    mode = 0;

	if (bu_strncmp(file, "/dev/mem", 8)) {
	    /* How did this happen?? */
	    mode = 0;
	} else {
	    /* Parse the options */
	    alpha = 0;
	    mp = &modebuf[0];
	    cp = &file[8];
	    while (*cp != '\0' && !isspace((int)*cp)) {
		*mp++ = *cp;	/* copy it to buffer */
		if (isdigit((int)*cp)) {
		    cp++;
		    continue;
		}
		alpha++;
		for (mfp = modeflags; mfp->c != '\0'; mfp++) {
		    if (mfp->c == *cp) {
			mode = (mode&~mfp->mask)|mfp->value;
			break;
		    }
		}
		if (mfp->c == '\0' && *cp != '-') {
		    fb_log("if_mem: unknown option '%c' ignored\n", *cp);
		}
		cp++;
	    }
	    *mp = '\0';
	    if (!alpha)
		mode = atoi(modebuf);
	}

    /* build a local static info struct */
    if ((MIL(ifp) = (char *)calloc(1, sizeof(struct mem_info))) == NULL) {
	fb_log("mem_open:  mem_info malloc failed\n");
	return -1;
    }
    cp = &file[strlen("/dev/mem")];
    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
	cp++;	/* skip suffix */
    while (*cp != '\0' && (*cp == ' ' || *cp == '\t' || *cp == ';'))
	cp++;	/* skip blanks and separators */

    if (*cp) {
	/* frame buffer device specified */
	if ((fbp = fb_open(cp, width, height)) == FBIO_NULL) {
	    free(MIL(ifp));
	    return -1;
	}
	MI(ifp)->fbp = fbp;
	ifp->if_width = fbp->if_width;
	ifp->if_height = fbp->if_height;
	ifp->if_selfd = fbp->if_selfd;
	if ((mode & MODE_1MASK) == MODE_1IMMEDIATE)
	    MI(ifp)->write_thru = 1;
    } else {
	/* no frame buffer specified */
	if (width > 0)
	    ifp->if_width = width;
	if (height > 0)
	    ifp->if_height = height;
    }
    if ((MI(ifp)->mem = (unsigned char *)calloc(ifp->if_width*ifp->if_height, 3)) == NULL) {
	fb_log("mem_open:  memory buffer malloc failed\n");
	(void)free(MIL(ifp));
	return -1;
    }
    if ((MI(ifp)->fbp != FBIO_NULL)
	&& (mode & MODE_2MASK) == MODE_2PREREAD) {
	/* Pre read all of the image data and cmap */
	int got;
	got = fb_readrect(MI(ifp)->fbp, 0, 0,
			  ifp->if_width, ifp->if_height,
			  (unsigned char *)MI(ifp)->mem);
	if (got != ifp->if_width * ifp->if_height) {
	    fb_log("if_mem:  WARNING: pre-read of %d only got %d, your image is truncated.\n",
		   ifp->if_width * ifp->if_height, got);
	}
	if (fb_rmap(MI(ifp)->fbp, &(MI(ifp)->cmap)) < 0)
	    fb_make_linear_cmap(&(MI(ifp)->cmap));
    } else {
	/* Image data begins black, colormap linear */
	fb_make_linear_cmap(&(MI(ifp)->cmap));
    }

    return 0;
}
예제 #5
0
파일: fb-pix.c 프로젝트: cogitokat/brlcad
int
main(int argc, char **argv)
{
    FBIO *fbp;
    int y;

    unsigned char *scanline;	/* 1 scanline pixel buffer */
    int scanbytes;		/* # of bytes of scanline */
    int scanpix;		/* # of pixels of scanline */
    ColorMap cmap;		/* libfb color map */

    char usage[] = "\
Usage: fb-pix [-h -i -c] [-F framebuffer]\n\
	[-s squaresize] [-w width] [-n height] [file.pix]\n";

    screen_height = screen_width = 512;		/* Defaults */

    if (!get_args(argc, argv)) {
	(void)fputs(usage, stderr);
	bu_exit(1, NULL);
    }

#if defined(_WIN32) && !defined(__CYGWIN__)
    setmode(fileno(stdout), O_BINARY);
#endif

    scanpix = screen_width;
    scanbytes = scanpix * sizeof(RGBpixel);
    if ((scanline = (unsigned char *)malloc(scanbytes)) == RGBPIXEL_NULL) {
	fprintf(stderr,
		"fb-pix:  malloc(%d) failure\n", scanbytes);
	bu_exit(2, NULL);
    }

    if ((fbp = fb_open(framebuffer, screen_width, screen_height)) == NULL) {
	bu_exit(12, NULL);
    }

    if (screen_height > fb_getheight(fbp))
	screen_height = fb_getheight(fbp);
    if (screen_width > fb_getwidth(fbp))
	screen_width = fb_getwidth(fbp);

    if (crunch) {
	if (fb_rmap(fbp, &cmap) == -1) {
	    crunch = 0;
	} else if (fb_is_linear_cmap(&cmap)) {
	    crunch = 0;
	}
    }

    if (!inverse) {
	/* Regular -- read bottom to top */
	for (y=0; y < screen_height; y++) {
	    fb_read(fbp, 0, y, scanline, screen_width);
	    if (crunch)
		cmap_crunch((RGBpixel *)scanline, scanpix, &cmap);
	    if (fwrite((char *)scanline, scanbytes, 1, outfp) != 1) {
		perror("fwrite");
		break;
	    }
	}
    } else {
	/* Inverse -- read top to bottom */
	for (y = screen_height-1; y >= 0; y--) {
	    fb_read(fbp, 0, y, scanline, screen_width);
	    if (crunch)
		cmap_crunch((RGBpixel *)scanline, scanpix, &cmap);
	    if (fwrite((char *)scanline, scanbytes, 1, outfp) != 1) {
		perror("fwrite");
		break;
	    }
	}
    }
    fb_close(fbp);
    return 0;
}
예제 #6
0
파일: fbgamma.c 프로젝트: kanzure/brlcad
int
main(int argc, char **argv)
{
    int i;
    int onegamma = 0;
    int fbsize = 512;
    int overlay = 0;
    double gamr = 0, gamg = 0, gamb = 0;	/* gamma's */
    double f;
    ColorMap cm;
    FBIO *fbp;

    onegamma = 0;

    /* check for flags */
    bu_opterr = 0;
    while ((i=bu_getopt(argc, argv, options)) != -1) {
	switch (i) {
	    case 'H'	: fbsize = 1024; break;
	    case 'o'	: overlay++; break;
	    case 'i'	: image = !image; break;
	    case 'F'	: framebuffer = bu_optarg; break;
	    default	: bu_exit(1, "%s", usage);
	}
    }

    if (bu_optind == argc - 1) {
	/* single value for all channels */
	f = atof(argv[bu_optind]);
	checkgamma(f);
	gamr = gamg = gamb = 1.0 / f;
	onegamma++;
    } else if (bu_optind == argc - 4) {
	/* different RGB values */
	f = atof(argv[bu_optind]);
	checkgamma(f);
	gamr = 1.0 / f;
	f = atof(argv[bu_optind+1]);
	checkgamma(f);
	gamg = 1.0 / f;
	f = atof(argv[bu_optind+2]);
	checkgamma(f);
	gamb = 1.0 / f;
    } else {
	bu_exit(1, "%s", usage);
    }

    if ((fbp = fb_open(framebuffer, fbsize, fbsize)) == FBIO_NULL) {
	bu_exit(2, "Unable to open framebuffer\n");
    }

    /* draw the gamma image if requested */
    if (image) disp_image(fbp);

    /* get the starting map */
    if (overlay) {
	fb_rmap(fbp, &cm);
    } else {
	/* start with a linear map */
	for (i = 0; i < 256; i++) {
	    cm.cm_red[i] = cm.cm_green[i]
		= cm.cm_blue[i] = i << 8;
	}
    }

    /* apply the gamma(s) */
    for (i = 0; i < 256; i++) {
	if (gamr < 0)
	    cm.cm_red[i] = 65535 * pow((double)cm.cm_red[i] / 65535.0, -1.0/gamr);
	else
	    cm.cm_red[i] = 65535 * pow((double)cm.cm_red[i] / 65535.0, gamr);
	if (onegamma && (overlay == 0)) {
	    cm.cm_green[i] = cm.cm_red[i];
	    cm.cm_blue[i]  = cm.cm_red[i];
	} else {
	    if (gamg < 0)
		cm.cm_green[i] = 65535 * pow((double)cm.cm_green[i] / 65535.0, -1.0/gamg);
	    else
		cm.cm_green[i] = 65535 * pow((double)cm.cm_green[i] / 65535.0, gamg);
	    if (gamb < 0)
		cm.cm_blue[i]  = 65535 * pow((double)cm.cm_blue[i] / 65535.0, -1.0/gamb);
	    else
		cm.cm_blue[i]  = 65535 * pow((double)cm.cm_blue[i] / 65535.0, gamb);
	}
    }

    fb_wmap(fbp, &cm);
    fb_close(fbp);
    return 0;
}