int read_IR(FILE *fp) { int fy; int rx, ry; int min, max; if (fread((char *) &min, (int) sizeof(int), 1, fp) != 1 || fread((char *) &max, (int) sizeof(int), 1, fp) != 1 ) { bu_log("Can't read minimum and maximum temperatures.\n"); return 0; } else { bu_log("IR data temperature range is %d to %d\n", min, max ); if (ir_min == ABSOLUTE_ZERO) { /* Temperature range not set. */ ir_min = min; ir_max = max; } else { /* Merge with existing range. */ V_MIN(ir_min, min); V_MAX(ir_max, max); bu_log("Global temperature range is %d to %d\n", ir_min, ir_max ); } (void) fflush(stdout); } if (! init_Temp_To_RGB()) { return 0; } for (ry = 0, fy = grid_sz-1; ; ry += ir_aperture, fy--) { if (fb_seek(fbiop, 0, fy) == -1) { bu_log("\"%s\"(%d) fb_seek to pixel <%d, %d> failed.\n", __FILE__, __LINE__, 0, fy ); return 0; } for (rx = 0; rx < IR_DATA_WID; rx += ir_aperture) { int fah; int sum = 0; int i; int lgtindex; RGBpixel *pixel; for (i = 0; i < ir_aperture; i++) { int j; for (j = 0; j < ir_aperture; j++) { if (get_IR(rx+j, ry+i, &fah, fp)) sum += fah < ir_min ? ir_min : fah; else { /* EOF */ if (ir_octree.o_temp == ABSOLUTE_ZERO) ir_octree.o_temp = AMBIENT - 1; display_Temps(grid_sz/8, 0); return 1; } } } fah = Avg_Fah(sum); if ((lgtindex = fah-ir_min) > ir_max_index || lgtindex < 0) { bu_log("temperature out of range (%d)\n", fah ); return 0; } pixel = (RGBpixel *) ir_table[lgtindex]; (void) fb_wpixel(fbiop, (unsigned char *)pixel); } } }
void display_Temps(int xmin, int ymin) { int x, y; int interval = ((grid_sz*3+2)/4)/(S_BINS+2); int xmax = xmin+(interval*S_BINS); int ymax; fastf_t xrange = xmax - xmin; /* Avoid page thrashing of frame buffer. */ ymin = adjust_Page(ymin); ymax = ymin + interval; /* Initialize ir_table if necessary. */ if (! ir_Chk_Table()) return; for (y = ymin; y <= ymax; y++) { x = xmin; if (fb_seek(fbiop, x, y) == -1) { bu_log("\"%s\"(%d) fb_seek to pixel <%d, %d> failed.\n", __FILE__, __LINE__, x, y ); return; } for (; x <= xmax + interval; x++) { fastf_t percent; static RGBpixel *pixel; percent = D_XPOS / xrange; if (D_XPOS % interval == 0) { int temp = AMBIENT+percent*RANGE; int lgtindex = temp - ir_min; pixel = (RGBpixel *) ir_table[(lgtindex < ir_max_index ? lgtindex : ir_max_index)]; /* this should be an &ir_table..., allowed by ANSI C, but not K&R compilers. */ (void) fb_wpixel(fbiop, (unsigned char *) black); } else { (void) fb_wpixel(fbiop, (unsigned char *) pixel); } } } font = get_font((char *) NULL, bu_log); if (font.ffdes == NULL) { bu_log("Could not load font.\n"); fb_flush(fbiop); return; } y = ymin; for (x = xmin; x <= xmax; x += interval) { char tempstr[4]; fastf_t percent = D_XPOS / xrange; int temp = AMBIENT+percent*RANGE; int shrinkfactor = fb_getwidth(fbiop)/grid_sz; (void) sprintf(tempstr, "%3d", temp); do_line(x+2, y+(interval-(12/shrinkfactor))/2, tempstr /*, shrinkfactor*/ ); } fb_flush(fbiop); return; }
/* 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; }