/* VERY Simple printf interface J. Watlington, 9/13/95 - 10/25/95 Spoof of X interface ! Has the following interface : window_tag display_init_window( name, x_size, y_size, num_levels ) display_update( window_tag ) display_set_pixel( window_tag, x, y, raw_pixel_value ) display_set_scale( window_tag, min, max ) display_set_spixel( window_tag, x, y, scaled_value ) display_set_fpixel( window_tag, x, y, scaled_value_float ) */ #include #include #include "display.h" struct displayWindowDesc { unsigned char *image; int x_size; int y_size; int num_levels; int min; int delta; }; window_desc window_desc_table[DISPLAY_MAX_WINDOWS]; static int num_windows_open = 0; window_tag display_init_window( char *name, int xsize, int ysize, int num_levels ) { window_desc *wd; window_tag wt; if( num_levels > DISPLAY_MAX_COLORS ) { printf("display_init_window: Max num levels is %d\n", DISPLAY_MAX_COLORS ); return( -1 ); } /* assign a window_tag, and find the window descriptor */ wt = num_windows_open++; if( wt > DISPLAY_MAX_WINDOWS ) { printf( "display_window_init: Too many windows open ! (%d max)\n", DISPLAY_MAX_WINDOWS ); return( -1 ); } wd = window_desc_table + wt; printf( "Opening window %s (%d)\n", name, wt ); /* Allocate an image buffer and assign it to the window */ if( (wd->image = (unsigned char *)malloc( xsize * ysize )) == NULL ) { printf("display_init_window: Unable to alloc %d bytes of mem for image\n", xsize * ysize ); return( -1 ); } wd->x_size = xsize; wd->y_size = ysize; wd->num_levels = num_levels; wd->min = 0; wd->delta = 1; return( wt ); } void display_update( window_tag id ) { window_desc *wd = window_desc_table + id; int x, y; unsigned char *image_ptr; image_ptr = wd->image; printf( "Window %d:", id ); for( y = 0; y < wd->y_size; y++ ) { printf( "\n%3d: %d ", y, (int)( *image_ptr++ ) ); for( x = 1; x < wd->x_size; x++ ) { printf( "%d ", (int)( *image_ptr++ ) ); } } printf( "\n\n" ); }