home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / Devices / modules / getdisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  4.8 KB  |  195 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.  
  12. #include "iffp/ilbm.h"
  13. #include "iffp/packer.h"
  14. #include "iffp/ilbmapp.h"
  15.  
  16. extern struct Library *GfxBase;
  17.  
  18. /* showilbm
  19.  *
  20.  * Passed an ILBMInfo initilized with with a not-in-use ParseInfo.iff
  21.  *   IFFHandle and desired propchks, collectchks, stopchks, and a filename,
  22.  *   will load and display an ILBM, initializing ilbm->Bmhd, ilbm->camg,
  23.  *   ilbm->scr, ilbm->win, ilbm->vp, ilbm->srp, ilbm->wrp,
  24.  *   ilbm->colortable, and ilbm->ncolors.
  25.  *
  26.  *   Note that ncolors may be more colors than you can LoadRGB4.
  27.  *   Use MIN(ilbm->ncolors,MAXAMCOLORREG) for color count if you change
  28.  *   the colors yourself using 1.3/2.0 functions.
  29.  *
  30.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  31.  */
  32.  
  33. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  34. {
  35. LONG error = 0L;
  36.  
  37.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  38.  
  39.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  40.     {
  41.     D(bug("showilbm: openifile successful\n"));
  42.  
  43.     error = parseifile((struct ParseInfo *)ilbm,
  44.                 ID_FORM, ID_ILBM,
  45.                 ilbm->ParseInfo.propchks,
  46.                 ilbm->ParseInfo.collectchks,
  47.                 ilbm->ParseInfo.stopchks);
  48.  
  49.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  50.         {
  51.         D(bug("showilbm: parseifile successful\n"));
  52.  
  53.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  54.         {
  55.             if(error = createdisplay(ilbm))    deletedisplay(ilbm);
  56.         }
  57.         else
  58.         {
  59.         closeifile((struct ParseInfo *)ilbm);
  60.         message("Not an ILBM\n");
  61.         error = NOFILE;
  62.         }
  63.         }
  64.     }
  65.     return(error);
  66. }
  67.  
  68.  
  69. /* unshowilbm
  70.  *
  71.  * frees and closes everything alloc'd/opened by showilbm
  72.  */
  73. void unshowilbm(struct ILBMInfo *ilbm)
  74. {
  75.     deletedisplay(ilbm);
  76.     closeifile((struct ParseInfo *)ilbm);
  77. }
  78.  
  79.  
  80.  
  81. /* createdisplay
  82.  *
  83.  * Passed a initialized ILBMInfo with parsed IFFHandle (chunks parsed,
  84.  * stopped at BODY),
  85.  * opens/allocs the display and colortable, and displays the ILBM.
  86.  *
  87.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  88.  *   ilbm->vp,  ilbm->wrp, ilbm->srp and also ilbm->colortable and
  89.  *   ilbm->ncolors.
  90.  *
  91.  * Note that ncolors may be more colors than you can LoadRGB4.
  92.  * Use MIN(ilbm->ncolors,MAXAMCOLORREG) for color count if you change
  93.  *   the colors yourself using 1.3/2.0 functions.
  94.  *
  95.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  96.  */
  97.  
  98. LONG createdisplay(struct ILBMInfo *ilbm)
  99.     {
  100.     int error;
  101.  
  102.     D(bug("createdisplay:\n"));
  103.  
  104.     error             = getdisplay(ilbm);
  105.  
  106.     D(bug("createdisplay: after getdisplay, error = %ld\n", error));
  107.  
  108.     if(!error)     error     = loadbody(ilbm->ParseInfo.iff,
  109.                         &ilbm->scr->BitMap,&ilbm->Bmhd);
  110.  
  111.     D(bug("createdisplay: after loadbody, error = %ld\n", error));
  112.  
  113.     if(!error)
  114.         { 
  115.         if(!(getcolors(ilbm)))
  116.            LoadRGB4(ilbm->vp, ilbm->colortable,
  117.                 MIN(ilbm->ncolors,MAXAMCOLORREG));
  118.         }
  119.     if(error)  deletedisplay(ilbm);
  120.     return(error);
  121.     }
  122.  
  123.  
  124. /* deletedisplay
  125.  *
  126.  * closes and deallocates created display and colors
  127.  */
  128. void deletedisplay(struct ILBMInfo *ilbm)
  129.     {
  130.     freedisplay(ilbm);
  131.     freecolors(ilbm);
  132.     }
  133.  
  134.  
  135.  
  136. /* getdisplay
  137.  *
  138.  * Passed an initialized ILBMInfo with a parsed IFFHandle (chunks parsed,
  139.  * stopped at BODY),
  140.  * gets the dimensions and mode for the display and calls the external
  141.  * routine opendisplay().  Our opendisplay() is in the screen.c
  142.  * module.  It opens a 2.0 or 1.3, ECS or non-ECS screen and window.
  143.  * It also does 2.0 overscan centering based on the closest user prefs.
  144.  *
  145.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  146.  *   ilbm->vp, ilbm->wrp, ilbm->srp
  147.  *
  148.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  149.  */
  150. LONG getdisplay(struct ILBMInfo *ilbm)
  151.     {
  152.     struct IFFHandle *iff;
  153.     BitMapHeader *bmhd;
  154.     ULONG                modeid;
  155.     UWORD                wide, high, deep;
  156.  
  157.  
  158.     if(!(iff=ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  159.  
  160.     if(!(bmhd = (BitMapHeader *)findpropdata(iff, ID_ILBM, ID_BMHD)))
  161.         {
  162.         message ("No ILBM.BMHD chunk\n");
  163.         return(IFFERR_SYNTAX);
  164.         }
  165.  
  166.     *(&ilbm->Bmhd)    = *bmhd;
  167.  
  168.         wide = (RowBytes(bmhd->w)) >= (RowBytes(bmhd->pageWidth)) ?
  169.                 bmhd->w : bmhd->pageWidth;
  170.         high = MAX(bmhd->h, bmhd->pageHeight);
  171.         deep = MIN(bmhd->nPlanes,MAXAMDEPTH);
  172.  
  173.     ilbm->camg = modeid = getcamg(ilbm);
  174.  
  175.     /*
  176.      * Open the display
  177.      */
  178.     if(!(opendisplay(ilbm,wide,high,deep,modeid)))
  179.         {
  180.         message("Failed to open display.\n");
  181.         return(1);
  182.         }
  183.     return(0);
  184.     }
  185.  
  186.  
  187. /* freedisplay
  188.  *
  189.  * closes and deallocates display from getdisplay (not colors)
  190.  */
  191. void freedisplay(struct ILBMInfo *ilbm)
  192.     {
  193.     closedisplay(ilbm);
  194.     }
  195.