//--------------------------------------------------------// // // // File: WRTGIF.CPP // // // // Desc: Code to output a GIF file from a // // a VGA Display or a Memory Bitmap // // // //--------------------------------------------------------// #include "gif.hpp" #include "gifcodec.hpp" #include "color.hpp" #include "display.hpp" #include "imgstore.hpp" //..................Write VGA screen to GIF file 'fn' int WriteGIF( VgaDisplay& vga, char *fn, int x1, int y1, int x2, int y2 ) { // image metrics int nrows = y2 - y1 + 1; int ncols = x2 - x1 + 1; int nbits = vga.metric.nbits * vga.metric.nplanes; int size = (nbits < 8) ? nbits+1 : nbits; int ncolors = vga.metric.ncolors; rgb *pal = new rgb [ncolors]; if( pal == 0 ) return xNOMEMORY; vga.getpalette( pal ); // scan line buffer for encoder unsigned char *scanln = new unsigned char [ncols]; if( scanln == 0 ) return xNOMEMORY; // open and write the file FILE *f = fopen( fn, "wb" ); // GIF header - since we don't employ any of the // 89a extensions we set the version to 87a GIFHEADER hdr; hdr.ver[1] = '7'; if( hdr.put( f ) ) return xIOERROR; // GIF screen descriptor GIFSCDESC scd( ncols, nrows, nbits ); if( scd.put( f ) ) return xIOERROR; // the Global Color Table for( int i=0; i