home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 262.lha / IffLibrary_v1.3 / shopict.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  5.4 KB  |  216 lines

  1. #include <devices/printer.h>
  2. #include <intuition/intuition.h>
  3. #include "ifflib.h"
  4.  
  5. void *IntuitionBase, *GfxBase, *IFFBase;
  6.  
  7. struct NewScreen ns =
  8. {
  9. 0,0, 0,0, 0,  /* LE, TE, W, H, D */
  10. 0,0,          /* pns */
  11. 0,          /* ViewModes */
  12. CUSTOMSCREEN | SCREENBEHIND | SCREENQUIET, /* type */
  13. 0L,          /* font */
  14. (UBYTE *)"View",       /* title */
  15. 0L,          /* gadgets */
  16. 0L,          /* bitmap */
  17. };
  18.  
  19. struct NewWindow nw =
  20. {
  21. 0,0,0,0,       /* LE,TE,W,H */
  22. 0,0,           /* pns */
  23. RAWKEY | MOUSEBUTTONS,          /* IDCMP */
  24. SIMPLE_REFRESH | BACKDROP | BORDERLESS | ACTIVATE | RMBTRAP, /* flags */
  25. 0L,           /* Gadget */
  26. 0L,           /* checkmark */
  27. (UBYTE *)"",   /* title */
  28. 0L,           /* screen */
  29. 0L,           /* bitmap */
  30. 0,0,           /* min */
  31. 0,0,           /* max */
  32. CUSTOMSCREEN,  /* type */
  33. };
  34.  
  35. UWORD colors[4096];
  36. UWORD ncolors;
  37.  
  38. /*
  39. p(hdr)
  40. BitMapHeader *hdr;
  41. {
  42. printf("width: %d,  height: %d\n",hdr->w,hdr->h);
  43. printf("x: %d, y: %d\n",hdr->x,hdr->y);
  44. printf("nPlanes %d\n",(short)hdr->nPlanes);
  45. printf("masking: %d\n",(short)hdr->masking);
  46. printf("compression: %d\n",(short)hdr->compression);
  47. printf("transparentColor: %d\n",hdr->transparentColor);
  48. printf("xAspect: %d, yAspect:%d\n",
  49.    (short)hdr->xAspect,(short)hdr->yAspect);
  50. printf("pageWidth: %d, pageHeight: %d\n",
  51.    hdr->pageWidth,hdr->pageHeight);
  52.  
  53. if( hdr->viewmodes != GETVIEWMODES )
  54.    {
  55.    printf("ViewModes: 0");
  56.    if( hdr->viewmodes & PFBA ) printf("|PFBA");
  57.    if( hdr->viewmodes & DUALPF ) printf("|DUALPF");
  58.    if( hdr->viewmodes & HIRES ) printf("|HIRES");
  59.    if( hdr->viewmodes & LACE ) printf("|LACE");
  60.    if( hdr->viewmodes & HAM ) printf("|HAM");
  61.    if( hdr->viewmodes & VP_HIDE ) printf("|VP_HIDE");
  62.    if( hdr->viewmodes & GENLOCK_VIDEO ) printf("|GENLOCK_VIDEO");
  63.    if( hdr->viewmodes & GENLOCK_AUDIO ) printf("|GENLOCK_AUDIO");
  64.    if( hdr->viewmodes & EXTRA_HALFBRITE ) printf("|EXTRA_HALFBRITE");
  65.    printf("\n");
  66.    }
  67. }
  68.  
  69. pvp(s)
  70. struct Screen *s;
  71. {
  72. struct ViewPort *vp = &s->ViewPort;
  73.  
  74. printf("screen\nDxOffset: %d DyOffset: %d\n",vp->DxOffset,vp->DyOffset);
  75.  
  76. }
  77. */
  78.  
  79. void CleanPort(port)
  80. struct MsgPort *port;
  81. {
  82. extern void *GetMsg();
  83. struct IntuiMessage *msg;
  84. while( msg = GetMsg(port) ) ReplyMsg(msg);
  85. }
  86.  
  87. main(argc,argv)
  88. short argc;
  89. char *argv[];
  90. {
  91. extern void *OpenLibrary(), CloseLibrary();
  92. extern struct Window *OpenWindow();
  93. extern struct Screen *OpenScreen();
  94. extern struct ViewPort *ViewPortAddress();
  95. extern void *GetMsg();
  96. extern long Wait();
  97. extern long open_prtdev(), DumpRPort();
  98.  
  99. extern short QueryIFF();
  100. BitMapHeader hdr;
  101. struct IntuiMessage *i;
  102. struct Window *w = 0L;
  103. struct Screen *s = 0L;
  104. UWORD *clrs = colors, its_cool = 1, prt = 0;
  105. struct BitMap *bm;
  106.  
  107. if( argc > 1 )
  108.    {
  109.    if( !(GfxBase = OpenLibrary("graphics.library",0L)) )
  110.       goto abort;
  111.    if( !(IntuitionBase = OpenLibrary("intuition.library",0L)) )
  112.       goto abort;
  113.    if( !(IFFBase = OpenLibrary(IFFNAME,1L)) )
  114.       goto abort;
  115.  
  116.    hdr.viewmodes = GETVIEWMODES;
  117.  
  118.    if( !QueryIFF(argv[1],&hdr) )
  119.       {
  120.       /*p(&hdr); */
  121.  
  122.       ns.Width = hdr.pageWidth;
  123.       ns.Height = hdr.pageHeight;
  124.       ns.Depth = hdr.nPlanes;
  125.  
  126.       /* Most IFF pictures don't contain ViewModes,
  127.        * so the viewmodes variable will be un-changed.
  128.        * also older versions of the IFF.LIBRARY don't
  129.        * support the ViewModes variable.  */
  130.       if( hdr.viewmodes == GETVIEWMODES )
  131.      {
  132.      if( hdr.pageWidth > 384 && hdr.nPlanes < 5 ) ns.ViewModes |= HIRES;
  133.      if( hdr.pageHeight > 240 ) ns.ViewModes |= LACE;
  134.      if( hdr.nPlanes > 5 ) ns.ViewModes |= HAM;
  135.      }
  136.       else ns.ViewModes = hdr.viewmodes;
  137.  
  138.       /* open the screen */
  139.       if( !(s = OpenScreen(&ns)) )
  140.      goto abort;
  141.       /* pvp(s); */
  142.  
  143.       /* this piece of code handles over-scanned pictures */
  144.       if( ns.ViewModes & HIRES )
  145.      {
  146.      if( ns.Width > 640 ) s->ViewPort.DxOffset = -32;
  147.      }
  148.       else if( ns.Width > 320 ) s->ViewPort.DxOffset = -16;
  149.       if( ns.ViewModes & LACE )
  150.      {
  151.      if( ns.Height > 400 ) s->ViewPort.DyOffset = -32;
  152.      }
  153.       else if( ns.Height > 200 ) s->ViewPort.DyOffset = -16;
  154.       if( s->ViewPort.DxOffset || s->ViewPort.DyOffset ) RethinkDisplay();
  155.  
  156.       /* set up and open the new window */
  157.       bm = &s->BitMap;
  158.       nw.MaxWidth = nw.MinWidth = nw.Width = hdr.w;
  159.       nw.MinHeight = nw.MaxHeight = nw.Height = hdr.h;
  160.       nw.Screen = s;
  161.       if( !(w = OpenWindow(&nw)) )
  162.      goto abort;
  163.  
  164.       /* load the iff picture */
  165.       GetIFF_bitmap(argv[1],&bm,&clrs,&ncolors,0);
  166.  
  167.       /* load the colors into the screen's view port */
  168.       LoadRGB4(&s->ViewPort,clrs,(long)ncolors);
  169.  
  170.       /* bring the screen to the front */
  171.       ScreenToFront(s);
  172.  
  173.       /* input loop */
  174.       while(its_cool)
  175.      {
  176.      Wait(1L<<w->UserPort->mp_SigBit);
  177.      while( i = GetMsg(w->UserPort) )
  178.         {
  179.         if( i->Class == RAWKEY )
  180.            {
  181.            switch(i->Code)
  182.           {
  183.           case 0x40: its_cool = 0; break;
  184.           case 0x19: prt = 1; break;
  185.           default: break;
  186.           }
  187.            }
  188.         ReplyMsg(i);
  189.         }
  190.  
  191.      /* this part prints the picture if the user presses
  192.       * the 'P' key. */
  193.      if( prt )
  194.         {
  195.         if( !open_prtdev() )
  196.            {
  197.            DumpRPort(&s->RastPort,&s->ViewPort,(UWORD)0,(UWORD)0,
  198.            hdr.w,hdr.h,0L,0L,(UWORD)(SPECIAL_FULLCOLS|SPECIAL_FULLROWS));
  199.            close_prtdev();
  200.            prt = 0;
  201.            }
  202.         CleanPort(w->UserPort);
  203.         }
  204.      }
  205.       CleanPort(w->UserPort);
  206.       }
  207.  
  208.    abort:
  209.    if( w ) CloseWindow(w);
  210.    if( s ) CloseScreen(s);
  211.    if( IFFBase ) CloseLibrary(IFFBase);
  212.    if( IntuitionBase ) CloseLibrary(IntuitionBase);
  213.    if( GfxBase ) CloseLibrary(GfxBase);
  214.    }
  215. }
  216.