/* * read98721 - read an RLE image from a display device * * Author: Filippo Tampieri * Program of Computer Graphics * Cornell University * Date: Tue June 9 1987 * * [-m] - store maps * [-O] - store overlay (doesn't seem to do anything) * [-d display] - display device ("/dev/...") * [-x driver] - driver name ("hp98721") * [-p xstart ystart] - lower left pixel start * [-s xsize ysize] - size of image to store * [-b rbak gbak bbak] - background color * [-o fname] - output filename * [comments ...] * */ #include "starbase.c.h" #include #include #define TRUE 1 #define FALSE 0 #define MAX(i,j) ((i) > (j) ? (i) : (j)) #define NCHANS 3 #define NCMAPS 3 #define CMAPLEN 8 #define COLMAPLEN 256 #define MAX_X_SIZE 1280 /* if cmap_flag is TRUE the color maps are saved */ int cmap_flag = FALSE; int display_flag = FALSE; int driver_flag = FALSE; /* default display device and device driver */ char *display_name = "/dev/hp98721"; char *driver_name = "hp98721"; int pos_flag = FALSE; /* (xstart,ystart) are the coordinates of the lower left corner of the block to be saved */ #define D_XSTART 0 #define D_YSTART 0 int xstart = D_XSTART; int ystart = D_YSTART; int size_flag = FALSE; /* xsize and ysize are the size of the block to be saved */ #define D_XSIZE 512 #define D_YSIZE 480 int xsize = D_XSIZE; int ysize = D_YSIZE; int overlay_flag = FALSE; /* if backgnd_flag is TRUE the background color given in backgnd[] is not explicitly saved */ int backgnd_flag = FALSE; int backgnd[NCHANS]; int fname_flag = FALSE; /* if fname is NULL the image is written to the standard output */ char *fname = NULL; int ncomments = 0; char **comments = NULL; /* starbase file descriptor for device from which the picture is read */ int picture_fd; main(argc, argv) int argc; char *argv[]; { int i,y; int dev_xmax,dev_ymax; rle_map cmap[COLMAPLEN * NCMAPS]; unsigned char scanline[NCHANS][MAX_X_SIZE],*rows[NCHANS]; /* Scanline storage & RLE row pointers */ if (scanargs(argc, argv, "% m%- O%- d%-display!s x%-driver!s p%-xstart!dystart!d s%-xsize!dysize!d \ b%-rbak!dgbak!dbbak!d o%-fname!s comments%*s", &cmap_flag, &overlay_flag, &display_flag,&display_name, &driver_flag,&driver_name, &pos_flag,&xstart,&ystart, &size_flag,&xsize,&ysize, &backgnd_flag,&(backgnd[0]),&(backgnd[1]),&(backgnd[2]), &fname_flag,&fname, &ncomments,&comments) == 0) exit(1); if(overlay_flag && backgnd_flag) { fprintf(stderr,"read98721: incompatible options -O and -b\n"); exit(1); } /* initialize the display device */ setup_graphics_device(&dev_xmax,&dev_ymax); clip(dev_xmax,dev_ymax,&xstart,&ystart,&xsize,&ysize); if((xsize <= 0)||(ysize <= 0)) { fprintf(stderr,"read98721: null image size\n"); exit(1); } /* open output file */ rle_dflt_hdr.rle_file = rle_open_f("read98721", fname, "w"); /* initialize image header */ rle_dflt_hdr.ncolors = NCHANS; rle_dflt_hdr.bg_color = backgnd_flag ? backgnd : (int *)0; rle_dflt_hdr.alpha = FALSE; rle_dflt_hdr.background = backgnd_flag ? 2 : (overlay_flag ? 1 : 0); rle_dflt_hdr.xmin = xstart; rle_dflt_hdr.xmax = xstart + xsize -1; rle_dflt_hdr.ymin = ystart; rle_dflt_hdr.ymax = ystart + ysize -1; if(cmap_flag) { read_color_maps(picture_fd,cmap); rle_dflt_hdr.ncmap = NCMAPS; rle_dflt_hdr.cmaplen = CMAPLEN; rle_dflt_hdr.cmap = cmap; } else { rle_dflt_hdr.ncmap = 0; rle_dflt_hdr.cmaplen = 0; rle_dflt_hdr.cmap = (rle_map *)0; } rle_dflt_hdr.bits[0] = 0x07; for(i=0; i dev_xmax) *xsize = dev_xmax - *xstart; if(*ystart + *ysize > dev_ymax) *ysize = dev_ymax - *ystart; } /* read scanline y from the screen */ read_scanline(y,rows) int y; unsigned char *rows[]; { int i,j; for(i=0,j=NCHANS-1; i