home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 302.lha / ILBMLib / ShowPic.c < prev    next >
C/C++ Source or Header  |  1980-12-03  |  8KB  |  252 lines

  1. /* Ilbm.library C application:
  2.  
  3.    cc +p ShowPic.c
  4.    as -cd FileInterface.asm
  5.    as -cd IlbmInterface.asm
  6.    ln -o ShowPic ShowPic.o FileInterface.o IlbmInterface.o -lc32 
  7. */
  8.  
  9. #include "math.h"
  10. #include "functions.h"    /* Manx C declarations */
  11. #include "intuition/intuition.h"
  12.  
  13. #include "exec/tasks.h"
  14. #include "exec/types.h"
  15. #include "exec/memory.h"
  16. #include "graphics/gfxbase.h"
  17. #include "graphics/rastport.h"
  18. #include "graphics/gfx.h"
  19. #include "graphics/view.h"
  20. #include "graphics/text.h"
  21. #include "intuition/intuitionbase.h"
  22.  
  23.  /* These INCLUDE files come with the ilbm and requester libs */
  24. #include "ILBM_Lib.h"
  25. #include "FileIO.h"
  26.  
  27.  
  28. /*-------------------------------defines---------------------------------*/
  29.  
  30. #define INTUITION_REV 33L
  31. #define GRAPHICS_REV  33L
  32. #define DEPTH         4
  33.  
  34.  
  35. struct IntuitionBase *IntuitionBase=0L;
  36. struct GfxBase       *GfxBase=0L;
  37. struct Window        *back_wind=0L;
  38. struct Screen        *main_scrn=0L;
  39.  
  40.  /* Data for the Dissidents Requester library */
  41. struct RequesterBase *RequesterBase=0L;
  42. struct FileIO        *myFileIO=0L;
  43.  
  44.  /* Data for the Dissidents ILBM library */
  45. struct ILBMBase      *ILBMBase=0L;
  46. struct ILBMFrame     myILBMFrame;
  47.  
  48. struct TextAttr my_font_attr={(UBYTE *)"topaz.font",TOPAZ_EIGHTY,\
  49.                          FS_NORMAL, FPF_ROMFONT};
  50.  
  51. struct NewScreen ns={0,0,640,200, DEPTH, 0,1, HIRES,
  52.           SCREENBEHIND | CUSTOMSCREEN, &my_font_attr, (UBYTE *)"Screen",
  53.           NULL, NULL };
  54.  
  55. struct NewWindow b_nw={0,0,640,200, -1,-1, GADGETDOWN | RAWKEY |\
  56.                      GADGETUP | MENUPICK | MOUSEMOVE,
  57.                      SMART_REFRESH | ACTIVATE | BACKDROP |\
  58.                      WINDOWDEPTH | REPORTMOUSE | BORDERLESS,
  59.                      NULL, NULL, (UBYTE *)"Background Window", NULL,NULL,
  60.                      640,200,640,200, CUSTOMSCREEN};
  61.  
  62.  
  63. VOID open_all(), damp_mop();
  64.  
  65. /*------------------------------start of main()----------------------------*/
  66.  
  67. main( argc, argv )
  68. LONG argc;
  69. UBYTE *argv[];
  70. {
  71.    UBYTE *string;
  72.    IFFP  Result;
  73.    struct IntuiMessage *mes;
  74.  
  75.    ULONG secs=250; /* Display for 5 secs */
  76.  
  77.  /* We expect at least the filename for the first arg. Optionally, any
  78.     additional arg is perceived as a flag to trigger resaving the picture
  79.     as it appears in this window. */
  80.    if( argc > 3 || argc < 2 )
  81.    {
  82.       printf("USAGE: ShowPic filename [resave]\n");
  83.       exit();
  84.    }
  85.  
  86.    open_all();
  87.  
  88.  /* The FileIO is for the file requester lib. See Fish Disc #203 for the
  89.     documentation and examples */
  90.    if( (myFileIO = GetFileIO()) == NULL) damp_mop();
  91.    myFileIO->X = 6;
  92.    myFileIO->Y = 11;
  93.    myFileIO->DrawMode = JAM2;
  94.    myFileIO->PenA = 0;
  95.    myFileIO->PenB = 1;
  96.  
  97.  /* We can open our own window/screen and load pictures there by setting
  98.     the ILBMFrame's iWindow and iScreen fields to this address. Any pic
  99.     that is larger than our window/screen dimensions will be scaled to
  100.     fit. Also, any picture intended for a different view mode than our
  101.     screen (or with more colors) may come out "weird". The main advantage
  102.     of loading into an open window is that we are certain what dimensions
  103.     the screen/window will be. If you had a program which loaded a company
  104.     logo in an IFF ILBM FORM when it started, you would certainly make sure
  105.     that the ILBM file was the proper dimensions for your opened screen.
  106.     In a dissidents product, SpeakerSim, there is a feature for loading in
  107.     an ILBM beneath the speaker plot graph. Since the mouse coordinates
  108.     figure prominantly in obtaining info from the user, it would have been
  109.     too much overhead to tailor all functions to work in both HIRES, LORES,
  110.     and INTERLACE simultaneously. So, there are several "versions" of
  111.     SpeakerSim, each one's graphing routines optimized for the dimensions
  112.     of the main screen. Since the ILBM is meant to be a low-key, background
  113.     beneath the speaker plot, the picture is scaled to fit. Obviously, its
  114.     best to load an ILBM that fits that version of SpeakerSim, but the em-
  115.     phasis is on the graphing, not the background. This is an example of why
  116.     you might load into an existing window.
  117.     Otherwise, we could have the lib open an appropriately sized
  118.     backdrop window/screen by setting iWindow and iScreen to 0. In this
  119.     case, the lib will place the addresses in the ILBMFrame fields. We
  120.     could then do a ModifyIDCMP after the load. Eventually, we'll have
  121.     to CloseWindow and CloseScreen. With this method, the image is never
  122.     scaled (currently the lib doesn't allow for overscan images) as long
  123.     the pic's BMHD w=pageWidth and h=pageHeight, and the image is a standard
  124.     amiga screen dimension. Unfortunately, you won't know whether you have
  125.     a HAM, LORES, HIRES, etc until after the load.
  126.  
  127.     Both options are shown here. First the picture is loaded into a
  128.     640 by 200, HIRES screen with 4 bitplanes. If you load a LORES pic
  129.     it will scale to fill the screen. If that pic has > 16 colors, some colors
  130.     may not look right. If you load a pic with > 4 planes, it may also
  131.     look weird. If you load a 640by200 pic with 4 planes, it will look
  132.     just right. Next the window/screen is closed, and the picture is
  133.     reloaded with the lib opening a window/screen for us. No scaling.
  134.     Lastly, if you supplied a 2nd arg on the CLI line, it will simply
  135.     resave the picture. This is just for the sake of demonstration. */
  136.  
  137.    if((main_scrn=(struct Screen *)OpenScreen(&ns)) == NULL) damp_mop();
  138.    b_nw.Screen=main_scrn;
  139.    if((back_wind=(struct Window *)OpenWindow(&b_nw)) == NULL) damp_mop();
  140.    ScreenToFront(main_scrn);
  141.  
  142.    myILBMFrame.iScreen = main_scrn;
  143.    myILBMFrame.iWindow = back_wind;
  144.    myILBMFrame.iUserFlags = 3;     /* no pointer, and hidden title bar */
  145.  
  146.    Result=LoadIFFToWindow( argv[1], &myILBMFrame );
  147.    if( !Result )
  148.       Delay( secs );
  149.    else
  150.       {
  151.    /* Get the IFFP error message and display it in a auto requester */
  152.       string=GetIFFPMsg( Result );
  153.       AutoMessage( string, back_wind );
  154.       }
  155.  
  156.  if(back_wind)
  157.  {                /* drain the IDCMP */
  158.    while( mes=(struct IntuiMessage *)GetMsg(back_wind->UserPort))
  159.      ReplyMsg(mes);
  160.    CloseWindow( back_wind );
  161.    back_wind=0;
  162.  }
  163.  
  164.  if( main_scrn )     CloseScreen( main_scrn );
  165.  main_scrn=0;
  166.  
  167.    /* Now the lib opens the window for us */
  168.    myILBMFrame.iScreen = 0;
  169.    myILBMFrame.iWindow = 0;
  170.    myILBMFrame.iUserFlags = 3;     /* no pointer, and hidden title bar */
  171.  
  172.    Result=LoadIFFToWindow( argv[1], &myILBMFrame );
  173.    if( !Result )
  174.       {
  175.       Delay( secs );
  176.       main_scrn=myILBMFrame.iScreen;
  177.       back_wind=myILBMFrame.iWindow;
  178.       }
  179.    else
  180.       {
  181.    /* Get the IFFP error message and display it in a auto requester */
  182.       string=GetIFFPMsg( Result );
  183.       AutoMessage( string, back_wind );
  184.       }
  185.  
  186.    if( argv[2] )
  187.    {
  188.       if( SaveWindowToIFF( argv[1], back_wind ))
  189.          AutoMessage("Save OK", back_wind );
  190.       else
  191.          AutoMessage("Save error", back_wind );
  192.    }
  193.  
  194.    damp_mop();
  195.  
  196. }          /* end of main() */
  197.  
  198.  
  199. /*---------opens Intuition, graphics, requester, and ilbm libs--------*/
  200.  
  201. VOID open_all()
  202. {
  203.  
  204.  if( (IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library", INTUITION_REV)) == NULL )
  205.     damp_mop();
  206.  
  207.  if( (GfxBase=(struct GfxBase *)OpenLibrary("graphics.library", GRAPHICS_REV)) == NULL )
  208.     damp_mop();
  209.  
  210.  if( (RequesterBase=(struct RequesterBase *)OpenLibrary("requester.library", 0L)) == NULL )
  211.    {
  212.     printf("Need the dissidents requester.library on boot disk\n");
  213.     damp_mop();
  214.    }
  215.  
  216.  if( (ILBMBase=(struct ILBMBase *)OpenLibrary("ilbm.library", 0L)) == NULL )
  217.    {
  218.     printf("Need the dissidents ilbm.library on boot disk\n");
  219.     damp_mop();
  220.    }
  221. }
  222.  
  223.  
  224. /*---------------closes windows, screen, libs---------------*/
  225.  
  226. VOID damp_mop()
  227. {
  228.  struct IntuiMessage *mes;
  229.  
  230.  if( RequesterBase )
  231.  {
  232.  ReleaseFileIO( myFileIO ); /* ReleaseFileIO checks for myFileIO==NULL */
  233.  }
  234.  
  235.  if(back_wind)
  236.  {                /* drain the IDCMP */
  237.    while( mes=(struct IntuiMessage *)GetMsg(back_wind->UserPort))
  238.      ReplyMsg(mes);
  239.    ClearMenuStrip( back_wind );
  240.    CloseWindow( back_wind );
  241.  }
  242.  
  243.  if( main_scrn )     CloseScreen( main_scrn );
  244.  if( ILBMBase )      CloseLibrary( ILBMBase );
  245.  if( RequesterBase ) CloseLibrary( RequesterBase );
  246.  if( GfxBase )       CloseLibrary( GfxBase );
  247.  if( IntuitionBase ) CloseLibrary( IntuitionBase );
  248.  
  249.  exit(FALSE);
  250.  
  251. }
  252.