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

  1.  
  2. #include "aatypes.h"
  3. #include "aascreen.h"
  4. #include "str_low.h"
  5. #include "aaerr.h"
  6. #include "aafli.h"
  7. #include "aafii.h"
  8. #include "aaflisav.h"
  9.  
  10. static UBYTE *fii_brun_comp_line(Pixel *s1, Pixel *cbuf, int count)
  11. {
  12. int wcount;
  13. register UBYTE *c;
  14. register int bcount;
  15. int op_count;
  16. Pixel *start_dif;
  17. int dif_count;
  18.  
  19.     c = cbuf+1;
  20.     op_count = 0;
  21.     start_dif = s1;
  22.     dif_count = 0;
  23.     for (;;) {
  24.         if (count < 3) {
  25.             dif_count += count;
  26.             while (dif_count > 0) {
  27.                 bcount = (dif_count < FLI_MAX_RUN ? dif_count : FLI_MAX_RUN );
  28.                 *c++ = -bcount;
  29.                 dif_count -= bcount;
  30.                 while (--bcount >= 0)        *c++ = *start_dif++;
  31.                 op_count++;
  32.             }
  33.             *cbuf = op_count;
  34.             return c;
  35.         }
  36.         bcount = (count < FLI_MAX_RUN ? count : FLI_MAX_RUN );
  37.         if ((wcount = bsame((char *)s1, bcount)) >= 3) {
  38.             while (dif_count > 0) {
  39.                 bcount = (dif_count < FLI_MAX_RUN ? dif_count : FLI_MAX_RUN );
  40.                 *c++ = -bcount;
  41.                 dif_count -= bcount;
  42.                 while (--bcount >= 0)    *c++ = *start_dif++;
  43.                 op_count++;
  44.             }
  45.             *c++ = wcount;
  46.             *c++ = *s1;
  47.             op_count++;
  48.             s1 += wcount;
  49.             count -= wcount;
  50.             start_dif = s1;
  51.         } else {
  52.             dif_count++;
  53.             s1++;
  54.             count -= 1;
  55.         }
  56.     }
  57. }
  58.  
  59.  
  60. unsigned fii_brun(Pixel *s1, UBYTE *cbuf, int width, int height)
  61. {
  62.     UBYTE *oc, *c = cbuf;
  63.     unsigned total = 0;
  64.  
  65. /* store offset of 1st real line and set up for main line-at-a-time loop */
  66.     while (--height >= 0) {
  67.         oc = c;
  68.         c = fii_brun_comp_line(s1, c, width);
  69.         total += (unsigned)(c - oc);
  70.         if (total >= 60000U)     return 0;
  71.         s1 += width;
  72.     }
  73.     return (unsigned) (c - cbuf);
  74. }
  75.