/* * 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; }
/* * * Usage: * procname cell xmin ymin width height color */ HIDDEN int fbo_rect_tcl(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) { struct fb_obj *fbop = (struct fb_obj *)clientData; struct bu_vls vls; int xmin, ymin; int xmax, ymax; int width; int height; int i; RGBpixel pixel; if (argc != 7) { bu_vls_init(&vls); bu_vls_printf(&vls, "helplib fb_rect"); Tcl_Eval(interp, bu_vls_addr(&vls)); bu_vls_free(&vls); return TCL_ERROR; } if (sscanf(argv[2], "%d", &xmin) != 1) { Tcl_AppendResult(interp, "fb_rect: bad xmin value - ", argv[2], (char *)NULL); return TCL_ERROR; } if (sscanf(argv[3], "%d", &ymin) != 1) { Tcl_AppendResult(interp, "fb_rect: bad ymin value - ", argv[3], (char *)NULL); return TCL_ERROR; } /* check coordinates */ if (!fbo_coords_ok(interp, fbop->fbo_fbs.fbs_fbp, xmin, ymin)) { Tcl_AppendResult(interp, "fb_rect: coordinates (", argv[2], ", ", argv[3], ") are invalid.", (char *)NULL); return TCL_ERROR; } if (sscanf(argv[4], "%d", &width) != 1) { Tcl_AppendResult(interp, "fb_rect: bad width - ", argv[4], (char *)NULL); return TCL_ERROR; } if (sscanf(argv[5], "%d", &height) != 1) { Tcl_AppendResult(interp, "fb_rect: bad height - ", argv[5], (char *)NULL); return TCL_ERROR; } /* check width and height */ if (width <=0 || height <=0) { Tcl_AppendResult(interp, "fb_rect: width and height must be > 0", (char *)NULL); return TCL_ERROR; } /* * Decompose the color list into its constituents. * For now must be in the form of rrr ggg bbb. */ if (fbo_tcllist2color(interp, argv[6], pixel) == TCL_ERROR) { Tcl_AppendResult(interp, "fb_rect: invalid color spec: ", argv[6], ".", (char *)NULL); return TCL_ERROR; } xmax = xmin + width; ymax = ymin + height; /* draw horizontal lines */ for (i = xmin; i <= xmax; ++i) { /* working on bottom line */ fb_write(fbop->fbo_fbs.fbs_fbp, i, ymin, pixel, 1); /* working on top line */ fb_write(fbop->fbo_fbs.fbs_fbp, i, ymax, pixel, 1); } /* draw vertical lines */ for (i = ymin; i <= ymax; ++i) { /* working on left line */ fb_write(fbop->fbo_fbs.fbs_fbp, xmin, i, pixel, 1); /* working on right line */ fb_write(fbop->fbo_fbs.fbs_fbp, xmax, i, pixel, 1); } return TCL_OK; }
/* * * Usage: * procname cell xmin ymin width height color */ HIDDEN int fbo_cell_tcl(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) { struct fb_obj *fbop = (struct fb_obj *)clientData; struct bu_vls vls; int xmin, ymin; int width; int height; int i; RGBpixel pixel; unsigned char *pp; if (argc != 7) { bu_vls_init(&vls); bu_vls_printf(&vls, "helplib fb_cell"); Tcl_Eval(interp, bu_vls_addr(&vls)); bu_vls_free(&vls); return TCL_ERROR; } if (sscanf(argv[2], "%d", &xmin) != 1) { Tcl_AppendResult(interp, "fb_cell: bad xmin value - ", argv[2], (char *)NULL); return TCL_ERROR; } if (sscanf(argv[3], "%d", &ymin) != 1) { Tcl_AppendResult(interp, "fb_cell: bad ymin value - ", argv[3], (char *)NULL); return TCL_ERROR; } /* check coordinates */ if (!fbo_coords_ok(interp, fbop->fbo_fbs.fbs_fbp, xmin, ymin)) { Tcl_AppendResult(interp, "fb_cell: coordinates (", argv[2], ", ", argv[3], ") are invalid.", (char *)NULL); return TCL_ERROR; } if (sscanf(argv[4], "%d", &width) != 1) { Tcl_AppendResult(interp, "fb_cell: bad width - ", argv[4], (char *)NULL); return TCL_ERROR; } if (sscanf(argv[5], "%d", &height) != 1) { Tcl_AppendResult(interp, "fb_cell: bad height - ", argv[5], (char *)NULL); return TCL_ERROR; } /* check width and height */ if (width <=0 || height <=0) { Tcl_AppendResult(interp, "fb_cell: width and height must be > 0", (char *)NULL); return TCL_ERROR; } /* * Decompose the color list into its constituents. * For now must be in the form of rrr ggg bbb. */ if (fbo_tcllist2color(interp, argv[6], pixel) == TCL_ERROR) { Tcl_AppendResult(interp, "fb_cell: invalid color spec: ", argv[6], ".", (char *)NULL); return TCL_ERROR; } pp = (unsigned char *)calloc(width*height, sizeof(RGBpixel)); for (i = 0; i < width*height*sizeof(RGBpixel); i+=sizeof(RGBpixel)) { pp[i] = pixel[0]; pp[i+1] = pixel[1]; pp[i+2] = pixel[2]; } fb_writerect(fbop->fbo_fbs.fbs_fbp, xmin, ymin, width, height, pp); free((void *)pp); return TCL_OK; }
/* * 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; }
/* * * Usage: * procname cell xmin ymin width height color */ HIDDEN int fbo_rect_tcl(void *clientData, int argc, const char **argv) { struct fb_obj *fbop = (struct fb_obj *)clientData; int xmin, ymin; int xmax, ymax; int width; int height; int i; RGBpixel pixel; if (argc != 7) { bu_log("ERROR: expecting seven arguments\n"); return BRLCAD_ERROR; } if (sscanf(argv[2], "%d", &xmin) != 1) { bu_log("fb_rect: bad xmin value - %s", argv[2]); return BRLCAD_ERROR; } if (sscanf(argv[3], "%d", &ymin) != 1) { bu_log("fb_rect: bad ymin value - %s", argv[3]); return BRLCAD_ERROR; } /* check coordinates */ if (!fbo_coords_ok(fbop->fbo_fbs.fbs_fbp, xmin, ymin)) { bu_log("fb_rect: coordinates (%s, %s) are invalid.", argv[2], argv[3]); return BRLCAD_ERROR; } if (sscanf(argv[4], "%d", &width) != 1) { bu_log("fb_rect: bad width - %s", argv[4]); return BRLCAD_ERROR; } if (sscanf(argv[5], "%d", &height) != 1) { bu_log("fb_rect: bad height - %s", argv[5]); return BRLCAD_ERROR; } /* check width and height */ if (width <=0 || height <=0) { bu_log("fb_rect: width and height must be > 0"); return BRLCAD_ERROR; } /* * Decompose the color list into its constituents. * For now must be in the form of rrr ggg bbb. */ if (fbo_tcllist2color(argv[6], pixel) == BRLCAD_ERROR) { bu_log("fb_rect: invalid color spec: %s", argv[6]); return BRLCAD_ERROR; } xmax = xmin + width; ymax = ymin + height; /* draw horizontal lines */ for (i = xmin; i <= xmax; ++i) { /* working on bottom line */ fb_write(fbop->fbo_fbs.fbs_fbp, i, ymin, pixel, 1); /* working on top line */ fb_write(fbop->fbo_fbs.fbs_fbp, i, ymax, pixel, 1); } /* draw vertical lines */ for (i = ymin; i <= ymax; ++i) { /* working on left line */ fb_write(fbop->fbo_fbs.fbs_fbp, xmin, i, pixel, 1); /* working on right line */ fb_write(fbop->fbo_fbs.fbs_fbp, xmax, i, pixel, 1); } return BRLCAD_OK; }
/* * * Usage: * procname cell xmin ymin width height color */ HIDDEN int fbo_cell_tcl(void *clientData, int argc, const char **argv) { struct fb_obj *fbop = (struct fb_obj *)clientData; int xmin, ymin; long width; long height; size_t i; RGBpixel pixel; unsigned char *pp; if (argc != 7) { bu_log("ERROR: expecting seven arguments\n"); return BRLCAD_ERROR; } if (sscanf(argv[2], "%d", &xmin) != 1) { bu_log("fb_cell: bad xmin value - %s", argv[2]); return BRLCAD_ERROR; } if (sscanf(argv[3], "%d", &ymin) != 1) { bu_log("fb_cell: bad ymin value - %s", argv[3]); return BRLCAD_ERROR; } /* check coordinates */ if (!fbo_coords_ok(fbop->fbo_fbs.fbs_fbp, xmin, ymin)) { bu_log("fb_cell: coordinates (%s, %s) are invalid.", argv[2], argv[3]); return BRLCAD_ERROR; } if (sscanf(argv[4], "%ld", &width) != 1) { bu_log("fb_cell: bad width - %s", argv[4]); return BRLCAD_ERROR; } if (sscanf(argv[5], "%ld", &height) != 1) { bu_log("fb_cell: bad height - %s", argv[5]); return BRLCAD_ERROR; } /* check width and height */ if (width <=0 || height <=0) { bu_log("fb_cell: width and height must be > 0"); return BRLCAD_ERROR; } /* * Decompose the color list into its constituents. * For now must be in the form of rrr ggg bbb. */ if (fbo_tcllist2color(argv[6], pixel) == BRLCAD_ERROR) { bu_log("fb_cell: invalid color spec: %s", argv[6]); return BRLCAD_ERROR; } pp = (unsigned char *)bu_calloc(width*height, sizeof(RGBpixel), "allocate pixel array"); for (i = 0; i < width*height*sizeof(RGBpixel); i+=sizeof(RGBpixel)) { pp[i] = pixel[0]; pp[i+1] = pixel[1]; pp[i+2] = pixel[2]; } fb_writerect(fbop->fbo_fbs.fbs_fbp, xmin, ymin, width, height, pp); bu_free((void *)pp, "free pixel array"); return BRLCAD_OK; }