home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / animutil / pvquan / flilib / fccomp.c < prev    next >
C/C++ Source or Header  |  1992-11-30  |  2KB  |  75 lines

  1. /* fii_fccomp.c -  code used to delta compress colors. */
  2.  
  3. #include "aatypes.h"
  4. #include "aaerr.h"
  5. #include "aascreen.h"
  6. #include "str_low.h"
  7. #include "aafli.h"
  8. #include "aaflisav.h"
  9. #include "aafii.h"
  10.  
  11. /* fii_fccomp - compress an rgb triples color map just doing 'skip' compression */
  12. unsigned fii_fccomp(Cmap *s1, Cmap *s2, Cbuf *cbuf, int count)
  13. {
  14.     USHORT wcount;
  15.     Cbuf *c;
  16.     USHORT op_count;
  17.     USHORT dif_count;
  18.     USHORT bcount;
  19.     USHORT c3;
  20.  
  21.     c = cbuf + 2;
  22.     op_count = 0;
  23.     count *= 3;
  24.     wcount = wcompare((USHORT *)s1, (USHORT *)s2, count>>1);
  25.     wcount <<= 1;
  26.     if (wcount == count)        return 2;    /* stupid way to say got nothing... */
  27.     while (TRUE)    {
  28.         /* first find out how many words to skip... */
  29.         c3 = bcompare((char *) s1, (char *) s2, count)/3;
  30.         wcount = c3*3;
  31.         if ((count -= wcount) == 0)    break;    /* same until the end... */
  32.         *c++ = c3;
  33.         s1 += wcount;
  34.         s2 += wcount;
  35.         op_count++;
  36.  
  37.         /* figure out how long until the next worthwhile "skip" */
  38.         dif_count = 0;
  39.         bcount = count;
  40.         while (TRUE) {
  41.             wcount = bcontrast((char *) s1, (char *) s2, bcount)/3;
  42.             dif_count += wcount;
  43.             wcount *= 3;
  44.             s1 += wcount;
  45.             s2 += wcount;
  46.             bcount -= wcount;
  47.             if (bcount >= 3) {
  48.                 if ((wcount = bcompare((char *) s1, (char *) s2, 3)) == 3)    break;
  49.                 else {
  50.                     dif_count += 1;
  51.                     s1 += 3;
  52.                     s2 += 3;
  53.                     bcount -= 3;
  54.                 }
  55.             } else break;
  56.         }
  57.         *c++ = dif_count;
  58.         dif_count *= 3;
  59.         s2 -= dif_count;
  60.         count -= dif_count;
  61.         while (dif_count != 0) {
  62.             dif_count--;
  63.             *c++ = *s2++;
  64.         }
  65.         if (count <= 0)    break;
  66.     }
  67. #ifdef __TURBOC__
  68.     *(USHORT *)cbuf = op_count;
  69. #else
  70.     wbuf(cbuf, op_count);
  71. #endif
  72.     return (unsigned) (c - cbuf);
  73. }
  74.  
  75.