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; }
/* * D O _ F B */ void do_fb(void) { FBIO *fbp; if ( (fbp = fb_open( framebuffer, 0, 0 )) == FBIO_NULL ) { bu_exit( 2, "Unable to open framebuffer\n" ); } if ( fb_wmap( fbp, &map ) < 0 ) fprintf( stderr, "fbgammamod: unable to write color map\n"); fb_close(fbp); }
HIDDEN int mem_wmap(FBIO *ifp, const ColorMap *cmp) { if (cmp == COLORMAP_NULL) { fb_make_linear_cmap(&(MI(ifp)->cmap)); } else { MI(ifp)->cmap = *cmp; /* struct copy */ } if (MI(ifp)->write_thru) { return fb_wmap(MI(ifp)->fbp, cmp); } else { MI(ifp)->cmap_dirty = 1; } return 0; }
/* f b _ S e t u p ( ) */ int fb_Setup(char *file, int size) { if ( BU_STR_EQUAL( file, "/dev/remote" ) ) file = "/dev/debug"; prnt_Event( "Opening device..." ); if (((fbiop = fb_open(file[0] == '\0' ? NULL : file, size, size)) == FBIO_NULL) || (fb_ioinit( fbiop ) == -1) || (fb_wmap( fbiop, COLORMAP_NULL ) == -1)) return 0; (void) fb_setcursor( fbiop, arrowcursor, 16, 16, 0, 0 ); (void) fb_cursor( fbiop, 1, size/2, size/2 ); prnt_Event( (char *) NULL ); return 1; }
HIDDEN int mem_close(FBIO *ifp) { /* * Flush memory/cmap to attached frame buffer if any */ if (MI(ifp)->fbp != FBIO_NULL) { if (MI(ifp)->cmap_dirty) { fb_wmap(MI(ifp)->fbp, &(MI(ifp)->cmap)); } if (MI(ifp)->mem_dirty) { fb_writerect(MI(ifp)->fbp, 0, 0, ifp->if_width, ifp->if_height, (unsigned char *)MI(ifp)->mem); } fb_close(MI(ifp)->fbp); MI(ifp)->fbp = FBIO_NULL; } (void)free((char *)MI(ifp)->mem); (void)free((char *)MIL(ifp)); return 0; }
HIDDEN int mem_flush(FBIO *ifp) { /* * Flush memory/cmap to attached frame buffer if any */ if (MI(ifp)->fbp != FBIO_NULL) { if (MI(ifp)->cmap_dirty) { fb_wmap(MI(ifp)->fbp, &(MI(ifp)->cmap)); MI(ifp)->cmap_dirty = 0; } if (MI(ifp)->mem_dirty) { fb_writerect(MI(ifp)->fbp, 0, 0, ifp->if_width, ifp->if_height, (unsigned char *)MI(ifp)->mem); MI(ifp)->mem_dirty = 0; } return fb_flush(MI(ifp)->fbp); } MI(ifp)->cmap_dirty = 0; MI(ifp)->mem_dirty = 0; return 0; /* success */ }
static bool_t display_Cells(long int ncells) { Cell *gp, *ep = &grid[ncells]; static int zoom; unsigned char *buf; static RGBpixel pixel; double lasty = -INFINITY; double dx, dy; int y_0 = 0, y_1; if (compute_fb_height) { dy = ((ymax - ymin) / cell_size + 1.0) * (hgt + grid_flag); if (compute_fb_height == SNUG_FIT) fb_height = dy + (key_flag * 2 * hgt) + yorigin; else if (dy > LORES) /* LOOSE_FIT */ fb_height = HIRES; else fb_height = LORES; } if (compute_fb_width) { dx = ((xmax - xmin) / cell_size + 1.0) * (wid + grid_flag); if (compute_fb_width == SNUG_FIT) fb_width = dx + xorigin; else if (dx > LORES) /* LOOSE_FIT */ fb_width = HIRES; else fb_width = LORES; } zoom = 1; fbiop = fb_open((fbfile[0] != '\0') ? fbfile : NULL, fb_width, fb_height); if (fbiop == FB_NULL) return 0; if (compute_fb_height || compute_fb_width) { bu_log("fb_size requested: %d %d\n", fb_width, fb_height); fb_width = fb_getwidth(fbiop); fb_height = fb_getheight(fbiop); bu_log("fb_size obtained: %d %d\n", fb_width, fb_height); } if (fb_wmap(fbiop, COLORMAP_NULL) == -1) bu_log("Cannot initialize color map\n"); if (fb_zoom(fbiop, zoom, zoom) == -1) bu_log("Cannot set zoom <%d, %d>\n", zoom, zoom); if (erase_flag && fb_clear(fbiop, BACKGROUND) == -1) bu_log("Cannot clear frame buffer\n"); buf = (unsigned char *) bu_malloc(sizeof(RGBpixel) * fb_width, "line of frame buffer"); if (debug_flag & CFB_DBG_MEM) bu_log("buf = %p... %d pixels @ %lu bytes/pixel\n", (void *)buf, fb_width, sizeof(RGBpixel)); for (gp = grid; gp < ep; gp++) { int x0, x1; /* Whenever Y changes, write out row of cells. */ if (!ZERO(lasty - gp->c_y)) { /* If first time, nothing to write out. */ if (!ZERO(lasty - INFINITY)) { if (debug_flag & CFB_DBG_GRID) bu_log("%g = V2SCRY(%g)\n", V2SCRY(lasty), lasty); y_0 = V2SCRY(lasty); if (y_0 >= 0 && y_0 < fb_height) { for (y_1 = y_0 + hgt; y_0 < y_1; y_0++) if (fb_write(fbiop, 0, y_0, buf, fb_width) == -1) { bu_log("Couldn't write to <%d, %d>\n", 0, y_0); (void) fb_close(fbiop); return 0; } } } /* Clear buffer. */ for (x0 = 0; x0 < fb_width; x0++) { COPYRGB(&buf[3*x0], BACKGROUND); } /* Draw grid line between rows of cells. */ if (grid_flag && !ZERO(lasty - INFINITY)) { if (fb_write(fbiop, 0, y_0, buf, fb_width) == -1) { bu_log("Couldn't write to <%d, %d>\n", 0, y_0); (void) fb_close(fbiop); return 0; } if (debug_flag & CFB_DBG_GRID) bu_log("Writing grid row at %d\n", y_0); } lasty = gp->c_y; } val_To_RGB(gp->c_val, pixel); /* Be careful only to write color within bounds of the screen */ x0 = H2SCRX(gp->c_x); if (x0 >= 0 && x0 <= fb_width - wid) { for (x1 = x0 + wid; x0 < x1; x0++) { COPYRGB(&buf[3*x0], pixel); } } } /* Write out last row of cells. */ if (debug_flag & CFB_DBG_GRID) bu_log("%g = V2SCRY(%g)\n", V2SCRY(lasty), lasty); for (y_0 = V2SCRY(lasty), y_1 = y_0 + hgt; y_0 < y_1; y_0++) if (fb_write(fbiop, 0, y_0, buf, fb_width) == -1) { bu_log("Couldn't write to <%d, %d>\n", 0, y_0); (void) fb_close(fbiop); return 0; } /* Draw color key. */ if (key_flag && (fb_width < (10 + 1) * wid)) bu_log("Width of key (%d) would exceed frame-buffer width (%d)\n", (10 + 1) * wid, fb_width); else if (key_flag) { int i, j; double base; int scr_min, scr_max; int scr_center; /* screen coord of center of view */ int center_cell; /* cell # of center of view */ /* Clear buffer. */ for (i = 0; i < fb_width; i++) { COPYRGB(&buf[3*i], BACKGROUND); } /* Center the color key from side-to-side in the viewport. * Find screen coords of min and max vals, clip to (0, fb_width). * If there are fewer than 11 cells, the run the key * from the left edge to beyond the right edge. */ scr_min = H2SCRX(xmin); scr_max = H2SCRX(xmax); CLAMP(scr_min, 0, fb_width); CLAMP(scr_max, 0, fb_width); scr_center = (scr_max + scr_min)/2; if ((center_cell = VPX2CX(SCRX2VPX(scr_center))) < 5) center_cell = 5; /* Draw 10 cells for the color key */ dom_cvt = 10.0; for (i = 0; i <= 10; i++) { cell_val cv; /* * Determine where to start the key, * being careful not to back up beyond the beginning of buf. */ base = VPX2SCRX(CX2VPX(center_cell - 10/2 + i)); cv.v_scalar = i / 10.0; val_To_RGB(cv, pixel); for (j = 0; j < wid; j++) { int idx = base + j; COPYRGB(&buf[3*idx], pixel); } } dom_cvt = 10.0 / (dom_max - dom_min); for (i = yorigin; i < yorigin+hgt; i++) if (fb_write(fbiop, 0, i, buf, fb_width) == -1) { bu_log("Couldn't write to <%d, %d>\n", 0, i); (void) fb_close(fbiop); return 0; } } (void) fb_close(fbiop); bu_free((char *) buf, "line of frame buffer"); if (debug_flag & CFB_DBG_MEM) bu_log("freed buf, which is now %p\n", (void *)buf); return 1; }
int main(int argc, char **argv) { FBIO *fbp; int i; int file_width; /* unclipped width of rectangle */ int file_skiplen; /* # of pixels to skip on l.h.s. */ int screen_xbase; /* screen X of l.h.s. of rectangle */ int screen_xlen; /* clipped len of rectangle */ int ncolors; infp = stdin; if (!get_args(argc, argv)) { (void)fputs(usage, stderr); bu_exit(1, NULL); } rle_dflt_hdr.rle_file = infp; if (rle_get_setup(&rle_dflt_hdr) < 0) { fprintf(stderr, "rle-fb: Error reading setup information\n"); bu_exit(1, NULL); } if (r_debug) { fprintf(stderr, "Image bounds\n\tmin %d %d\n\tmax %d %d\n", rle_dflt_hdr.xmin, rle_dflt_hdr.ymin, rle_dflt_hdr.xmax, rle_dflt_hdr.ymax); fprintf(stderr, "%d color channels\n", rle_dflt_hdr.ncolors); fprintf(stderr, "%d color map channels\n", rle_dflt_hdr.ncmap); if (rle_dflt_hdr.alpha) fprintf(stderr, "Alpha Channel present in input, ignored.\n"); for (i=0; i < rle_dflt_hdr.ncolors; i++) fprintf(stderr, "Background channel %d = %d\n", i, rle_dflt_hdr.bg_color[i]); rle_debug(1); } if (rle_dflt_hdr.ncmap == 0) crunch = 0; /* Only interested in R, G, & B */ RLE_CLR_BIT(rle_dflt_hdr, RLE_ALPHA); for (i = 3; i < rle_dflt_hdr.ncolors; i++) RLE_CLR_BIT(rle_dflt_hdr, i); ncolors = rle_dflt_hdr.ncolors > 3 ? 3 : rle_dflt_hdr.ncolors; /* Optional switch of library to overlay mode */ if (overlay) { rle_dflt_hdr.background = 1; /* overlay */ override_background = 0; } /* Optional background color override */ if (override_background) { for (i=0; i<ncolors; i++) rle_dflt_hdr.bg_color[i] = background[i]; } file_width = rle_dflt_hdr.xmax - rle_dflt_hdr.xmin + 1; /* If screen sizes not specified, try to display rectangle part > 0 */ if (screen_width == 0) { screen_width = rle_dflt_hdr.xmax + 1; if (scr_xoff > 0) screen_width += scr_xoff; } if (screen_height == 0) { screen_height = rle_dflt_hdr.ymax + 1; if (scr_yoff > 0) screen_height += scr_yoff; } /* Incorporate command-line rectangle repositioning */ rle_dflt_hdr.xmin += scr_xoff; rle_dflt_hdr.xmax += scr_xoff; rle_dflt_hdr.ymin += scr_yoff; /* Pretend saved image origin is at 0, clip & position in fb_write call */ screen_xbase = rle_dflt_hdr.xmin; rle_dflt_hdr.xmax -= screen_xbase; rle_dflt_hdr.xmin = 0; 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); /* Discard any scanlines which exceed screen height */ if (rle_dflt_hdr.ymax > screen_height-1) rle_dflt_hdr.ymax = screen_height-1; /* Clip left edge */ screen_xlen = rle_dflt_hdr.xmax + 1; file_skiplen = 0; if (screen_xbase < 0) { file_skiplen = -screen_xbase; screen_xbase = 0; screen_xlen -= file_skiplen; } /* Clip right edge */ if (screen_xbase + screen_xlen > screen_width) screen_xlen = screen_width - screen_xbase; if (screen_xlen <= 0 || rle_dflt_hdr.ymin > screen_height || rle_dflt_hdr.ymax < 0) { fprintf(stderr, "rle-fb: Warning: RLE image rectangle entirely off screen\n"); goto done; } scan_buf = (unsigned char *)malloc(sizeof(RGBpixel) * screen_width); for (i=0; i < ncolors; i++) rows[i] = (unsigned char *)malloc((size_t)file_width); for (; i < 3; i++) rows[i] = rows[0]; /* handle monochrome images */ /* * Import Utah color map, converting to libfb format. * Check for old format color maps, where high 8 bits * were zero, and correct them. * XXX need to handle < 3 channels of color map, by replication. */ if (rle_dflt_hdr.ncmap > 0) { int maplen = (1 << rle_dflt_hdr.cmaplen); int all = 0; for (i=0; i<256; i++) { cmap.cm_red[i] = rle_dflt_hdr.cmap[i]; cmap.cm_green[i] = rle_dflt_hdr.cmap[i+maplen]; cmap.cm_blue[i] = rle_dflt_hdr.cmap[i+2*maplen]; all |= cmap.cm_red[i] | cmap.cm_green[i] | cmap.cm_blue[i]; } if ((all & 0xFF00) == 0 && (all & 0x00FF) != 0) { /* This is an old (Edition 2) color map. * Correct by shifting it left 8 bits. */ for (i=0; i<256; i++) { cmap.cm_red[i] <<= 8; cmap.cm_green[i] <<= 8; cmap.cm_blue[i] <<= 8; } fprintf(stderr, "rle-fb: correcting for old style colormap\n"); } } if (rle_dflt_hdr.ncmap > 0 && !crunch) (void)fb_wmap(fbp, &cmap); else (void)fb_wmap(fbp, COLORMAP_NULL); /* Handle any lines below zero in y. Decode and discard. */ for (i = rle_dflt_hdr.ymin; i < 0; i++) rle_getrow(&rle_dflt_hdr, rows); for (; i <= rle_dflt_hdr.ymax; i++) { unsigned char *pp = (unsigned char *)scan_buf; rle_pixel *rp = &(rows[0][file_skiplen]); rle_pixel *gp = &(rows[1][file_skiplen]); rle_pixel *bp = &(rows[2][file_skiplen]); int j; if (overlay) { fb_read(fbp, screen_xbase, i, scan_buf, screen_xlen); for (j = 0; j < screen_xlen; j++) { *rp++ = *pp++; *gp++ = *pp++; *bp++ = *pp++; } pp = (unsigned char *)scan_buf; rp = &(rows[0][file_skiplen]); gp = &(rows[1][file_skiplen]); bp = &(rows[2][file_skiplen]); } rle_getrow(&rle_dflt_hdr, rows); /* Grumble, convert from Utah layout */ if (!crunch) { for (j = 0; j < screen_xlen; j++) { *pp++ = *rp++; *pp++ = *gp++; *pp++ = *bp++; } } else { for (j = 0; j < screen_xlen; j++) { *pp++ = cmap.cm_red[*rp++]>>8; *pp++ = cmap.cm_green[*gp++]>>8; *pp++ = cmap.cm_blue[*bp++]>>8; } } if (fb_write(fbp, screen_xbase, i, scan_buf, screen_xlen) != screen_xlen) break; } done: fb_close(fbp); return 0; }
int main(int argc, char **argv) { int i; int fudge; ColorMap cmap; ColorMap *cp = &cmap; FBIO *fbp; if (! pars_Argv(argc, argv)) { usage(); return 1; } if ((fbp = fb_open(framebuffer, scr_width, scr_height)) == NULL) return 1; switch (flavor) { case 0 : /* Standard - Linear color map */ (void) fprintf(stderr, "Color map #0, linear (standard).\n"); cp = (ColorMap *) NULL; break; case 1 : /* Reverse linear color map */ (void) fprintf(stderr, "Color map #1, reverse-linear (negative).\n"); for (i = 0; i < 256; i++) { cp->cm_red[255-i] = cp->cm_green[255-i] = cp->cm_blue[255-i] = i << 8; } break; case 2 : /* Experimental correction, for POLAROID 8x10 print film */ (void) fprintf(stderr, "Color map #2, corrected for POLAROID 809/891 film.\n"); /* First entry black */ #define BOOST(point, bias) \ ((int)((bias)+((float)(point)/256.*(255-(bias))))) for (i = 1; i < 256; i++) { fudge = BOOST(i, 70); cp->cm_red[i] = fudge << 8; /* B */ } for (i = 1; i < 256; i++) { fudge = i; cp->cm_green[i] = fudge << 8; /* G */ } for (i = 1; i < 256; i++) { fudge = BOOST(i, 30); cp->cm_blue[i] = fudge << 8; /* R */ } break; case 3 : /* Standard, with low intensities set to black */ (void) fprintf(stderr, "Color map #3, low 100 entries black.\n"); for (i = 100; i < 256; i++) { cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = i << 8; } break; case 4 : /* Amplify middle of the range, for Moss's dim pictures */ #define UPSHIFT 64 (void) fprintf(stderr, "Color map #4, amplify middle range to boost dim pictures.\n"); /* First entry black */ for (i = 1; i< 256-UPSHIFT; i++) { int j = i + UPSHIFT; cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = j << 8; } for (i = 256-UPSHIFT; i < 256; i++) { cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = 255 << 8; /* Full Scale */ } break; case 5 : /* University of Utah's color map */ (void) fprintf(stderr, "Color map #5, University of Utah's gamma correcting map.\n"); for (i = 0; i < 256; i++) cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = utah_cmap[i] << 8; break; case 6 : /* Delta's */ (void) fprintf(stderr, "Color map #6, color deltas.\n"); /* white at zero */ cp->cm_red[0] = 65535; cp->cm_green[0] = 65535; cp->cm_blue[0] = 65535; /* magenta at 32 */ cp->cm_red[32] = 65535; cp->cm_blue[32] = 65535; /* Red at 64 */ cp->cm_red[32*2] = 65535; /* Yellow ... */ cp->cm_red[32*3] = 65535; cp->cm_green[32*3] = 65535; /* Green */ cp->cm_green[32*4] = 65535; /* Cyan */ cp->cm_green[32*5] = 65535; cp->cm_blue[32*5] = 65535; /* Blue */ cp->cm_blue[32*6] = 65535; break; case 8: (void) fprintf(stderr, "Color map #8, Ikcmap 8.\n"); for (i = 0; i < 256; i++) { cp->cm_red[i] = utah8[3*i] << 8; cp->cm_green[i] = utah8[3*i+1] << 8; cp->cm_blue[i] = utah8[3*i+2] << 8; } break; case 9: (void) fprintf(stderr, "Color map #9, Ikcmap 9.\n"); for (i = 0; i < 256; i++) { cp->cm_red[i] = utah9[3*i] << 8; cp->cm_green[i] = utah9[3*i+1] << 8; cp->cm_blue[i] = utah9[3*i+2] << 8; } break; case 10: /* Black */ (void) fprintf(stderr, "Color map #10, solid black.\n"); break; case 11: /* White */ (void) fprintf(stderr, "Color map #11, solid white.\n"); for (i = 0; i < 256; i++) { cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = 255 << 8; } break; case 12: /* 18% Grey */ (void) fprintf(stderr, "Color map #12, 18%% neutral grey.\n"); for (i = 0; i < 256; i++) { cp->cm_red[i] = cp->cm_green[i] = cp->cm_blue[i] = 46 << 8; } break; default: (void) fprintf(stderr, "Color map #%d, flavor not implemented!\n", flavor); usage(); return 1; } fb_wmap(fbp, cp); return fb_close(fbp); }
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; }