Exemplo n.º 1
0
/*
 * Set/get the pixel value at position (x, y).
 *
 * Usage:
 * procname pixel x y [rgb]
 */
HIDDEN int
fbo_pixel_tcl(void *clientData, int argc, const char **argv)
{
    struct fb_obj *fbop = (struct fb_obj *)clientData;
    struct bu_vls vls = BU_VLS_INIT_ZERO;
    int x, y; 	/* pixel position */
    RGBpixel pixel;

    if (argc != 4 && argc != 5) {
	bu_log("ERROR: expecting five arguments\n");
	return BRLCAD_ERROR;
    }

    /* get pixel position */
    if (sscanf(argv[2], "%d", &x) != 1) {
	bu_log("fb_pixel: bad x value - %s", argv[2]);
	return BRLCAD_ERROR;
    }

    if (sscanf(argv[3], "%d", &y) != 1) {
	bu_log("fb_pixel: bad y value - %s", argv[3]);
	return BRLCAD_ERROR;
    }

    /* check pixel position */
    if (!fbo_coords_ok(fbop->fbo_fbs.fbs_fbp, x, y)) {
	bu_log("fb_pixel: coordinates (%s, %s) are invalid.", argv[2], argv[3]);
	return BRLCAD_ERROR;
    }

    /* get pixel value */
    if (argc == 4) {
	fb_rpixel(fbop->fbo_fbs.fbs_fbp, pixel);
	bu_vls_printf(&vls, "%d %d %d", pixel[RED], pixel[GRN], pixel[BLU]);
	Tcl_AppendResult(fbop->fbo_interp, bu_vls_addr(&vls), (char *)NULL);
	bu_vls_free(&vls);

	return BRLCAD_OK;
    }

    /*
     * Decompose the color list into its constituents.
     * For now must be in the form of rrr ggg bbb.
     */

    /* set pixel value */
    if (fbo_tcllist2color(argv[4], pixel) == BRLCAD_ERROR) {
	bu_log("fb_pixel: invalid color spec - %s", argv[4]);
	return BRLCAD_ERROR;
    }

    fb_write(fbop->fbo_fbs.fbs_fbp, x, y, pixel, 1);

    return BRLCAD_OK;
}
Exemplo n.º 2
0
/*
 * Set/get the pixel value at position (x, y).
 *
 * Usage:
 *	  procname pixel x y [rgb]
 */
HIDDEN int
fbo_pixel_tcl(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
    struct fb_obj *fbop = (struct fb_obj *)clientData;
    struct bu_vls vls;
    int x, y; 	/* pixel position */
    RGBpixel pixel;


    if (argc < 4)
	goto error;

    /* get pixel position */
    if (sscanf(argv[2], "%d", &x) != 1) {
	Tcl_AppendResult(interp, "fb_pixel: bad x value - ",
			 argv[2], (char *)NULL);
	return TCL_ERROR;
    }

    if (sscanf(argv[3], "%d", &y) != 1) {
	Tcl_AppendResult(interp, "fb_pixel: bad y value - ",
			 argv[3], (char *)NULL);
	return TCL_ERROR;
    }

    /* check pixel position */
    if (!fbo_coords_ok(interp, fbop->fbo_fbs.fbs_fbp, x, y)) {
	Tcl_AppendResult(interp,
			 "fb_pixel: coordinates (", argv[2], ", ", argv[3],
			 ") are invalid.", (char *)NULL);
	return TCL_ERROR;
    }

    /* get pixel value */
    if (argc == 4) {
	fb_rpixel(fbop->fbo_fbs.fbs_fbp, pixel);
	bu_vls_init(&vls);
	bu_vls_printf(&vls, "%d %d %d", pixel[RED], pixel[GRN], pixel[BLU]);
	Tcl_AppendResult(interp, bu_vls_addr(&vls), (char *)NULL);
	bu_vls_free(&vls);

	return TCL_OK;
    }

    /* set pixel value */
    if (argc == 5) {
	/*
	 * Decompose the color list into its constituents.
	 * For now must be in the form of rrr ggg bbb.
	 */

	if (fbo_tcllist2color(interp, argv[4], pixel) == TCL_ERROR) {
	    Tcl_AppendResult(interp, "fb_pixel: invalid color spec - ", argv[4], ".",
			     (char *)NULL);
	    return TCL_ERROR;
	}

	fb_write(fbop->fbo_fbs.fbs_fbp, x, y, pixel, 1);

	return TCL_OK;
    }

 error:
    bu_vls_init(&vls);
    bu_vls_printf(&vls, "helplib fb_pixel");
    Tcl_Eval(interp, bu_vls_addr(&vls));
    bu_vls_free(&vls);
    return TCL_ERROR;
}
Exemplo n.º 3
0
/*	d o _ c h a r ( )
	Outputs pixel representation of a chararcter by reading a row of a
	bitmap from the character font file.  The file pointer is assumed
	to be in the correct position.
*/
static void
do_char(int c, register int xpos, register int ypos)
{
    int     	up = font.dir[c].up / ir_aperture;
    int		left = font.dir[c].left / ir_aperture;
    static char	bitbuf[BUFFSIZ][BUFFSIZ];
    static RGBpixel	pixel;
    register int    h, i, j;
    int		k, x;
    for ( k = 0; k < font.height; k++ )
    {
	/* Read row, rounding width up to nearest byte value. */
	if ( fread( bitbuf[k], (size_t)font.width/8+(font.width % 8 == 0 ? 0 : 1), 1, font.ffdes )
	     != 1 )
	{
	    bu_log( "\"%s\" (%d) read of character from font failed.\n",
		    __FILE__, __LINE__
		);
	    return;
	}
    }
    for ( k = 0; k < font.height; k += ir_aperture, ypos-- )
    {
	x = xpos - left;
	for ( j = 0; j < font.width; j += ir_aperture, x++ )
	{
	    register int	sum;
	    fastf_t		weight;
	    /* The bitx routine extracts the bit value.
	       Can't just use the j-th bit because
	       the bytes are backwards. */
	    sum = 0;
	    for ( i = 0; i < ir_aperture; i++ )
		for ( h = 0; h < ir_aperture; h++ )
		    sum += bitx(	bitbuf[k+i],
					((j+h)&~7) + (7-((j+h)&7))
			) != 0;
	    weight = (fastf_t) sum / sample_sz;
	    if ( fb_seek( fbiop, x, ypos + up ) == -1 )
		continue;
	    if ( fb_rpixel( fbiop, (unsigned char *) pixel ) == -1 )
	    {
		bu_log( "\"%s\" (%d) read of pixel from <%d,%d> failed.\n",
			__FILE__, __LINE__, x, ypos
		    );
		return;
	    }
	    pixel[RED] = pixel[RED]*(1.0-weight) + FONTCOLOR_RED*weight;
	    pixel[GRN] = pixel[GRN]*(1.0-weight) + FONTCOLOR_GRN*weight;
	    pixel[BLU] = pixel[BLU]*(1.0-weight) + FONTCOLOR_BLU*weight;
	    if ( fb_seek( fbiop, x, ypos + up ) == -1 )
		continue;
	    if ( fb_wpixel( fbiop, (unsigned char *) pixel ) == -1 )
	    {
		bu_log( "\"%s\" (%d) write of pixel to <%d,%d> failed.\n",
			__FILE__, __LINE__, x, ypos
		    );
		return;
	    }
	}
    }
    return;
}