home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 390.lha / iff_library_v18.5 / Examples / EasyExample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-01  |  2.8 KB  |  108 lines

  1. /*
  2.     EasyExample.c - A simple ILBM file viewer by Christian A. Weber
  3.     This program is in the public domain, use at your own risk.
  4.     Requires the iff.library in the LIBS: dircetory. Compiles with
  5.     Lattice C V5.04 (LC -L EasyExample), should also work with Manx.
  6. */
  7.  
  8. #include <exec/types.h>
  9. #include <graphics/gfxbase.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/iff.h>            /* Our iff header file */
  12.  
  13. struct Library *IntuitionBase,*IFFBase, *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)"Simple ILBM viewer by Christian A. Weber", NULL, NULL
  20. };
  21.  
  22. struct Screen *myscreen, *OpenScreen();
  23. IFFFILE ifffile;
  24.  
  25. void SetOverscan(screen)        /* Adjust the screen position for overscan */
  26. register struct Screen *screen;
  27. {
  28.     register WORD rows = GfxBase->NormalDisplayRows;
  29.     register WORD x=screen->Width,y=screen->Height;
  30.     register struct ViewPort *vp=&(screen->ViewPort);
  31.  
  32.     if(rows>300) rows>>=1;
  33.     x -= 320;  if(vp->Modes & HIRES) x -= 320;
  34.     y -= rows; if(vp->Modes & LACE)  y -= rows;
  35.     x >>=1; if(x<0) x=0; y >>=1; if(y<0) y=0; if(y>40) y=40;
  36.     if(vp->Modes & HAM)    /* Correct overscan HAM color distortions */
  37.     {
  38.         if(GfxBase->ActiView->DxOffset-x < 96)
  39.             x=GfxBase->ActiView->DxOffset-96;
  40.     }
  41.     vp->DxOffset = -x; vp->DyOffset = -y;
  42.     RemakeDisplay();
  43. }
  44.  
  45. void Fail(text)
  46. char *text;
  47. {
  48.     printf("%s, IFFError = %ld\n",text,IFFError());
  49.  
  50.     if(ifffile) CloseIFF(ifffile);
  51.     if(myscreen) CloseScreen(myscreen);
  52.  
  53.     if(IFFBase) CloseLibrary(IFFBase);    /* MUST ALWAYS BE CLOSED !! */
  54.     CloseLibrary(IntuitionBase);
  55.     CloseLibrary(GfxBase);
  56.     exit(0);
  57. }
  58.  
  59. void main(argc,argv)
  60. int argc;
  61. char **argv;
  62. {
  63.     register LONG count,i;
  64.     struct BitMapHeader *bmhd;
  65.     UWORD colortable[128];
  66.  
  67.     if((argc != 2) || !strcmp(argv[1],"?")) {
  68.         printf("Format: %s filename\n",argv[0]);
  69.         exit(20);
  70.     }
  71.  
  72.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  73.     IntuitionBase = OpenLibrary("intuition.library",0L);
  74.  
  75.     if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
  76.         printf("Copy the iff.library to your LIBS: directory!\n");
  77.         exit(10);
  78.     }
  79.  
  80.     printf("Loading file %s ... ",argv[1]);
  81.  
  82.     if(!(ifffile=OpenIFF(argv[1]))) Fail("Error opening file");
  83.     if(!(bmhd=GetBMHD(ifffile)))    Fail("BitMapHeader not found");
  84.  
  85.     ns.Width      = bmhd->w;
  86.     ns.Height     = bmhd->h;
  87.     ns.Depth      = bmhd->nPlanes;
  88.     ns.ViewModes  = GetViewModes(ifffile);
  89.  
  90.     if(!(myscreen = OpenScreen(&ns))) Fail("Can't open screen!");
  91.     SetOverscan(myscreen);
  92.  
  93.     count = GetColorTab(ifffile,colortable);
  94.     if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
  95.     LoadRGB4(&(myscreen->ViewPort),colortable,count);
  96.  
  97.     if(!DecodePic(ifffile,&myscreen->BitMap)) Fail("Can't decode picture");
  98.  
  99.     for(i=0; i<100; ++i)
  100.     {
  101.         if(!((*((UBYTE*)0xbfe001))&64)) break; /* Don't use this in your code! */
  102.         Delay(5L);
  103.     }
  104.  
  105.     Fail("done"); /* Close down the whole stuff */
  106. }
  107.  
  108.