diff options
author | Simon Howard | 2008-03-09 03:02:48 +0000 |
---|---|---|
committer | Simon Howard | 2008-03-09 03:02:48 +0000 |
commit | f9b29073f787a7ddbd7f73b80eb360915ebef4ae (patch) | |
tree | 5e0a9dc8e7a52a578ae32d135fd6077756bc2aec /src/v_video.c | |
parent | 6121dd5eb9cc18e673cb1b82a71e7f76e82e6518 (diff) | |
download | chocolate-doom-f9b29073f787a7ddbd7f73b80eb360915ebef4ae.tar.gz chocolate-doom-f9b29073f787a7ddbd7f73b80eb360915ebef4ae.tar.bz2 chocolate-doom-f9b29073f787a7ddbd7f73b80eb360915ebef4ae.zip |
Split out configuration file code from m_misc.c into m_config.c. Move
screenshot code into v_video.c Add M_FileLength common function for
finding the length of an open file.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1102
Diffstat (limited to 'src/v_video.c')
-rw-r--r-- | src/v_video.c | 127 |
1 files changed, 125 insertions, 2 deletions
diff --git a/src/v_video.c b/src/v_video.c index a4a556bf..82d9f357 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -35,11 +35,13 @@ #include "doomdef.h" #include "doomdata.h" +#include "deh_main.h" #include "m_bbox.h" #include "i_swap.h" - +#include "i_video.h" +#include "m_misc.h" #include "v_video.h" - +#include "w_wad.h" #include "z_zone.h" // Each screen is [SCREENWIDTH*SCREENHEIGHT]; @@ -493,3 +495,124 @@ void V_Init (void) } } +// +// SCREEN SHOTS +// + +typedef struct +{ + char manufacturer; + char version; + char encoding; + char bits_per_pixel; + + unsigned short xmin; + unsigned short ymin; + unsigned short xmax; + unsigned short ymax; + + unsigned short hres; + unsigned short vres; + + unsigned char palette[48]; + + char reserved; + char color_planes; + unsigned short bytes_per_line; + unsigned short palette_type; + + char filler[58]; + unsigned char data; // unbounded +} PACKEDATTR pcx_t; + + +// +// WritePCXfile +// + +void WritePCXfile(char *filename, byte *data, + int width, int height, + byte *palette) +{ + int i; + int length; + pcx_t* pcx; + byte* pack; + + pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL); + + pcx->manufacturer = 0x0a; // PCX id + pcx->version = 5; // 256 color + pcx->encoding = 1; // uncompressed + pcx->bits_per_pixel = 8; // 256 color + pcx->xmin = 0; + pcx->ymin = 0; + pcx->xmax = SHORT(width-1); + pcx->ymax = SHORT(height-1); + pcx->hres = SHORT(width); + pcx->vres = SHORT(height); + memset (pcx->palette,0,sizeof(pcx->palette)); + pcx->color_planes = 1; // chunky image + pcx->bytes_per_line = SHORT(width); + pcx->palette_type = SHORT(2); // not a grey scale + memset (pcx->filler,0,sizeof(pcx->filler)); + + // pack the image + pack = &pcx->data; + + for (i=0 ; i<width*height ; i++) + { + if ( (*data & 0xc0) != 0xc0) + *pack++ = *data++; + else + { + *pack++ = 0xc1; + *pack++ = *data++; + } + } + + // write the palette + *pack++ = 0x0c; // palette ID byte + for (i=0 ; i<768 ; i++) + *pack++ = *palette++; + + // write output file + length = pack - (byte *)pcx; + M_WriteFile (filename, pcx, length); + + Z_Free (pcx); +} + +// +// V_ScreenShot +// + +void V_ScreenShot (void) +{ + int i; + byte* linear; + char lbmname[12]; + + // munge planar buffer to linear + linear = screens[2]; + I_ReadScreen (linear); + + // find a file name to save it to + strcpy(lbmname,"DOOM00.pcx"); + + for (i=0 ; i<=99 ; i++) + { + lbmname[4] = i/10 + '0'; + lbmname[5] = i%10 + '0'; + if (!M_FileExists(lbmname)) + break; // file doesn't exist + } + if (i==100) + I_Error ("V_ScreenShot: Couldn't create a PCX"); + + // save the pcx file + WritePCXfile (lbmname, linear, + SCREENWIDTH, SCREENHEIGHT, + W_CacheLumpName (DEH_String("PLAYPAL"), PU_CACHE)); +} + |