/*---------------------------------------------------------------------------*/ /* */ /* This file contains functions that are used to store and retrieve */ /* pictures from disk storage. Note the file format. The line length */ /* then the # of lines are saved as the first items in the file. */ /* */ /*---------------------------------------------------------------------------*/ #include #include #include extern WINDOW *funcwin; extern char strg[79]; int buf[512]; /*****************************************************************************/ #define xdim 512 #define ydim 512 /*****************************************************************************/ /* */ /* save_picture */ /* */ /* This function saves any rectangular portion of the screen into a disk */ /* file. Note that the line length and # of lines are the first things */ /* stored into the file. Also '\n's are included to make it compatible */ /* 'vi' so the file can be examined or possibly edited. */ /* */ /*****************************************************************************/ save_picture( x1, y1, x2, y2, filename ) int x1, y1, x2, y2; char filename[]; { int i,j,k,keep; FILE *fopen(), *pic; /* char buf[xdim]; */ /* do some window operations */ wclear( funcwin ); box( funcwin, VERTCH, HORZCH ); wmove( funcwin, 4, 20 ); waddstr( funcwin, "S A V I N G P I C T U R E" ); wmove( funcwin, 5, 20 ); waddstr( funcwin, "- - - - - - - - - - - - -" ); wrefresh( funcwin ); /* first we will open the file given by the indicated file name */ pic = fopen( filename, "w" ); /* if x2 is < x1 if (x2 < x1) { keep = x2; x2 = x1; x1 = keep; } /* if y2 is < y1 if (y2 < y1) { keep = y2; y2 = y1; y1 = keep; } */ if (pic == NULL) { wmove( funcwin, 7, 5 ); wprintw( funcwin, "Warning from save_picture, %s could not be opened!\n", filename); /* wait_window(); */ } else { /* save the line length and the # of lines */ if (y1 == 0) fprintf( pic, "%d,%d\n", x2-x1 +1, y2-y1 ); /* this adjusts because we cannot read the top line of the frame */ /* buffer */ else fprintf( pic, "%d,%d\n", x2-x1 +1, y2-y1 +1 ); for (i=(y1 ? 0 : 1); i <= y2 - y1; i++) { #ifdef ROGER for ( k = 0; k <= x2-x1; k++ ) buf[k] = VIS$GET_PIXEL(x1+k,y1+i); #endif VIS$READ_HORIZONTAL_LINE (x1, y1+i, x2-x1, buf); for (j=0; j<=x2-x1; j++) putc( buf[j], pic ); putc( '\n', pic ); /* this line is useful for editors */ } } /* end else */ fclose( pic ); wclear( funcwin ); wrefresh( funcwin ); } /* end of save_picture */ /****************************************************************************/ /****************************************************************************/ /* */ /* read_picture */ /* */ /* This function reads an image stored in a disk file and places it at the */ /* indicated position on the moniter. Note that this procedure must know */ /* the file format used by the write procedure. It is important to NOTE */ /* that this function does not check for end of file. */ /* */ /****************************************************************************/ read_picture(x, y, filename ) int x, y; char filename[]; { FILE *fopen(), *pic; int i,j,k,linelen,numlines; pic = fopen( filename, "r" ); if (pic == NULL) { sprintf (strg, "Warning: file %s does not exist!", filename); printit (strg); wait_window(); } else { /* read in the line length and the # of lines in the stored image */ fscanf( pic, "%d,%d\n", &linelen, &numlines ); /* now read in the image and store it out to the frame buffer */ for (i=0; ( (i