home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / drawiff.c < prev    next >
C/C++ Source or Header  |  1998-06-21  |  4KB  |  157 lines

  1. /** DrawIFF.c
  2.   *
  3.   *    NAME
  4.   *
  5.   * DrawIFF
  6.   * =======
  7.   *
  8.   *    SYNOPSIS
  9.   *
  10.   * DrawIFF(file, rp, x, y, width, height, screen)
  11.   *
  12.   *    FUNCTION
  13.   *
  14.   * This function opens an IFF ILBM file and draws it into a layered
  15.   * rastport, and changes the colors on the screen if the screen
  16.   * argument is given.
  17.   *
  18.   *    ARGUMENTS
  19.   *
  20.   * char *file  Name of IFF ILBM file
  21.   * struct RastPort *rp Destination rastport
  22.   * int x, y  Offset into destination rastport
  23.   * int width  Width of picture in destination rastport
  24.   * int height  Height of picture in destination rastport
  25.   * struct Screen *screen Pointer to screen receiving the colormap
  26.   *
  27.   *    ADDITIONAL CONSIDERATIONS
  28.   *
  29.   * This routine uses a lot of memory. The IFF file is read into ram,
  30.   * and a private RastPort is allocated the size of the picture before
  31.   * the picture is copied into the destination rastport. This routine
  32.   * uses the iff.library written by Werner Guenther.
  33.   *
  34.   *    BUGS
  35.   *
  36.   * None known.
  37.   *
  38.   *    AUTHOR/DATE
  39.   *   ============
  40.   *
  41.   *   W.G.J. Langeveld, 15 November 1988
  42.   *
  43.   *    CURRENT VERSION:
  44.   *
  45.   *    This version has been converted to SAS C 6.5 format. It has been modified
  46.   *    for modern definition sequences for ANSI compilation. This no longer works
  47.   *    with OS versions prior to 2.04.
  48.   *
  49.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  50.   *   ============
  51.   *
  52.   **/
  53.  
  54. #include <functions.h>
  55. #include "ralprotos.h"
  56. #include <exec/types.h>
  57. #include <exec/exec.h>
  58. #include <libraries/dos.h>
  59. #include <intuition/intuition.h>
  60. #include <graphics/gfxmacros.h>
  61. #include <devices/timer.h>
  62. #include <stdlib.h>
  63. #include <string.h>
  64. #include <ctype.h>
  65. #include <iff.h>
  66.  
  67. struct Library *IFFBase = NULL;
  68. /**
  69.  *
  70.  *   Function to draw an IFF file into a RastPort.
  71.  *
  72. **/
  73. int DrawIFF( char *file, struct RastPort *rp, int x, int y, int width, int height, struct Screen *screen )
  74. {
  75.     struct RastPort *trp = NULL, *AllocRastPort(), *FreeRastPort();
  76.     UWORD colortable[128];
  77.     struct BitMapHeader *bmhd = NULL;
  78.     ULONG count = 0L;
  79.     int picw = 0, picd = 0, pich = 0;
  80.     long picv = 0L;
  81.     APTR ifffile = NULL;
  82.     int result = 4;
  83.     
  84.     IFFBase = (struct Library *) OpenLibrary("iff.library", 0L);
  85.     if (IFFBase == NULL)
  86.         goto cleanup;
  87.     /*
  88.      *   Load the IFF file
  89.      */
  90.     if ((ifffile = IFFL_OldOpenIFF(file)) == NULL)
  91.         goto cleanup;
  92.     /*
  93.      *   Get bitmap header
  94.      */
  95.     result = 3;
  96.     if ((bmhd = IFFL_GetBMHD(ifffile)) == NULL)
  97.         goto cleanup;
  98.     
  99.     picw = bmhd->w;
  100.     if (width > picw)
  101.         width = picw;
  102.     if (width == 0)
  103.         width = picw;
  104.     
  105.     pich = bmhd->h;
  106.     if (height > pich)
  107.         height = pich;
  108.     if (height == 0)
  109.         height = pich;
  110.     
  111.     picd = bmhd->nPlanes;
  112.     picv = IFFL_GetViewModes(ifffile);
  113.     /*
  114.      *   Get a rastport of our own.
  115.      */
  116.     result = 2;
  117.     if ((trp = AllocRastPort(picd, picw, pich)) == NULL)
  118.         goto cleanup;
  119.     /*
  120.      *   If screen pointer is given, set colors as well.
  121.      */
  122.     if (screen) 
  123.     {
  124.         count = IFFL_GetColorTab(ifffile, (WORD *) colortable);
  125.         if (count > 32L)
  126.             count = 32L;
  127.         if (count)
  128.             LoadRGB4(&(screen->ViewPort), colortable, count);
  129.     }
  130.     /*
  131.      *   Put the picture in the bitmap.
  132.      */
  133.     result = 1;
  134.     if ((IFFL_DecodePic(ifffile, trp->BitMap)) == NULL)
  135.         goto cleanup;
  136.     /*
  137.      *   Copy the picture into the window.
  138.      */
  139.     ClipBlit(trp, 0L, 0L, rp, (long) x,     (long) y,
  140.     (long) width, (long) height, 0xCCL);
  141.     /*
  142.     BltBitMapRastPort(trp->BitMap, 0L, 0L, rp, (long) x,     (long) y,
  143.     (long) width, (long) height, 0xCCL);
  144.      */
  145.     result = 0;
  146.     
  147.     cleanup:
  148.     if (ifffile)
  149.         IFFL_CloseIFF(ifffile);
  150.     if (IFFBase)
  151.         CloseLibrary(IFFBase);
  152.     if (trp)
  153.         FreeRastPort(trp);
  154.     
  155.     return(result);
  156. }
  157.