#include <intuition/intuition.h>
#include "ifflib.h"

void *IntuitionBase, *GfxBase, *IFFBase;

struct NewScreen ns =
{
0,0, 0,0, 0,  /* LE, TE, W, H, D */
0,0,          /* pns */
0,            /* ViewModes */
CUSTOMSCREEN, /* type */
0L,           /* font */
(UBYTE *)"View",       /* title */
0L,           /* gadgets */
0L,           /* bitmap */
};

struct NewWindow nw =
{
0,0,0,0,       /* LE,TE,W,H */
0,0,           /* pns */
RAWKEY,        /* IDCMP */
SIMPLE_REFRESH | BACKDROP | BORDERLESS | ACTIVATE, /* flags */
0L,            /* Gadget */
0L,            /* checkmark */
(UBYTE *)"",   /* title */
0L,            /* screen */
0L,            /* bitmap */
0,0,           /* min */
0,0,           /* max */
CUSTOMSCREEN,  /* type */
};

UWORD colors[4096];
UWORD ncolors;

/* p(hdr)
BitMapHeader *hdr;
{
printf("width: %d,  height: %d\n",hdr->w,hdr->h);
printf("x: %d, y: %d\n",hdr->x,hdr->y);
printf("nPlanes %d\n",(short)hdr->nPlanes);
printf("masking: %d\n",(short)hdr->masking);
printf("compression: %d\n",(short)hdr->compression);
printf("transparentColor: %d\n",hdr->transparentColor);
printf("xAspect: %d, yAspect:%d\n",
   (short)hdr->xAspect,(short)hdr->yAspect);
printf("pageWidth: %d, pageHeight: %d\n",
   hdr->pageWidth,hdr->pageHeight);
}  */


main(argc,argv)
short argc;
char *argv[];
{
extern void *OpenLibrary(), CloseLibrary();
extern struct Window *OpenWindow();
extern struct Screen *OpenScreen();
extern struct ViewPort *ViewPortAddress();
extern void *GetMsg();
extern long Wait();

extern short QueryIFF();
BitMapHeader hdr;
struct ViewPort *vp;
struct IntuiMessage *i;
struct Window *w = 0L;
struct Screen *s = 0L;
UWORD *clrs = colors;
struct BitMap *bm;


if( !(GfxBase = OpenLibrary("graphics.library",0L)) )
   goto abort;
if( !(IntuitionBase = OpenLibrary("intuition.library",0L)) )
   goto abort;
if( !(IFFBase = OpenLibrary(IFFNAME,1L)) )
   goto abort;

if( argc > 1 )
   if( !QueryIFF(argv[1],&hdr) )
      {
      /* p(&hdr); */
      if( (ns.Width = hdr.pageWidth) > 320 )
         ns.ViewModes |= HIRES;
      if( (ns.Height = hdr.pageHeight) > 200 )
         ns.ViewModes |= LACE;
      if( (ns.Depth = hdr.nPlanes) > 5 )
         ns.ViewModes |= HAM;
      nw.MaxWidth = nw.MinWidth = nw.Width = hdr.w;
      nw.MinHeight = nw.MaxHeight = nw.Height = hdr.h;
      if( !(s = OpenScreen(&ns)) )
         goto abort;
      bm = &s->BitMap;
      nw.Screen = s;
      if( !(w = OpenWindow(&nw)) )
         goto abort;
      ShowTitle(s,0L);
      GetIFF_bitmap(argv[1],&bm,&clrs,&ncolors,0);
      vp = ViewPortAddress(w);
      LoadRGB4(vp,clrs,(long)ncolors);
      Wait(1L<<w->UserPort->mp_SigBit);
      while( i = GetMsg(w->UserPort) )
         ReplyMsg(i);
      }

abort:
if( w ) CloseWindow(w);
if( s ) CloseScreen(s);
if( IFFBase ) CloseLibrary(IFFBase);
if( IntuitionBase ) CloseLibrary(IntuitionBase);
if( GfxBase ) CloseLibrary(GfxBase);
}
