home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / BlitPixie / Headers / BlitPixieHeader.h < prev    next >
Encoding:
Text File  |  2000-10-06  |  15.7 KB  |  459 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    BlitPixieHeader.h
  3. //        general header for BlitPixie, a collection of fast software blitters
  4. ///--------------------------------------------------------------------------------------
  5.  
  6. #ifndef __BLITPIXIE__
  7. #define __BLITPIXIE__
  8.  
  9. #include "BlitPixieSystem.h"        // various system-dependant type definitions
  10.  
  11. #ifndef BLITPIXIE_DEBUG                // remove debugger calls, if not debugging (release code)
  12. #undef BLITPIXIE_DEBUGGER
  13. #define BLITPIXIE_DEBUGGER(x)
  14. #endif /* BLITPIXIE_DEBUG */
  15.  
  16. #ifndef BLITPIXIE_ASSERT            // debugging assertion
  17. #define BLITPIXIE_ASSERT(x) if (!(x)) { BLITPIXIE_DEBUGGER("Assertion failed: " #x " (" __FILE__ ")"); }
  18. #endif /* BLITPIXIE_ASSERT */
  19.  
  20. #include "BlitPixieVersion.h"        // library version
  21.  
  22. ///--------------------------------------------------------------------------------------
  23. //    Type definitions and structs
  24. ///--------------------------------------------------------------------------------------
  25.  
  26.     // The following struct is used by BlitPixieDoubleRects.
  27. struct BlitPixieOffsetInfo
  28. {
  29.     long     srcOffsetAtoB;    /* offset from right of rect A to left of rect B */
  30.     long     srcOffsetBtoA;    /* offset from right of rect B to left of rect A, in the next row */
  31.     long     dstOffsetAtoB;
  32.     long     dstOffsetBtoA;
  33. };
  34.  
  35. typedef struct BlitPixieOffsetInfo    BlitPixieOffsetInfo, *BlitPixieOffsetInfoPtr;
  36.  
  37.     // which kind of CPU we're running on, see BlitPixieGetProcessorType
  38. extern short    gBlitPixieProcessorType;
  39.  
  40.     // The following is used by the blitters, for optimal performance
  41. enum BlitPixieProcessorTypes
  42. {
  43.     kUnknownProcessor = 0,
  44.  
  45.     // 68k Processors
  46.     k68000,        
  47.     k68010,
  48.     k68020,
  49.     k68030,
  50.     k68040,
  51.  
  52.     // PPC Processors
  53.     k601,        
  54.     k603,
  55.     k604,
  56.     kG3,
  57.     kG4
  58. };
  59.  
  60.  
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64.  
  65. ///--------------------------------------------------------------------------------------
  66. //    Library functions
  67. ///--------------------------------------------------------------------------------------
  68.  
  69.     // get numeric version
  70. unsigned long BlitPixieVersion( void );
  71.  
  72.     // get string version
  73. void BlitPixieVersionString( char string[BLITPIXIE_VERSION_STRINGLEN] );
  74.  
  75.     // call this function once at startup
  76. void BlitPixieGetProcessorType(void);
  77.  
  78. ///--------------------------------------------------------------------------------------
  79. //    utility functions, for C blitters to use
  80. ///--------------------------------------------------------------------------------------
  81.  
  82.     // copy a block of memory, using longwords
  83. void BlitPixieMemCopy( unsigned char *dst, unsigned char *src, int bytes);
  84.  
  85.     // set a block of memory to a repeated longword value
  86. void BlitPixieMemSet( unsigned char *dst, unsigned long value, int bytes );
  87.  
  88. ///--------------------------------------------------------------------------------------
  89. //    Blitters that work in 8-bits, 16-bits, and 32-bits
  90. ///--------------------------------------------------------------------------------------
  91.  
  92. void BlitPixieClear(
  93.     unsigned char *dstPixel,        unsigned long dstRowBytes,    
  94.     unsigned short bytes,            unsigned short rows,        
  95.     unsigned long color);
  96.  
  97. void BlitPixieRect(
  98.     unsigned char *srcPixel,        unsigned char *dstPixel,
  99.     unsigned long srcRowBytes,        unsigned long dstRowBytes,        
  100.     unsigned short bytes,            unsigned short rows );
  101.  
  102. void BlitPixieDoubleRects(
  103.     unsigned char *src,                unsigned char *dst,
  104.     unsigned short bytesA,            unsigned short bytesB,
  105.     unsigned short rows,            BlitPixieOffsetInfo *info );
  106.  
  107.  
  108. void BlitPixieBlitClear(
  109.     unsigned char *src,                unsigned char *dst,                unsigned long color,
  110.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  111.     unsigned short bytes,            unsigned short rows);
  112.  
  113. void BlitPixieBlitErase(
  114.     unsigned char *src,                unsigned char *dst,                unsigned char *background,
  115.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  116.     unsigned short bytes,            unsigned short rows);
  117.  
  118.  
  119. void BlitPixieMask(
  120.     unsigned char *srcPixel,        unsigned char *dstPixel,        unsigned char *maskPixel,
  121.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  122.     unsigned short bytes,            unsigned short rows );
  123.  
  124. void BlitPixiePartialMask(
  125.     unsigned char *srcPixel,        unsigned char *dstPixel,        unsigned char *maskPixel,
  126.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  127.     unsigned short bytes,            unsigned short rows );
  128.  
  129. void BlitPixieMaskColor(
  130.     unsigned long srcColor,            unsigned char *dstPixel,        unsigned char *maskPixel,
  131.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  132.     unsigned short bytes,            unsigned short rows );
  133.  
  134. Boolean BlitPixieMaskCollision(
  135.     unsigned char *maskPtr1,        unsigned char *maskPtr2,    
  136.     unsigned long rowBytes1,        unsigned long rowBytes2,
  137.     unsigned short bytes,            unsigned short rows );
  138.  
  139.  
  140. ///--------------------------------------------------------------------------------------
  141. //    Blitters that have different routines for different bit depths
  142. ///--------------------------------------------------------------------------------------
  143.  
  144. void BlitPixieColorKey8Bit(
  145.     unsigned char *srcPixel,        unsigned char *dstPixel,            
  146.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  147.     unsigned short bytes,            unsigned short rows,                
  148.     unsigned char colorKey);
  149.  
  150. void BlitPixieColorKey16Bit(
  151.     unsigned short *srcPixel,        unsigned short *dstPixel,            
  152.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  153.     unsigned short bytes,            unsigned short rows,                
  154.     unsigned short colorKey);
  155.  
  156. void BlitPixieColorKey32Bit(
  157.     unsigned long *srcPixel,        unsigned long *dstPixel,            
  158.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  159.     unsigned short bytes,            unsigned short rows,                
  160.     unsigned long colorKey);
  161.  
  162.  
  163. void BlitPixieFlip8Bit(
  164.     unsigned char *srcPixel,        unsigned char *dstPixel,
  165.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  166.     unsigned short width,            unsigned short height);
  167.  
  168. void BlitPixieFlip16Bit(
  169.     unsigned short *srcPixel,        unsigned short *dstPixel,
  170.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  171.     unsigned short width,            unsigned short height);
  172.  
  173. void BlitPixieFlip32Bit(
  174.     unsigned long *srcPixel,        unsigned long *dstPixel,
  175.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  176.     unsigned short width,            unsigned short height);
  177.  
  178.  
  179. void BlitPixieFlipMask8Bit(
  180.     unsigned char *srcPixel,        unsigned char *dstPixel,        unsigned char *maskPixel,
  181.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  182.     unsigned short width,            unsigned short height);
  183.  
  184. void BlitPixieFlipMask16Bit(
  185.     unsigned short *srcPixel,        unsigned short *dstPixel,        unsigned short *maskPixel,
  186.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  187.     unsigned short width,            unsigned short height);
  188.  
  189. void BlitPixieFlipMask32Bit(
  190.     unsigned long *srcPixel,        unsigned long *dstPixel,        unsigned long *maskPixel,
  191.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  192.     unsigned short width,            unsigned short height);
  193.  
  194. Boolean BlitPixieFlipMaskCollision(
  195.     unsigned char *maskPtr1,        unsigned char *maskPtr2,    
  196.     unsigned long rowBytes1,        unsigned long rowBytes2,
  197.     unsigned short bytes,            unsigned short rows );
  198.  
  199. void BlitPixieFlipMaskColor(
  200.     unsigned long srcColor,            unsigned char *dstPixel,        unsigned char *maskPixel,
  201.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  202.     unsigned short bytes,            unsigned short rows );
  203.  
  204.  
  205. void BlitPixieDoubled8Bit(
  206.     unsigned char *srcPixel,        unsigned char *dstPixel,
  207.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  208.     unsigned short width,            unsigned short height);
  209.  
  210. void BlitPixieDoubled16Bit(
  211.     unsigned short *srcPixel,        unsigned short *dstPixel,
  212.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  213.     unsigned short width,            unsigned short height);
  214.  
  215. void BlitPixieDoubled32Bit(
  216.     unsigned long *srcPixel,        unsigned long *dstPixel,
  217.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  218.     unsigned short width,            unsigned short height);
  219.  
  220.  
  221. void BlitPixieScale8Bit(
  222.     unsigned char *src,    unsigned long srcBytes,    long width1, long height1, long startu,
  223.     unsigned char *dst,    unsigned long dstBytes,    long width2, long height2, long startv );
  224.  
  225. void BlitPixieScaleMask8Bit(
  226.     unsigned char *src,    unsigned long srcBytes,    long width1, long height1, long startu,
  227.     unsigned char *dst,    unsigned long dstBytes,    long width2, long height2, long startv,
  228.     unsigned char *mask );
  229.  
  230. void BlitPixieScale16Bit(
  231.     unsigned short *src, unsigned long srcBytes, long width1, long height1, long startu,
  232.     unsigned short *dst, unsigned long dstBytes, long width2, long height2, long startv );
  233.  
  234. void BlitPixieScaleMask16Bit(
  235.     unsigned short *src, unsigned long srcBytes, long width1, long height1, long startu,
  236.     unsigned short *dst, unsigned long dstBytes, long width2, long height2, long startv,
  237.     unsigned short *mask );
  238.  
  239. void BlitPixieScale32Bit(
  240.     unsigned long *src,    unsigned long srcBytes,    long width1, long height1, long startu,
  241.     unsigned long *dst,    unsigned long dstBytes,    long width2, long height2, long startv );
  242.  
  243. void BlitPixieScaleMask32Bit(
  244.     unsigned long *src,    unsigned long srcBytes,    long width1, long height1, long startu,
  245.     unsigned long *dst,    unsigned long dstBytes,    long width2, long height2, long startv,
  246.     unsigned long *mask );
  247.  
  248.  
  249. void BlitPixieRotoZoom8Bit(
  250.     unsigned char *srcPixel,        unsigned char *dstPixel,
  251.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  252.     unsigned long width1,            unsigned long height1,        
  253.     unsigned long width2,            unsigned long height2,
  254.     unsigned long angle,            unsigned long zoom    );
  255.  
  256. void BlitPixieMaskRotoZoom8Bit(
  257.     unsigned char *srcPixel,        unsigned char *dstPixel,        unsigned char *maskPixel,
  258.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  259.     unsigned long width1,            unsigned long height1,        
  260.     unsigned long width2,            unsigned long height2,
  261.     unsigned long angle,            unsigned long zoom    );
  262.  
  263. void BlitPixieRotoZoom16Bit(
  264.     unsigned short *srcPixel,        unsigned short *dstPixel,
  265.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  266.     unsigned long width1,            unsigned long height1,        
  267.     unsigned long width2,            unsigned long height2,
  268.     unsigned long angle,            unsigned long zoom    );
  269.  
  270. void BlitPixieMaskRotoZoom16Bit(
  271.     unsigned short *srcPixel,        unsigned short *dstPixel,        unsigned short *maskPixel,
  272.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  273.     unsigned long width1,            unsigned long height1,        
  274.     unsigned long width2,            unsigned long height2,
  275.     unsigned long angle,            unsigned long zoom    );
  276.  
  277. void BlitPixieRotoZoom32Bit(
  278.     unsigned long *srcPixel,        unsigned long *dstPixel,
  279.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  280.     unsigned long width1,            unsigned long height1,        
  281.     unsigned long width2,            unsigned long height2,
  282.     unsigned long angle,            unsigned long zoom    );
  283.  
  284. void BlitPixieMaskRotoZoom32Bit(
  285.     unsigned long *srcPixel,        unsigned long *dstPixel,        unsigned long *maskPixel,
  286.     unsigned long srcRowBytes,        unsigned long dstRowBytes,
  287.     unsigned long width1,            unsigned long height1,        
  288.     unsigned long width2,            unsigned long height2,
  289.     unsigned long angle,            unsigned long zoom    );
  290.  
  291. ///--------------------------------------------------------------------------------------
  292. //    zero-overdraw dirty rect screen blitter, works in 8-bits, 16-bits, and 32-bits
  293. ///--------------------------------------------------------------------------------------
  294.  
  295. Boolean BlitPixieInitDirtyRects(
  296.     unsigned char *src,
  297.     unsigned char *dst,
  298.     unsigned short width,
  299.     unsigned short height,
  300.     unsigned short depth);
  301.  
  302. void BlitPixieAddDirtyRect(
  303.     Rect *dirtyRect );
  304.  
  305. void BlitPixieClearDirtyRects(void);
  306.  
  307. void BlitPixieExitDirtyRects(void);
  308.  
  309.  
  310. void BlitPixieBlitClearDirtyRects(
  311.     unsigned char *src,            unsigned char *dst,            unsigned long color,
  312.     unsigned long srcRowBytes,    unsigned long dstRowBytes);
  313.  
  314. void BlitPixieBlitEraseDirtyRects(
  315.     unsigned char *src,            unsigned char *dst,            unsigned char *background,
  316.     unsigned long srcRowBytes,    unsigned long dstRowBytes);
  317.  
  318. ///--------------------------------------------------------------------------------------
  319. //    pre-generated RLE tokens blitter, works in 8-bits, 16-bits, and 32-bits
  320. ///--------------------------------------------------------------------------------------
  321.  
  322. #define BLITPIXIE_USE_DRAW_SPANS     1    // whether to use spans of single color ?
  323.  
  324. typedef unsigned long                TokenDataType, *TokenDataPtr, **TokenDataHdl;
  325. #define kTokenShift                    24
  326. #define kCountMask                    0x00FFFFFFL
  327.  
  328. #define kEndShapeToken                0x00L
  329. #define kLineStartToken                0x01L
  330. #define kDrawPixelsToken            0x02L
  331. #define kSkipPixelsToken            0x03L
  332. #if BLITPIXIE_USE_DRAW_SPANS
  333. #define kSingleColorToken            0x04L // (this token not used in the original code)
  334. #endif
  335.  
  336. void BlitPixieRLE(
  337.     unsigned char *srcTokens,
  338.     unsigned char *dstPixel,        unsigned long dstRowBytes);
  339.  
  340. void BlitPixieRLEClipped(
  341.     unsigned char *srcTokens,
  342.     unsigned char *dstPixel,        unsigned long dstOffset,
  343.     Rect *dstClipRect);
  344.  
  345. void BlitPixieRLEColor(
  346.     unsigned char *srcTokens,        unsigned long srcColor,
  347.     unsigned char *dstPixel,        unsigned long dstRowBytes);
  348.  
  349. void BlitPixieRLEColorClipped(
  350.     unsigned char *srcTokens,        unsigned long srcColor,
  351.     unsigned char *dstPixel,        unsigned long dstRowBytes,
  352.     Rect *dstClipRect );
  353.  
  354. Boolean BlitPixieRLECollision(
  355.     unsigned char *srcTokens,        unsigned char *dstTokens,
  356.     Rect *srcRect,                    Rect *dstRect);
  357.  
  358. #ifdef macintosh
  359.  
  360.     // on the Macintosh, the compiler returns a handle from "NewHandle"
  361. OSErr BlitPixieRLEParsePixels(
  362.     unsigned char *srcStartAddrP,
  363.     unsigned char *maskStartAddrP,
  364.     unsigned long rowBytes,
  365.     unsigned short width,
  366.     unsigned short height,
  367.     unsigned short depth,
  368.     TokenDataHdl *newPixCodeH);
  369.  
  370. #else
  371.  
  372.     // on other systems, the compiler returns a pointer from "malloc"
  373. int BlitPixieRLEParsePixels(
  374.     unsigned char *srcStartAddrP,
  375.     unsigned char *maskStartAddrP,
  376.     unsigned long rowBytes,
  377.     unsigned short width,
  378.     unsigned short height,
  379.     unsigned short depth,
  380.     TokenDataPtr *newPixCodeP);
  381.  
  382. #endif /* macintosh */
  383.  
  384. ///--------------------------------------------------------------------------------------
  385. //    68k blitter that works in depths below 8 bits per pixel too (i.e. in : 1,2,4,8,16,32)
  386. ///--------------------------------------------------------------------------------------
  387.  
  388. #if defined(macintosh) && GENERATING68K
  389.  
  390. void BlitPixieAllBitRect(
  391.     register unsigned char *srcPixelP,
  392.     register unsigned char *dstPixelP,
  393.     register unsigned long srcRowBytes,
  394.     register unsigned long dstRowBytes,
  395.     unsigned long numBytesPerRow,
  396.     unsigned long rowsToCopy,
  397.     register unsigned long srcExtraStart,
  398.     register unsigned long dstExtraStart,
  399.     register unsigned long dstExtraEnd);
  400.     
  401. void BlitPixieAllBitMask(
  402.     register unsigned char *srcPixelP,
  403.     register unsigned char *dstPixelP,
  404.     register unsigned char *maskPixelP,
  405.     register unsigned long srcRowBytes,
  406.     register unsigned long dstRowBytes,
  407.     unsigned long numBytesPerRow,
  408.     unsigned long rowsToCopy,
  409.     register unsigned long srcExtraStart,
  410.     register unsigned long dstExtraStart,
  411.     register unsigned long dstExtraEnd);
  412.     
  413. void BlitPixieAllBitPartialMask(
  414.     register unsigned char *srcPixelP,
  415.     register unsigned char *dstPixelP,
  416.     register unsigned char *maskPixelP,
  417.     register unsigned long srcRowBytes,
  418.     register unsigned long dstRowBytes,
  419.     unsigned long numBytesPerRow,
  420.     unsigned long rowsToCopy,
  421.     register unsigned long srcExtraStart,
  422.     register unsigned long dstExtraStart,
  423.     register unsigned long dstExtraEnd);
  424.  
  425. #endif /* GENERATING68K */
  426.  
  427. ///--------------------------------------------------------------------------------------
  428. //    sprite compiler for 68k code, works in 8-bits, 16-bits, and 32-bits
  429. ///--------------------------------------------------------------------------------------
  430.  
  431. #if defined(macintosh) && GENERATING68K
  432.  
  433.     // blitter requires a pointer to external pixel data (only mask in code)
  434.     // this compiled blitter does NOT handle ANY clipping!
  435.     // use BlitPixieMask for that (which requires a pixel mask).
  436. typedef void (*BlitFuncPtr)(
  437.     long srcRowBytes,
  438.     long dstRowBytes,
  439.     char *srcBaseAddr,
  440.     char *dstBaseAddr);
  441.  
  442. typedef BlitFuncPtr        *PixelCodeHdl;
  443.  
  444. OSErr BlitPixieCodeParsePixels(
  445.     unsigned char *maskStartAddrP,
  446.     unsigned long rowBytes,
  447.     unsigned short numBytesPerScanLine,
  448.     unsigned short numberOfScanLines,
  449.     PixelCodeHdl* newPixCodeH);
  450.  
  451. #endif /* GENERATING68K */
  452.  
  453. ///--------------------------------------------------------------------------------------
  454.  
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458.  
  459. #endif /* __BLITPIXIE__ */