home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 177.lha / IffLib_v15.3 / ShowIFF.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  104 lines

  1. /*
  2.     ShowIFF.c  -  an easy IFF file view program by Christian A. Weber
  3.     Requires the iff.library (in the LIBS: dircetory or in a ROM)
  4.     This program may be freely used and modified!
  5.     I compiled it with Aztec C V3.6, for Lattice you must change iff.h
  6. */
  7.  
  8. #include "exec/types.h"
  9. #include "intuition/intuition.h"
  10. #include "libraries/iff.h"
  11.  
  12.  
  13. struct Library *GfxBase,*IntuitionBase,*IFFBase=NULL;
  14.  
  15. struct NewScreen ns =
  16. {
  17.     0,0,0,0,0,0,0, NULL, CUSTOMSCREEN, NULL,
  18.     (STRPTR)"IFF test screen", NULL, NULL
  19. };
  20.  
  21. struct Screen *myscreen = NULL;
  22. APTR ifffile = NULL;
  23.  
  24.  
  25. main(argc,argv)
  26. int argc;
  27. char **argv;
  28. {
  29.     struct Library *OpenLibrary();
  30.     struct Screen *OpenScreen();
  31.  
  32.     UWORD colortable[128];
  33.     struct BitMapHeader *bmhd;
  34.     ULONG count;
  35.     int i;
  36.  
  37.     if((argc != 2) || !strcmp(argv[1],"?")) {
  38.         printf("Format: %s filename\n",argv[0]);
  39.         exit(20);
  40.     }
  41.  
  42.     GfxBase = OpenLibrary("graphics.library",0L);
  43.     IntuitionBase = OpenLibrary("intuition.library",0L);
  44.  
  45.     if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
  46.         printf("Copy the iff.library to your LIBS: directory!\n");
  47.         exit(10);
  48.     }
  49.  
  50.     printf("Loading file %s ... ",argv[1]);
  51.  
  52.     if(!(ifffile=OpenIFF(argv[1]))) {
  53.         Fail("Error opening file");
  54.     }
  55.  
  56.     if(!(bmhd=GetBMHD(ifffile))) {
  57.         Fail("BitMapHeader not found");
  58.     }
  59.  
  60.     ns.Width      = bmhd->w;
  61.     ns.Height     = bmhd->h;
  62.     ns.Depth      = bmhd->nPlanes;
  63.     ns.ViewModes  = GetViewModes(ifffile);
  64.  
  65.     if(!(myscreen = OpenScreen(&ns))) {
  66.         Fail("Can't open screen!");
  67.     }
  68.  
  69.     count = GetColorTab(ifffile,colortable);
  70.     if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
  71.     LoadRGB4(&(myscreen->ViewPort),colortable,count);
  72.  
  73.     if(!(DecodePic(ifffile,&(myscreen->BitMap))))
  74.     {
  75.         Fail("Can't decode the picture");
  76.     }
  77.  
  78.     for(i=0; i<100; ++i)
  79.     {
  80.         if(!((*((UBYTE*)0xbfe001))&64)) break;
  81.         Delay(5L);
  82.     }
  83.  
  84.     Fail("done"); /* Close the whole stuff */
  85.  
  86. }
  87.  
  88.  
  89. Fail(text)
  90. char *text;
  91. {
  92.     if(ifffile) CloseIFF(ifffile);
  93.     if(myscreen) CloseScreen(myscreen);
  94.  
  95.     printf("%s\n",text);
  96.     printf("IffError: %ld\n",IffError());
  97.  
  98.     if(IFFBase) CloseLibrary(IFFBase);
  99.     CloseLibrary(IntuitionBase);
  100.     CloseLibrary(GfxBase);
  101.     exit(0);
  102. }
  103.  
  104.