/********************************************************************* ** Copyright 1992 Lexicor Software Corp. ** ** Prism Paint file format's ** ** This document may be freely distributed. ** **********************************************************************/ /* ** Header block for Prism Paint PNT picture files... ** sizeof(PNT_HEADER) = 128 bytes. */ typedef struct pnthdr { char id_string[4]; /* File ID, must be "PNT" (ASCIIZ string) */ int version; /* Prism Paint version that saved picture */ int pal_colors; /* number of colors in PNT picture */ int image_width; /* width of PNT picture in pixels */ int image_height; /* height of PNT picture in pixels */ int image_planes; /* bit-planes in PNT picture */ int image_compressed; /* image compressed/uncompressed flag */ long image_size; /* size of image data in file */ int reserved[54]; /* must be all zeros! */ } PNT_HEADER; /* ** For the following save/load subroutines, assume that the variable ** 'pnt_buffer' contains the address of a buffer large enough to hold ** a full screen image in the current resolution. Actually, adding ** another 2K-3K to the size of the 'pnt_buffer' is a good idea, since ** an RLE compressed picture can sometimes end up larger than the ** original uncompressed picture. */ /******************************************************** * load_pnt(): * * General structure of subroutine to load a compressed, * * or uncompressed Prism Paint PNT picture file. * ********************************************************/ int load_pnt( void ) { int fd; int vdipal[256][3]; PNT_HEADER PNT; fd = Fopen( "PICTURE.PNT", 0 ); Fread( fd, (long)sizeof(PNT_HEADER), &PNT ); /* check the PNT header to see if the file is valid */ if( strncmp( PNT.id_string, "PNT", 4 ) != 0 ) { Fclose(fd); return(-1); } /* ** Note: ** Be sure to check the following PNT structure fields: ** PNT.image_width, PNT.image_height, and PNT.image_planes ** to see if the picture can be displayed in the current ** resolution. */ /* ** Read the color palette of the PNT file. ** This palette is in exactly the same format as the one used ** by the VDI vs_color()/vq_color() functions [R,G,B = 0-1000]. */ Fread( fd, (long)PNT.pal_colors * 6L, &vdipal[0][0] ); /* read the image data into an intermediate buffer */ Fread( fd, PNT.image_size, pnt_buffer ); Fclose(fd); if( PNT.image_compressed == 0 ) { /* ** The data in the intermediate buffer is an ** uncompressed PNT picture file that can be ** copied directly to the screen. */ } if( PNT.image_compressed == 1 ) { /* ** The data in the intermediate buffer ** is compressed using the same RLE format ** that Degas Elite uses for its "PC?" files. */ } else { /* ** The compression flag indicates a currently undefined ** format. Future versions of Prism Paint will add more ** compression schemes. */ return(-1); } return(0); } /* End: load_pnt() */ /******************************************************** * save_pnt(): * * General structure of subroutine to save a compressed, * * or uncompressed Prism Paint PNT picture file. * ********************************************************/ int save_pnt( void ) { int fd; int vdipal[256][3]; long int start_pos; long int end_pos; long int size; PNT_HEADER PNT; /* set up the PNT header block */ strcpy( PNT.id_string, "PNT" ); PNT.version = 0x100; /* Version of Prism Paint that saved picture */ PNT.pal_colors = 256; /* number of colors for current resolution */ PNT.image_width = 800; /* width of screen in pixels */ PNT.image_height = 600; /* height of screen in pixels */ PNT.image_planes = 8; /* number of planes for current resolution */ PNT.image_size = 0L; /* initialize size to zero */ /* set the reserved area to all zeros */ memset( PNT.reserved, 0, 54 << 1 ); /* ** Set the 'image compressed' flag accordingly. ** image not compressed = 0 ** image RLE compressed = 1 ** future compression schemes = 2 and greater */ PNT.image_compressed = 0; /* create the file, save the header, and save the palette */ fd = Fcreate( "PICTURE.PNT", 0 ); Fwrite( fd, (long)sizeof(PNT_HEADER), &PNT ); /* ** Here's where you save the color palette for the picture. ** You will have to get all the colors in the VDI palette ** and store them in the vdipal[][] array. */ Fwrite( fd, (long)PNT.pal_colors * 6L, &vdipal[0][0] ); /* get current file pointer before saving the picture data */ start_pos = (long)Fseek( 0L, fd, 1 ); if( PNT.image_compressed == 0 ) { /* save the screen to the file */ } else { /* compress the screen using RLE and write it to the file */ } /* save the size of the image data to the PNT header */ end_pos = (long)Fseek( 0L, fd, 2 ); size = end_pos - start_pos; /* Seek to the image size field in the header and update it */ Fseek( (long)&PNT.image_size - (long)&PNT, fd, 0 ); Fwrite( fd, 4L, &size ); Fclose(fd); return(0); } /* End: save_pnt() */