home *** CD-ROM | disk | FTP | other *** search
- /*
- ┌───────────────────────────────────────────────────────────────────────────┐
- │ PCX reading Module only for 320*200 images │
- │ Copyright KUMM 1997 │
- │ Ver 0.00 │
- └───────────────────────────────────────────────────────────────────────────┘
- */
- #include <stdio.h>
- #include <malloc.h>
- #include <my\graph.h>
-
- #define PCXPAL 1
- #define NOPAL 0
-
- void readpcx(char *filename,char *screen,int dopal);
-
-
- //decompress the pcx image from pic to screen
- void decompress(char *pic,char *screen)
- {
- int scp=0,ism=0;
-
- pic+=128; //pcx header atlepese
- while(scp<320*200)
- {
- if((*pic & 128) && (*pic & 64))
- {
- ism=*pic&63;
- pic++;
- while(ism)
- {
- screen[scp]=*pic;
- scp++;
- ism--;
- }
- } else
- {
- screen[scp]=*pic;
- scp++;
- }
- pic++;
- }
- }
-
- //read and put the pcx image from filename to screen
- void readpcx(char *filename,char *screen,int dopal)
- {
- FILE *pcx;
- int n;
- char *pic,*pal;
- int filesize;
-
- pcx=fopen(filename,"rb");
- fseek(pcx,0,SEEK_END);
- filesize=ftell(pcx);
- fseek(pcx,0,SEEK_SET);
- pic=(char*) malloc(filesize);
- fread(pic, 1, filesize, pcx);
- fclose(pcx);
-
- decompress(pic,screen);
- pal=pic+filesize-768;
- if (dopal==PCXPAL)
- {
- for(n=0;n<768;n++)
- {
- pal[n]>>=2;
- }
- setpal(pal);
- }
-
- free(pic);
- }
-
-