home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.1 / IFF / newiff39 / modules / getdisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  5.6 KB  |  220 lines

  1.  
  2. /*----------------------------------------------------------------------*
  3.  * GETDISPLAY.C  Support routines for reading/displaying ILBM files.
  4.  * (IFF is Interchange Format File.)
  5.  *
  6.  * Based on code by Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  * Modified for iffparse.library by CBM 04/90
  9.  * This version for the Commodore-Amiga computer.
  10.  *
  11.  * 37.9  04/92 - use vp->ColorMap->Count instead of MAXAMCOLORREG
  12.  * 37.10 07/92 - use scr->RastPort.BitMap instead of &scr->BitMap
  13.  *                      for future compatibility
  14.  * 39.1  07/92 - add support for V39 color loading
  15.  *----------------------------------------------------------------------*/
  16. #define INTUI_V36_NAMES_ONLY
  17.  
  18. #include "iffp/ilbm.h"
  19. #include "iffp/packer.h"
  20. #include "iffp/ilbmapp.h"
  21.  
  22. extern struct Library *GfxBase;
  23.  
  24. /* showilbm
  25.  *
  26.  * Passed an ILBMInfo initilized with with a not-in-use ParseInfo.iff
  27.  *   IFFHandle and desired propchks, collectchks, stopchks, and a filename,
  28.  *   will load and display an ILBM, initializing ilbm->Bmhd, ilbm->camg,
  29.  *   ilbm->scr, ilbm->win, ilbm->vp, ilbm->srp, ilbm->wrp,
  30.  *   ilbm->colortable, and ilbm->ncolors.
  31.  *
  32.  *   Note that ncolors may be more colors than you can LoadRGB4.
  33.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  34.  *   change the colors yourself using 1.3/2.0 functions.
  35.  *
  36.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  37.  *   color load under V39 and higher
  38.  *
  39.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  40.  */
  41.  
  42. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  43. {
  44. LONG error = 0L;
  45.  
  46.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  47.  
  48.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  49.     {
  50.     D(bug("showilbm: openifile successful\n"));
  51.  
  52.     error = parseifile((struct ParseInfo *)ilbm,
  53.                 ID_FORM, ID_ILBM,
  54.                 ilbm->ParseInfo.propchks,
  55.                 ilbm->ParseInfo.collectchks,
  56.                 ilbm->ParseInfo.stopchks);
  57.  
  58.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  59.         {
  60.         D(bug("showilbm: parseifile successful\n"));
  61.  
  62.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  63.         {
  64.             if(error = createdisplay(ilbm))
  65.             {
  66.             deletedisplay(ilbm);
  67.             }
  68.         }
  69.         else
  70.         {
  71.         message(SI(MSG_ILBM_NOILBM));
  72.         error = NOFILE;
  73.         }
  74.         }
  75.     if(error)    closeifile((struct ParseInfo *)ilbm);
  76.     }
  77.     return(error);
  78. }
  79.  
  80.  
  81. /* unshowilbm
  82.  *
  83.  * frees and closes everything alloc'd/opened by showilbm
  84.  * returns BOOL Success under V36 and above, always TRUE under <V36
  85.  */
  86. BOOL unshowilbm(struct ILBMInfo *ilbm)
  87. {
  88.     if(deletedisplay(ilbm))
  89.         {
  90.         closeifile((struct ParseInfo *)ilbm);
  91.         return(TRUE);
  92.         }
  93.     else return(FALSE);
  94. }
  95.  
  96.  
  97.  
  98. /* createdisplay
  99.  *
  100.  * Passed a initialized ILBMInfo with parsed IFFHandle (chunks parsed,
  101.  * stopped at BODY),
  102.  * opens/allocs the display and colortable, and displays the ILBM.
  103.  *
  104.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  105.  *   ilbm->vp,  ilbm->wrp, ilbm->srp and also ilbm->colortable and
  106.  *   ilbm->ncolors.
  107.  *
  108.  * Note that ncolors may be more colors than you can LoadRGB4.
  109.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  110.  *   change the colors yourself using 1.3/2.0 functions.
  111.  *
  112.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  113.  *   color load under V39 and higher
  114.  *
  115.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  116.  */
  117.  
  118. LONG createdisplay(struct ILBMInfo *ilbm)
  119.     {
  120.     LONG error;
  121.  
  122.     D(bug("createdisplay:\n"));
  123.  
  124.     error             = getdisplay(ilbm);
  125.  
  126.     D(bug("createdisplay: after getdisplay, error = %ld\n", error));
  127.  
  128.     if(!error) 
  129.         error     = loadbody(ilbm->ParseInfo.iff,
  130.                     ilbm->scr->RastPort.BitMap,&ilbm->Bmhd);
  131.  
  132.     D(bug("createdisplay: after loadbody, error = %ld\n", error));
  133.  
  134.     if(!error)
  135.         { 
  136.         if(!(getcolors(ilbm)))    setcolors(ilbm,ilbm->vp);
  137.         }
  138.     if(error)  deletedisplay(ilbm);
  139.     return(error);
  140.     }
  141.  
  142.  
  143. /* deletedisplay
  144.  *
  145.  * closes and deallocates created display and colors
  146.  * returns BOOL Success under V36 and above, always TRUE under <V36
  147.  */
  148. BOOL deletedisplay(struct ILBMInfo *ilbm)
  149.     {
  150.     if(freedisplay(ilbm))
  151.         {
  152.         freecolors(ilbm);
  153.         return(TRUE);
  154.         }
  155.     else return(FALSE);
  156.     }
  157.  
  158.  
  159.  
  160. /* getdisplay
  161.  *
  162.  * Passed an initialized ILBMInfo with a parsed IFFHandle (chunks parsed,
  163.  * stopped at BODY),
  164.  * gets the dimensions and mode for the display and calls the external
  165.  * routine opendisplay().  Our opendisplay() is in the screen.c
  166.  * module.  It opens a 2.0 or 1.3, ECS or non-ECS screen and window.
  167.  * It also does 2.0 overscan centering based on the closest user prefs.
  168.  *
  169.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  170.  *   ilbm->vp, ilbm->wrp, ilbm->srp
  171.  *
  172.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  173.  */
  174. LONG getdisplay(struct ILBMInfo *ilbm)
  175.     {
  176.     struct IFFHandle *iff;
  177.     BitMapHeader *bmhd;
  178.     ULONG                modeid;
  179.     UWORD                wide, high, deep;
  180.  
  181.  
  182.     if(!(iff=ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  183.  
  184.     if(!(bmhd = (BitMapHeader *)findpropdata(iff, ID_ILBM, ID_BMHD)))
  185.         {
  186.         message (SI(MSG_ILBM_NOBMHD));
  187.         return(IFFERR_SYNTAX);
  188.         }
  189.  
  190.     *(&ilbm->Bmhd)    = *bmhd;
  191.  
  192.         wide = (RowBytes(bmhd->w)) >= (RowBytes(bmhd->pageWidth)) ?
  193.                 bmhd->w : bmhd->pageWidth;
  194.         high = MAX(bmhd->h, bmhd->pageHeight);
  195.         deep = MIN(bmhd->nPlanes,MAXAMDEPTH);
  196.  
  197.     ilbm->camg = modeid = getcamg(ilbm);
  198.  
  199.     /*
  200.      * Open the display
  201.      */
  202.     if(!(opendisplay(ilbm,wide,high,deep,modeid)))
  203.         {
  204.         message(SI(MSG_ILBM_NODISPLAY));
  205.         return(1);
  206.         }
  207.     return(0);
  208.     }
  209.  
  210.  
  211. /* freedisplay
  212.  *
  213.  * closes and deallocates display from getdisplay (not colors)
  214.  * returns BOOL Success under V36 and above, always TRUE under <V36
  215.  */
  216. BOOL freedisplay(struct ILBMInfo *ilbm)
  217.     {
  218.     return(closedisplay(ilbm));
  219.     }
  220.