6
extern bool _mapAll,_hexspritenums;
8
/***********************\
12
\***********************/
14
// to make this a bit more readable, use binary digits instead of hex
33
#define _(o,t) ((b ## t << 4) + b ## o)
37
// DIGITHEIGHT*DIGITWIDTH*16(digits)/8(bitsperbyte) = 40 bytes
38
#define DIGITIND(digit,line) (digit/2+8*line)
39
#define DIGITSHR(digit) (4*(digit&1))
40
static unsigned char digitlines[40] = {
42
_( _OO_, __O_ ),_( OOO_, OOO_ ),_( __O_, OOOO),_( _OO_, OOOO),_( _OO_, _OO_ ), _( _OO_, OOO_ ), _( _OOO, OOO_ ), _( OOOO, OOOO ),
43
_( O__O, _OO_ ),_( ___O, ___O ),_( _OO_, O___),_( O___, ___O),_( O__O, O__O ), _( O__O, O__O ), _( O___, O__O ), _( O___, O___ ),
44
_( O__O, __O_ ),_( _OO_, _OO_ ),_( O_O_, OOO_),_( OOOO, __O_),_( _OO_, _OOO ), _( OOOO, OOO_ ), _( O___, O__O ), _( OOO_, OOO_ ),
45
_( O__O, __O_ ),_( O___, ___O ),_( OOOO, ___O),_( O__O, _O__),_( O__O, ___O ), _( O__O, O__O ), _( O___, O__O ), _( O___, O___ ),
46
_( _OO_, _OOO ),_( OOOO, OOO_ ),_( __O_, OOO_),_( _OO_, _O__),_( _OO_, _OO_ ), _( O__O, OOO_ ), _( _OOO, OOO_ ), _( OOOO, O___ ),
52
pcxwrite::pcxwrite(multifile *mfile)
55
spriteno=-1; // so the first one will be 0
59
void pcxwrite::filedone(int final)
65
// fill with blank lines to the right height if necessary
66
for (y=totaly; y<sy; y++) {
68
encodebytes(background, sx);
83
void pcxwrite::setcolours(U8 bg, U8 bord, int skip)
90
void pcxwrite::startsubimage(int /*x*/, int /*y*/, int sx, int sy)
93
int bordersizex = BORDERSIZE;
94
int bordersizey = BORDERSIZE + DIGITHEIGHT + 1;
99
subx += ( (int) (px + bandx) / bandx) * bandx;
101
if (subx + sx >= pcxfile::sx) {
106
if (sy > thisbandy) {
107
thisbandy = ( (int) (sy + bandy - 1) / bandy) * bandy;
108
alloclines(thisbandy);
114
px = sx;// - bordersizex;
115
py = sy;// - bordersizey;
124
for (i=0; i < 2*bx+2*by; i+=borderskip) {
128
putpixel(i, 0, border);
130
else if (i < bx + by)
131
putpixel(0, i - bx, border);
133
else if (i < 2*bx + by)
134
putpixel(i-bx-by, by, border);
137
putpixel(bx, i-2*bx-by, border);
141
// WRONG Y IN NFO FILE !!
143
// show sprite number
150
void pcxwrite::showspriteno()
155
sprintf(spritenum, "%X", spriteno);
157
sprintf(spritenum, "%d", spriteno);
159
newlastx = subx+strlen(spritenum)*(DIGITWIDTH+1)+dx;
160
if (newlastx >= pcxfile::sx)
163
if (subx+dx < lastdigitx + 2*(DIGITWIDTH+1))
166
lastdigitx = newlastx;
168
for (int i=0; spritenum[i]; i++) {
169
int digit = spritenum[i] - '0';
172
for (int y=0; y<DIGITHEIGHT; y++) {
173
int pixels = digitlines[DIGITIND(digit,y)] >> DIGITSHR(digit);
174
for (int x=DIGITWIDTH-1; x>=0; x--) {
176
putpixel(x + i*(DIGITWIDTH+1),y,border);
183
void pcxwrite::setline(U8 *band)
185
memset(band, background, sx);
188
void pcxwrite::spritedone(int sx, int sy){
191
bool maybeGlyph=!_mapAll;
193
for(int cx=0, x=subofsx(cx,0);cx<sx&&maybeGlyph;cx++,x++)
194
for(int cy=0, y=subofsy(cy,0);cy<sy;cy++,y++)
195
maybeGlyph &= (band[y][x] < 3);
198
for(int cx=0, x=subofsx(cx,0);cx<sx;cx++,x++)
199
for(int cy=0, y=subofsy(cy,0);cy<sy;cy++,y++)
200
band[y][x] = putcolourmap[band[y][x]];
203
void pcxwrite::writeheader()
205
long oldpos = ftell(curfile);
206
fseek(curfile, 0, SEEK_SET);
208
header.window[3] = totaly - 1;
209
header.screen[1] = totaly - 1;
211
#ifdef __BIG_ENDIAN__
212
pcxheader le_header = header;
213
be_swapheader(le_header);
215
pcxheader& le_header = header;
217
cfwrite("writing pcx header", &le_header, sizeof(pcxheader), 1, curfile);
218
fseek(curfile, oldpos, SEEK_SET);
221
void pcxwrite::writepal()
223
long oldpos = ftell(curfile);
225
fseek(curfile, 0, SEEK_END);
228
cfwrite("writing palette", palette, 768, 1, curfile);
230
fseek(curfile, oldpos, SEEK_SET);
233
void pcxwrite::setpalette(const U8 *palette)
235
pcxwrite::palette = palette;
238
/*void pcxwrite::setpalette(FILE *palfile)
240
cfread(palette, 1, 768, palfile);
244
/***********************\
248
\***********************/
250
pcxread::pcxread(singlefile *mfile)
255
void pcxread::startsubimage(int x, int y, int sx, int sy)
259
if (y + sy > pcxread::sy) {
260
printf("\nError: Sprite y extends beyond end of PCX file.\nFile has %d lines, sprite wants %d..%d\n.",
261
pcxread::sy, y, y + sy - 1);
265
if (sy > bandlines) { // don't have enough lines in memory, read rest
269
if (y > totaly) { // doesn't start right at the top -> delete extra lines
270
expirelines(y - totaly);
284
void pcxread::setline(U8 *band)
288
decodebytes(band, sx);
294
void pcxread::readheader()
296
long oldpos = ftell(curfile);
297
fseek(curfile, 0, SEEK_SET);
299
cfread("reading pcx header", &header, sizeof(pcxheader), 1, curfile);
300
be_swapheader(header);
302
if (header.nplanes == 3) {
303
fprintf(stderr, "Cannot read truecolour PCX files!\n");
306
if ( (header.bpp != 8) || (header.nplanes != 1) ) {
307
fprintf(stderr, "PCX file is not a 256 colour file!\n");
311
fseek(curfile,-768,SEEK_END);
314
if (fread(palette,1,768,curfile) != 768 ) {
315
fprintf(stderr, "Could not read palette from PCX file!\n");
321
if(!memcmp(palette,defaultpalettes[i],768)) break;
323
if ( i == NUM_PALS ) {
325
if (!_quiet) fprintf(stderr, "Warning: Encoding despite unrecognized palette.\n");
327
fprintf(stderr, "Error: Unrecognized palette, aborting.\n"
328
"Specify -f on the command line to override this check.\n");
333
fseek(curfile, oldpos, SEEK_SET);
335
/* header.bpl is number of bytes per scanline.
336
* header.window[2] - header.window[0] + 1 is number of bytes actually used.
337
* The original ZSoft standard defines header.bpl to be always even, so there may be unused bytes.
338
* However, more modern software (e.g. gimp) do not care about that and do not waste any bytes. */
340
sy = header.window[3] - header.window[1] + 1;