home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / STK100.ZIP / STKSRC.COM / SPR_MISC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-20  |  3.8 KB  |  109 lines

  1. /**********************************************************************
  2. * spr_misc.c
  3. * Miscellaneous (internal) utility routines for the sprite support
  4. **********************************************************************
  5.                     This file is part of
  6.  
  7.           STK -- The sprite toolkit -- version 1.0
  8.  
  9.               Copyright (C) Jari Karjala 1990
  10.  
  11. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  12. resolution sprite graphics with PCompatible hardware. This toolkit 
  13. is provided as is without any warranty or such thing. See the file
  14. COPYING for further information.
  15.  
  16. **********************************************************************/
  17.  
  18.  
  19. #include "sprP.h"
  20.  
  21.  
  22. /**********************************************************************
  23. * Shift the given shape and mask bitmaps given number of bits to the
  24. * right and combine the result bytewise as required in sprite data
  25. * buffer.
  26. * shape   The original bitmap
  27. * mask    The original mask
  28. * step    The size of the step to the right in pixels (0-7)
  29. * shift   If zero then shape and mask are as wide as w (ie destination)
  30. * w       The width of the destination bitmap
  31. * h       The height of the bitmap
  32. * mask    Pad the result with ones if this is non-zero
  33. * bp      Pointer into the destination buffer
  34. **********************************************************************/
  35. static void shift_combine(BITMAP shape, BITMAP mask, 
  36.                           BYTE step, BYTE shift, BYTE w, BYTE h, FARMAP bp)
  37. {
  38.     WORD i,j;
  39.     BYTE mask1;
  40.     
  41.     mask1 = 0xFF << (8-step);
  42.  
  43.     if (shift)  /** shape/mask width is one less than given w **/
  44.         w--;
  45.     
  46.     for (j=0; j < h; j++) {         /* shift all scanlines */
  47.         *bp++ = *shape >> step;                 /* first shape byte */ 
  48.         *bp++ = (*mask >> step) | mask1;        /* first mask byte */
  49.         for (i=0; i < w-1; i++, shape++, mask++) {   /* next bytes */
  50.             *bp++ = (*shape << (8-step)) | (*(shape+1) >> step);
  51.             *bp++ = (*mask << (8-step)) | (*(mask+1) >> step);
  52.         }
  53.         if (shift) {    /** fix the shift overflow byte **/
  54.             *bp++ = (*shape << (8-step));
  55.             *bp++ = (*mask << (8-step)) | (0xFF >> step);
  56.         }
  57.         shape++;
  58.         mask++;
  59.     }
  60. }
  61.  
  62. /**********************************************************************
  63. * Create the shape data from the given shape and mask bitmaps
  64. * spr     The sprite used
  65. * shape   The shape bitmap
  66. * mask    The mask bitmap
  67. * res     The resolution used (1,2,4 or 8)
  68. **********************************************************************/
  69. void spr_misc_create_data(SPRITE spr, BITMAP shape, BITMAP mask)
  70. {
  71.     WORD size = spr->size, i;
  72.  
  73.     if (spr->res==1)
  74.         shift_combine(shape, mask, 0, 0, spr->w, spr->hp, spr->data);
  75.     else
  76.         for(i=0; i < spr->res; i++)
  77.             shift_combine(shape, mask, 
  78.                           (8/spr->res)*i,1, spr->w,spr->hp, spr->data+size*i);
  79. }
  80.  
  81. /**********************************************************************
  82. * Delete the given sprite from the display list for the given page.
  83. * Set the coordinates of the sprite to (WORD)-1,(WORD)-1
  84. * spr       The sprite to delete
  85. * spr_page  The page number (0/1)
  86. **********************************************************************/
  87. void spr_misc_delete(SPRITE spr, int spr_page)
  88. {
  89.     SPRITE s;
  90.     
  91.     spr->x = spr->y = (WORD)-1;
  92.     
  93.     s = spr_sprites[spr_page];
  94.     if (s==spr) /** it was the first one **/
  95.         spr_sprites[spr_page] = spr_sprites[spr_page]->next[spr_page];
  96.     else
  97.     while (s!=NULL) {
  98.         if (s->next[spr_page]!=NULL && s->next[spr_page]==spr) {
  99.             s->next[spr_page] = s->next[spr_page]->next[spr_page];
  100.             break;
  101.         }
  102.         s = s->next[spr_page];
  103.     }
  104. }
  105.