home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / drawimage.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  4KB  |  206 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: drawimage.c,v 1.8 1997/01/27 00:36:37 ldp Exp $
  4.     $Log: drawimage.c,v $
  5.     Revision 1.8  1997/01/27 00:36:37  ldp
  6.     Polish
  7.  
  8.     Revision 1.7  1996/12/10 14:00:02  aros
  9.     Moved #include into first column to allow makedepend to see it.
  10.  
  11.     Revision 1.6  1996/11/08 11:28:01  aros
  12.     All OS function use now Amiga types
  13.  
  14.     Moved intuition-driver protos to intuition_intern.h
  15.  
  16.     Revision 1.5  1996/10/24 15:51:18  aros
  17.     Use the official AROS macros over the __AROS versions.
  18.  
  19.     Revision 1.4  1996/10/04 15:33:43  digulla
  20.     Optimized: Draws now as many consecutive pixels as possible
  21.  
  22.     Revision 1.3  1996/09/18 14:43:42  digulla
  23.     Made DrawImage work
  24.     After OpenWindow() one *must* call Wait() to allow X11 to draw for now.
  25.  
  26.     Revision 1.2  1996/08/29 13:33:30  digulla
  27.     Moved common code from driver to Intuition
  28.     More docs
  29.  
  30.     Revision 1.1  1996/08/23 17:28:18  digulla
  31.     Several new functions; some still empty.
  32.  
  33.  
  34.     Desc:
  35.     Lang: english
  36. */
  37. #include "intuition_intern.h"
  38. #include <proto/graphics.h>
  39.  
  40. #define DEBUG 1
  41. #include <aros/debug.h>
  42. #include <proto/aros.h>
  43.  
  44. /*****************************************************************************
  45.  
  46.     NAME */
  47. #include <graphics/rastport.h>
  48. #include <intuition/intuition.h>
  49. #include <proto/intuition.h>
  50.  
  51.     AROS_LH4(void, DrawImage,
  52.  
  53. /*  SYNOPSIS */
  54.     AROS_LHA(struct RastPort *, rp, A0),
  55.     AROS_LHA(struct Image    *, image, A1),
  56.     AROS_LHA(LONG             , leftOffset, D0),
  57.     AROS_LHA(LONG             , topOffset, D1),
  58.  
  59. /*  LOCATION */
  60.     struct IntuitionBase *, IntuitionBase, 19, Intuition)
  61.  
  62. /*  FUNCTION
  63.     Draw an image.
  64.  
  65.     INPUTS
  66.     rp - The RastPort to render into
  67.     image - The image to render
  68.     leftOffset, topOffset - Where to place the image.
  69.  
  70.     RESULT
  71.     None.
  72.  
  73.     NOTES
  74.  
  75.     EXAMPLE
  76.  
  77.     BUGS
  78.  
  79.     SEE ALSO
  80.  
  81.     INTERNALS
  82.  
  83.     HISTORY
  84.     29-10-95    digulla automatically created from
  85.                 intuition_lib.fd and clib/intuition_protos.h
  86.  
  87. *****************************************************************************/
  88. {
  89.     AROS_LIBFUNC_INIT
  90.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  91.     ULONG   apen;
  92.     ULONG   drmd;
  93.     WORD    x, y, d, plane;
  94.     WORD    xoff, yoff;
  95.     UWORD * bits[24];
  96.     UWORD   bitmask;
  97.     UWORD   shift;
  98.     UWORD   offset;
  99.     ULONG   pen;
  100.     ULONG   lastPen;
  101. #define START_BITMASK    0x8000L
  102.  
  103.     /* Store important variables of the RastPort */
  104.     apen = GetAPen (rp);
  105.     drmd = GetDrMd (rp);
  106.  
  107.     /* Change RastPort to the mode I need */
  108.     SetDrMd (rp, JAM1);
  109.  
  110.     /* For all borders... */
  111.     for ( ; image; image=image->NextImage)
  112.     {
  113.     /* Use x to store size of one image plane */
  114.     x = ((image->Width + 15) >> 4) * image->Height;
  115.     y = 0;
  116.     shift = image->PlanePick;
  117.  
  118.     for (d=0; d < image->Depth; d++)
  119.     {
  120.         while (!(shift & 1) )
  121.         {
  122.         bits[y ++] = NULL;
  123.         shift >>= 1;
  124.         }
  125.  
  126.         bits[y ++] = image->ImageData + d * x;
  127.         shift >>= 1;
  128.     }
  129.  
  130.     offset    = 0;
  131.  
  132.     yoff = image->TopEdge + topOffset;
  133.  
  134.     for (y=0; y < image->Height; y++, yoff++)
  135.     {
  136.         bitmask = START_BITMASK;
  137.  
  138.         xoff = image->LeftEdge + leftOffset;
  139.  
  140.         for (x=0; x < image->Width; x++, xoff++)
  141.         {
  142.         pen = image->PlaneOnOff;
  143.         shift = 1;
  144.         plane = 0;
  145.  
  146.         for (d=0; d < image->Depth; d++)
  147.         {
  148.             while (!bits[plane])
  149.             {
  150.             plane ++;
  151.             shift <<= 1;
  152.             }
  153.  
  154.             pen |= (bits[plane][offset] & bitmask) ? shift : 0;
  155.  
  156.             plane ++;
  157.             shift <<= 1;
  158.         }
  159.  
  160. /* kprintf (" x=%2d y=%2d   offset=%3d bitmask=%04x bits[]=%04x pen=%d\n"
  161.     , x
  162.     , y
  163.     , offset
  164.     , bitmask
  165.     , bits[0][offset]
  166.     , pen
  167. ); */
  168.  
  169.         if (!x)
  170.         {
  171.             lastPen = pen;
  172.             Move (rp, xoff, yoff);
  173.         }
  174.  
  175.         if (pen != lastPen)
  176.         {
  177.             SetAPen (rp, lastPen);
  178.             Draw (rp, xoff, yoff);
  179.             lastPen = pen;
  180.         }
  181.  
  182.         bitmask >>= 1;
  183.  
  184.         if (!bitmask)
  185.         {
  186.             bitmask = START_BITMASK;
  187.             offset ++;
  188.         }
  189.         }
  190.  
  191.         SetAPen (rp, pen);
  192.         Draw (rp, xoff-1, yoff);
  193.  
  194.         if (bitmask != START_BITMASK)
  195.         offset ++;
  196.     }
  197.  
  198.     }
  199.  
  200.     /* Restore RastPort */
  201.     SetAPen (rp, apen);
  202.     SetDrMd (rp, drmd);
  203.  
  204.     AROS_LIBFUNC_EXIT
  205. } /* DrawImage */
  206.