2 Copyright (C) 1998 BJ Eirich (aka vecna)
\r
3 This program is free software; you can redistribute it and/or
\r
4 modify it under the terms of the GNU General Public License
\r
5 as published by the Free Software Foundation; either version 2
\r
6 of the License, or (at your option) any later version.
\r
7 This program is distributed in the hope that it will be useful,
\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
10 See the GNU General Public Lic
\r
11 See the GNU General Public License for more details.
\r
12 You should have received a copy of the GNU General Public License
\r
13 along with this program; if not, write to the Free Software
\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
21 char manufacturer; // pcx header
\r
24 char bits_per_pixel;
\r
25 short int xmin,ymin;
\r
26 short int xmax,ymax;
\r
32 short int bytes_per_line;
\r
33 short int palette_type;
\r
36 unsigned short int width,depth;
\r
37 unsigned short int bytes, i;
\r
38 unsigned char c, run, ss=0;
\r
39 unsigned int vidoffset, n=0;
\r
42 void ReadPCXLine(unsigned char *dest)
\r
47 c=fgetc(pcxf) & 0xff;
\r
48 if ((c & 0xc0)==0xc0) {
\r
51 for (j=0; j<run; j++)
\r
52 dest[vidoffset+n+j]=c;
\r
54 else { dest[vidoffset+n]=c;
\r
57 fread(strbuf, 1, bytes_per_line-width, pcxf);
\r
60 void LoadPCXHeader(char *fname)
\r
62 if (!(pcxf=fopen(fname,"rb"))) err("Could not open specified PCX file.");
\r
63 fread(&manufacturer,1,1,pcxf);
\r
64 fread(&version,1,1,pcxf);
\r
65 fread(&encoding,1,1,pcxf);
\r
66 fread(&bits_per_pixel,1,1,pcxf);
\r
67 fread(&xmin,1,2,pcxf);
\r
68 fread(&ymin,1,2,pcxf);
\r
69 fread(&xmax,1,2,pcxf);
\r
70 fread(&ymax,1,2,pcxf);
\r
71 fread(&hres,1,2,pcxf);
\r
72 fread(&vres,1,2,pcxf);
\r
73 fread(&palette,1,48,pcxf);
\r
74 fread(&reserved,1,1,pcxf);
\r
75 fread(&color_planes,1,1,pcxf);
\r
76 fread(&bytes_per_line,1,2,pcxf);
\r
77 fread(&palette_type,1,2,pcxf);
\r
78 fread(&filler,1,58,pcxf);
\r
79 fseek(pcxf,-768L,SEEK_END);
\r
80 fread(pal,1,768,pcxf);
\r
81 fseek(pcxf,128L,SEEK_SET);
\r
84 bytes=bytes_per_line;
\r
86 for (i=0; i<768; i++)
\r
91 void LoadPCXHeaderNP(char *fname)
\r
93 if (!(pcxf=fopen(fname,"rb"))) err("Could not open specified PCX file.");
\r
94 fread(&manufacturer,1,1,pcxf);
\r
95 fread(&version,1,1,pcxf);
\r
96 fread(&encoding,1,1,pcxf);
\r
97 fread(&bits_per_pixel,1,1,pcxf);
\r
98 fread(&xmin,1,2,pcxf);
\r
99 fread(&ymin,1,2,pcxf);
\r
100 fread(&xmax,1,2,pcxf);
\r
101 fread(&ymax,1,2,pcxf);
\r
102 fread(&hres,1,2,pcxf);
\r
103 fread(&vres,1,2,pcxf);
\r
104 fread(&palette,1,48,pcxf);
\r
105 fread(&reserved,1,1,pcxf);
\r
106 fread(&color_planes,1,1,pcxf);
\r
107 fread(&bytes_per_line,1,2,pcxf);
\r
108 fread(&palette_type,1,2,pcxf);
\r
109 fread(&filler,1,58,pcxf);
\r
112 bytes=bytes_per_line;
\r
115 void loadpcx(char *fname, char *dest)
\r
117 LoadPCXHeader(fname);
\r
119 for (i=0; i<depth; i++)
\r
120 { vidoffset=5648+(i*352);
\r
121 ReadPCXLine(dest); }
\r
126 void WritePCXLine(unsigned char *p)
\r
128 unsigned char byte,samect,repcode;
\r
134 while (samect<(unsigned) 63 && i<320 && byte==p[i])
\r
139 if (samect>1 || (byte & 0xC0) != 0)
\r
141 repcode=0xC0 | samect;
\r
142 fwrite(&repcode,1,1,pcxf);
\r
144 fwrite(&byte,1,1,pcxf);
\r
148 void WritePalette()
\r
152 for (i=0; i<768; i++)
\r
153 pal[i]=pal[i] << 2;
\r
155 b=12; fwrite(&b, 1, 1, pcxf);
\r
156 fwrite(pal, 1, 768, pcxf);
\r
158 for (i=0; i<768; i++)
\r
159 pal[i]=pal[i] >> 2;
\r
163 { unsigned char b1;
\r
164 unsigned short int w1;
\r
167 // Takes a snapshot of the current screen.
\r
169 dec_to_asciiz(ss,&fnamestr);
\r
170 b1=strlen(&fnamestr);
\r
171 fnamestr[b1++]='.';
\r
172 fnamestr[b1++]='P';
\r
173 fnamestr[b1++]='C';
\r
174 fnamestr[b1++]='X';
\r
177 pcxf=fopen(&fnamestr,"wb");
\r
180 // Write PCX header
\r
182 b1=10; fwrite(&b1, 1, 1, pcxf); // manufacturer always = 10
\r
183 b1=5; fwrite(&b1, 1, 1, pcxf); // version = 3.0, >16 colors
\r
184 b1=1; fwrite(&b1, 1, 1, pcxf); // encoding always = 1
\r
185 b1=8; fwrite(&b1, 1, 1, pcxf); // 8 bits per pixel, for 256 colors
\r
186 w1=0; fwrite(&w1, 1, 2, pcxf); // xmin = 0;
\r
187 w1=0; fwrite(&w1, 1, 2, pcxf); // ymin = 0;
\r
188 w1=319; fwrite(&w1, 1, 2, pcxf); // xmax = 319;
\r
189 w1=199; fwrite(&w1, 1, 2, pcxf); // ymax = 199;
\r
190 w1=320; fwrite(&w1, 1, 2, pcxf); // hres = 320;
\r
191 w1=200; fwrite(&w1, 1, 2, pcxf); // vres = 200;
\r
193 fwrite(virscr,1,48,pcxf); // 16-color palette data. Who knows what's
\r
194 // actually in here. It doesn't matter since
\r
195 // the 256-color palette is stored elsewhere.
\r
197 b1=0; fwrite(&b1, 1, 1, pcxf); // reserved always = 0.
\r
198 b1=1; fwrite(&b1, 1, 1, pcxf); // number of color planes. Just 1 for 8bit.
\r
199 w1=320; fwrite(&w1, 1, 2, pcxf); // number of bytes per line
\r
201 w1=0; fwrite(&w1, 1, 1, pcxf);
\r
202 fwrite(virscr, 1, 59, pcxf); // filler
\r
204 for (w1=0; w1<200; w1++)
\r
205 WritePCXLine(screen+(w1*320));
\r