home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 230.lha / IffLib_v16.1 / ShowIFF.c < prev    next >
C/C++ Source or Header  |  1989-04-06  |  3KB  |  112 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, it should also work with Lattice.
  6. */
  7.  
  8. #include <exec/types.h>
  9. #include <graphics/gfxbase.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/iff.h>
  12.  
  13. struct Library *IntuitionBase,*IFFBase=NULL, *OpenLibrary();
  14. struct GfxBase *GfxBase;
  15.  
  16. struct NewScreen ns =
  17. {
  18.     0,0,0,0,0,0,0, NULL, CUSTOMSCREEN|SCREENQUIET, NULL,
  19.     (STRPTR)"ShowIFF by Christian A. Weber", NULL, NULL
  20. };
  21.  
  22. struct Screen *myscreen = NULL, *OpenScreen();
  23. APTR ifffile = NULL;
  24.  
  25. void SetOverscan(screen,x,y,modes)
  26. register struct Screen *screen;
  27. register WORD x,y,modes;
  28. {
  29.     register WORD rows;
  30.  
  31.     rows = GfxBase->NormalDisplayRows; if(rows>300) rows>>=1;
  32.  
  33.     if(modes & HIRES) x -= 320;   x -= 320;
  34.     if(modes & LACE)  y -= rows;  y -= rows;
  35.  
  36.     x >>=1; if(x>32) x=32; if(x<0) x=0;
  37.     y >>=1; if(y>36) y=36; if(y<0) y=0;
  38.  
  39.     screen->ViewPort.DxOffset -= x;
  40.     screen->ViewPort.DyOffset -= y;
  41.  
  42.     RemakeDisplay();
  43. }
  44.  
  45.  
  46. main(argc,argv)
  47. int argc;
  48. char **argv;
  49. {
  50.     long count,i;
  51.     UWORD colortable[128];
  52.     struct BitMapHeader *bmhd;
  53.  
  54.     if((argc != 2) || !strcmp(argv[1],"?")) {
  55.         printf("Format: %s filename\n",argv[0]);
  56.         exit(20);
  57.     }
  58.  
  59.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  60.     IntuitionBase = OpenLibrary("intuition.library",0L);
  61.  
  62.     if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
  63.         printf("Copy the iff.library to your LIBS: directory!\n");
  64.         exit(10);
  65.     }
  66.  
  67.     printf("Loading file %s ... ",argv[1]);
  68.  
  69.     if(!(ifffile=OpenIFF(argv[1]))) Fail("Error opening file");
  70.  
  71.     if(!(bmhd=GetBMHD(ifffile)))    Fail("BitMapHeader not found");
  72.  
  73.     ns.Width      = bmhd->w;
  74.     ns.Height     = bmhd->h;
  75.     ns.Depth      = bmhd->nPlanes;
  76.     ns.ViewModes  = GetViewModes(ifffile);
  77.  
  78.     if(!(myscreen = OpenScreen(&ns))) Fail("Can't open screen!");
  79.     SetOverscan(myscreen,ns.Width,ns.Height,ns.ViewModes);
  80.  
  81.     count = GetColorTab(ifffile,colortable);
  82.     if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
  83.     LoadRGB4(&(myscreen->ViewPort),colortable,count);
  84.  
  85.     if(!DecodePic(ifffile,&myscreen->BitMap)) Fail("Can't decode picture");
  86.  
  87.     for(i=0; i<100; ++i)
  88.     {
  89.         if(!((*((UBYTE*)0xbfe001))&64)) break;    /* I know it's a hack */
  90.         Delay(5L);
  91.     }
  92.  
  93.     Fail("done"); /* Close the whole stuff */
  94. }
  95.  
  96.  
  97. Fail(text)
  98. char *text;
  99. {
  100.     if(ifffile) CloseIFF(ifffile);
  101.     if(myscreen) CloseScreen(myscreen);
  102.  
  103.     printf("%s\n",text);
  104.     printf("IffError = %ld\n",IffError());
  105.  
  106.     if(IFFBase) CloseLibrary(IFFBase);    /* MUST ALWAYS BE CLOSED !! */
  107.     CloseLibrary(IntuitionBase);
  108.     CloseLibrary(GfxBase);
  109.     exit(0);
  110. }
  111.  
  112.