home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 March / pcx19_9803.iso / PC-XUSER / PC-XUSER.14 / DEMO / PROGRAM / PCX.C < prev   
Encoding:
C/C++ Source or Header  |  1998-02-08  |  1.4 KB  |  75 lines

  1. /*
  2.  ┌───────────────────────────────────────────────────────────────────────────┐
  3.  │                        PCX reading Module only for 320*200 images         │
  4.  │                                 Copyright KUMM 1997                       │
  5.  │                                     Ver  0.00                             │
  6.  └───────────────────────────────────────────────────────────────────────────┘
  7. */
  8. #include <stdio.h>
  9. #include <malloc.h>
  10. #include <my\graph.h>
  11.  
  12. #define PCXPAL 1
  13. #define NOPAL  0
  14.  
  15. void readpcx(char *filename,char *screen,int dopal);
  16.  
  17.  
  18. //decompress the pcx image from pic to screen
  19. void decompress(char *pic,char *screen)
  20. {
  21.  int scp=0,ism=0;
  22.  
  23.  pic+=128;              //pcx header atlepese
  24.  while(scp<320*200)
  25.  {
  26.   if((*pic & 128) && (*pic & 64))
  27.   {
  28.    ism=*pic&63;
  29.    pic++;
  30.    while(ism)
  31.    {
  32.     screen[scp]=*pic;
  33.     scp++;
  34.     ism--;
  35.    }
  36.   } else
  37.   {
  38.    screen[scp]=*pic;
  39.    scp++;
  40.   }
  41.   pic++;
  42.  }
  43. }
  44.  
  45. //read and put the pcx image from filename to screen
  46. void readpcx(char *filename,char *screen,int dopal)
  47. {
  48.  FILE *pcx;
  49.  int n;
  50.  char *pic,*pal;
  51.  int filesize;
  52.  
  53.  pcx=fopen(filename,"rb");
  54.  fseek(pcx,0,SEEK_END);
  55.  filesize=ftell(pcx);
  56.  fseek(pcx,0,SEEK_SET);
  57.  pic=(char*) malloc(filesize);
  58.  fread(pic, 1, filesize, pcx);
  59.  fclose(pcx);
  60.  
  61.  decompress(pic,screen);
  62.  pal=pic+filesize-768;
  63.  if (dopal==PCXPAL)
  64.  {
  65.   for(n=0;n<768;n++)
  66.   {
  67.    pal[n]>>=2;
  68.   }
  69.   setpal(pal);
  70.  }
  71.  
  72.  free(pic);
  73. }
  74.  
  75.