home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsii / rotate8x.c < prev    next >
Text File  |  1991-10-02  |  2KB  |  79 lines

  1. /*
  2. **    Rotate an 8x8 tile clockwise by table lookup
  3. **    and write to destination directly.
  4. **    Large bitmaps can be rotated an 8x8 tile at a time.
  5. **    The extraction is done a nybble at a time to reduce the
  6. **    size of the tables.
  7. **
  8. **    Input parameters:
  9. **    src        starting address of source 8x8 tile
  10. **    srcstep        difference in byte address between
  11. **            adjacent rows in source bitmap
  12. **    dst        starting address of destination 8x8 tile
  13. **    dststep        difference in byte address between
  14. **            adjacent rows in destination bitmap
  15. **
  16. **    Ken Yap (Centre for Spatial Information Systems, CSIRO DIT, Australia)
  17. **    after an idea suggested by Alan Paeth (U of Waterloo).
  18. */
  19.  
  20. typedef    long    bit32;
  21.  
  22. #define    table(name,n)\
  23.     static bit32 name[16] =\
  24.     {\
  25.         0x00000000<<n, 0x00000001<<n, 0x00000100<<n, 0x00000101<<n,\
  26.         0x00010000<<n, 0x00010001<<n, 0x00010100<<n, 0x00010101<<n,\
  27.         0x01000000<<n, 0x01000001<<n, 0x01000100<<n, 0x01000101<<n,\
  28.         0x01010000<<n, 0x01010001<<n, 0x01010100<<n, 0x01010101<<n,\
  29.     };
  30.  
  31. table(ltab0,7)
  32. table(ltab1,6)
  33. table(ltab2,5)
  34. table(ltab3,4)
  35. table(ltab4,3)
  36. table(ltab5,2)
  37. table(ltab6,1)
  38. table(ltab7,0)
  39.  
  40. void rotate8x8(src, srcstep, dst, dststep)
  41.     unsigned char    *src, *dst;
  42.     int        srcstep, dststep;
  43. {
  44.     register unsigned char    *p;
  45.     register int    pstep, lownyb, hinyb;
  46.     register bit32    low, hi;
  47.  
  48.     low = hi = 0;
  49.  
  50. #define    extract(d,t)\
  51.     lownyb = *d & 0xf; hinyb = *d >> 4;\
  52.     low |= t[lownyb]; hi |= t[hinyb]; d += pstep;
  53.  
  54.     p = src; pstep = srcstep;
  55.     extract(p,ltab0) extract(p,ltab1) extract(p,ltab2) extract(p,ltab3)
  56.     extract(p,ltab4) extract(p,ltab5) extract(p,ltab6) extract(p,ltab7)
  57.  
  58. #define    unpack(d,w)\
  59.     *d = w & 0xff;        d += pstep;\
  60.     *d = (w >> 8) & 0xff;    d += pstep;\
  61.     *d = (w >> 16) & 0xff;    d += pstep;\
  62.     *d = (w >> 24) & 0xff;
  63.  
  64.     p = dst; pstep = dststep;
  65.     unpack(p,low) p += pstep; unpack(p,hi)
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.