home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Misc / FASTMC.LHA / fastmc / src / ppmview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-31  |  2.7 KB  |  110 lines

  1. /* PPMView v0.4 (31 October 1995) - ©1995 by WK-Artworks */
  2. /*
  3.  
  4.  wkmc is a simple true-color-display using a 8-bit-screen,
  5.  the idea behind this came from Stefan Kost and Smack/IFT
  6.  
  7.  NOTE: I think it's fast beeing pure C !
  8.  
  9.  
  10.  Advantages (compared against MultiColor):
  11.   -terrible high speed
  12.   -picture-size and -aspect isn't changed
  13.   -no ugly diagonal-dithering
  14.   -no flickering (uses Multiscan)
  15.   -uses all 256 registers (not only 255)
  16.   -every color-channel (RGB) has a diffent number of
  17.    shades ("eye-sensitive")
  18. */
  19.  
  20. #include "wkmc.h"
  21.  
  22. int main(int argc,char **argv) {
  23.  FILE *fh;
  24.  char hs[64];
  25.  UBYTE *bl[8];
  26.  int width,height,i,qt=0,bn;
  27.  UBYTE *line=NULL;
  28.  struct IntuiMessage *imsg;
  29.  ULONG iclass;
  30.  USHORT icode;
  31.  printf("\n PPMView v0.4 - ©1995 by WK-Artworks/IFT\n");
  32.  printf("-----------------------------------------\n");
  33.  if(argc<2) {printf(" Usage: ppmview <ppm-file> [displayID]\n");return(1);}
  34.  fh=fopen(argv[1],"rb");
  35.  if(fh==NULL) return(1);
  36.  if(argc>2) displayID=strtol(argv[2],NULL,16); 
  37.  fscanf(fh,"%s",hs);
  38.  
  39.  fscanf(fh,"%s",hs);
  40.  width=strtol(hs,NULL,10);
  41.  fscanf(fh,"%s",hs);
  42.  height=strtol(hs,NULL,10);
  43.  fscanf(fh,"%s",hs);
  44.  #ifdef __GNUC__
  45.  fread(&i,1,1,fh);
  46.  #endif
  47.  printf(" Resolution : %dx%d\n",width,height);
  48.  if(init(width,height)==0) {
  49.  
  50.   /* do it */
  51.   bn=theScreen->BitMap.BytesPerRow;
  52.  
  53.   for(i=0;i<8;i++) {bl[i]=malloc(bn);if(bl[i]==NULL) return(1);}
  54.   line=(UBYTE*)malloc(3*width);
  55.   if(line==NULL) {fclose(fh);return(1);}
  56.   time(&tm1);
  57.   for(i=0;i<height;i++) {
  58.    fread(line,1,3*width,fh);   
  59.    SetLineS(i,line,width,bn,bl);
  60.  
  61.    imsg=(struct IntuiMessage*)GetMsg(theWindow->UserPort);
  62.    if(imsg!=NULL) {
  63.     iclass=imsg->Class;
  64.     icode=imsg->Code;
  65.     ReplyMsg((struct Message*)imsg);
  66.     switch(iclass) {
  67.      case IDCMP_VANILLAKEY:switch(icode) {
  68.                             case ' ':free(line);for(i=0;i<8;i++) free(bl[i]);fclose(fh);  cleanup();return(0);break;
  69.                             case 27:free(line);for(i=0;i<8;i++) free(bl[i]);fclose(fh);  cleanup();return(0);break;
  70.                            }
  71.     }
  72.    }
  73.  
  74.  
  75.   }
  76.  
  77.   time(&tm2);
  78.   tm=difftime(tm2,tm1);
  79.   printf(" Decode-time: %lds\n",(ULONG)tm);
  80.   free(line);
  81.   for(i=0;i<8;i++) free(bl[i]);
  82.   fclose(fh);
  83.  
  84.   /* wait */
  85.   do {
  86.    WaitPort(theWindow->UserPort);
  87.    do {
  88.     imsg=(struct IntuiMessage*)GetMsg(theWindow->UserPort);
  89.     if(imsg!=NULL) {
  90.      iclass=imsg->Class;
  91.      icode=imsg->Code;
  92.      ReplyMsg((struct Message*)imsg);
  93.      switch(iclass) {
  94.       case IDCMP_VANILLAKEY:switch(icode) {
  95.                              case ' ':qt=1;break;
  96.                              case 27:qt=1;break;
  97.                             }
  98.      }
  99.     }
  100.    } while(imsg!=NULL);
  101.   } while(qt==0);
  102.   /* clean up*/
  103.   cleanup();
  104.  }
  105.  return(0);
  106.  printf("\n");
  107. }
  108.  
  109.  
  110.