home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Sprite / c / MemSize next >
Encoding:
Text File  |  1993-07-11  |  2.4 KB  |  63 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Sprite.MemSize.c
  12.     Author:  Copyright © 1993 Tom Kirby-Green
  13.     Version: 1.00 (12 Jul 1993)
  14.     Purpose: Calculate the size in bytes of a sprite with the given parameters
  15. */
  16.  
  17.  
  18. #include "DeskLib:Sprite.h"
  19. #include "DeskLib:SWI.h"
  20.  
  21.  
  22. #define XOS_ReadModeVariable 0x20035
  23.  
  24. /* Macro to round a number of BITS up to a multiple of words */
  25. #define ROUND32(value) (((value) + 31) & ~31)
  26.  
  27.  
  28. extern int Sprite_MemorySize(int width, int height, int mode,
  29.                              spritemem_flags flags)
  30. {
  31.   int ncolours;          /* Maximum logical colour: 1, 3, 15 or 63    */
  32.   int log2bpp;           /* Log base 2 bits per pixel, i.e. 2^log2bpp */
  33.   int bpp;               /* Bits per pixel                            */
  34.   int bit_strlen;        /* Bit string length                         */
  35.   int size;              /* Memory requirements                       */
  36.  
  37.   SWI(2, 3, XOS_ReadModeVariable,             /* Get Log2BPP for mode */
  38.                  mode, 9,
  39.        /* TO */  NULL, NULL, &log2bpp );
  40.  
  41.   bpp = 1 << log2bpp;                /* Work out bits per pixel       */
  42.   bit_strlen = ROUND32(width * bpp); /* Initial bit string length,    *
  43.                                       * rounded up to nearest word    */
  44.  
  45.   bit_strlen >>= 3;                  /* Convert bits to bytes (/= 8)  */
  46.   size = bit_strlen * height;        /* Multiply by number of columns */
  47.  
  48.   if (flags & sprite_HASMASK)        /* Mask is just another chunk of */
  49.     size *= 2;                       /* same size as the sprite data  */
  50.                                      
  51.   size += sizeof( sprite_header);    /* Add on 44 bytes for header    */
  52.  
  53.   if (flags & sprite_HASPAL)         /* Add on size of palette        */
  54.   {
  55.     SWI(2, 3, XOS_ReadModeVariable,
  56.                    mode, 3,
  57.          /* TO */  NULL, NULL, &ncolours);
  58.     size += ( ncolours + 1 ) * ( sizeof( palette_entry ) * 2);
  59.   }
  60.  
  61.   return(size);
  62. }
  63.