2 Cockos WDL - LICE - Lightweight Image Compositing Engine
3 Copyright (C) 2007 and later, Cockos Incorporated
4 File: lice_pcx.cpp (PCX loading for LICE)
5 See lice.h for license and other information
9 #include "../wdltypes.h"
13 // note: you'd never really want to use PCX files, but in case you do...
15 LICE_IBitmap
*LICE_LoadPCX(const char *filename
, LICE_IBitmap
*_bmp
)
17 FILE *fp
= fopen(filename
,"rb");
21 if (fgetc(fp
) != 5) { fclose(fp
); return NULL
; }
22 if (fgetc(fp
) != 1) { fclose(fp
); return NULL
; }
23 if (fgetc(fp
) != 8) { fclose(fp
); return NULL
; }
25 int sx
= fgetc(fp
); sx
+= fgetc(fp
)<<8;
26 int sy
= fgetc(fp
); sy
+= fgetc(fp
)<<8;
27 int ex
= fgetc(fp
); ex
+= fgetc(fp
)<<8;
28 int ey
= fgetc(fp
); ey
+= fgetc(fp
)<<8;
31 unsigned char pal
[768];
32 fseek(fp
,-769,SEEK_END
);
33 if (fgetc(fp
) != 12) { fclose(fp
); return NULL
; }
35 if (feof(fp
)) { fclose(fp
); return NULL
; }
38 LICE_IBitmap
*usebmp
= NULL
;
39 if (_bmp
) (usebmp
=_bmp
)->resize(ex
-sx
+1,ey
-sy
+1);
40 else usebmp
= new WDL_NEW
LICE_MemBitmap(ex
-sx
+1,ey
-sy
+1);
41 if (!usebmp
|| usebmp
->getWidth() != (ex
-sx
+1) || usebmp
->getHeight() != (ey
-sy
+1))
43 if (usebmp
!= _bmp
) delete usebmp
;
48 fseek(fp
,128,SEEK_SET
);
51 int y
= usebmp
->getHeight();
52 int w
= usebmp
->getWidth();
53 int rowspan
= usebmp
->getRowSpan();
54 LICE_pixel
*pout
= usebmp
->getBits();
55 if (usebmp
->isFlipped())
57 pout
+= rowspan
*(y
-1);
69 int oc
= (fgetc(fp
))&255;
70 LICE_pixel t
=LICE_RGBA(pal
[oc
*3],pal
[oc
*3+1],pal
[oc
*3+2],255);
73 while (c
-- && xpos
<w
) pout
[xpos
++] = t
;
75 else pout
[xpos
++] = LICE_RGBA(pal
[c
*3],pal
[c
*3+1],pal
[c
*3+2],255);
88 _LICE_ImageLoader_rec rec
;
91 rec
.loadfunc
= loadfunc
;
92 rec
.get_extlist
= get_extlist
;
93 rec
._next
= LICE_ImageLoader_list
;
94 LICE_ImageLoader_list
= &rec
;
97 static LICE_IBitmap
*loadfunc(const char *filename
, bool checkFileName
, LICE_IBitmap
*bmpbase
)
101 const char *p
=filename
;
103 while (p
>filename
&& *p
!= '\\' && *p
!= '/' && *p
!= '.') p
--;
104 if (stricmp(p
,".pcx")) return 0;
106 return LICE_LoadPCX(filename
,bmpbase
);
108 static const char *get_extlist()
110 return "PCX files (*.PCX)\0*.PCX\0";
115 LICE_PCXLoader LICE_pcxldr
;