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

  1. /* str_low.c -- String low-level operations */
  2.  
  3. #include "aatypes.h"
  4. #include "aascreen.h"
  5. #include "str_low.h"
  6.  
  7. int wcompare(USHORT *s1, USHORT *s2, int count)
  8. {
  9.     unsigned i;
  10.  
  11.     for (i = 0; *s1++ == *s2++ && i < count; i++) ;
  12.     return i;
  13. }
  14.  
  15. int bcompare(char *s1, char *s2, int count)
  16. {
  17.     unsigned i;
  18.  
  19.     for (i = 0; *s1++ == *s2++ && i < count; i++) ;
  20.     return i;
  21. }
  22.  
  23. /* return how many bytes of s1 and s2 are different */
  24. int bcontrast(char *s1, char *s2, int count)
  25. {
  26.     unsigned i;
  27.  
  28.     for (i = 0; *s1++ != *s2++ && i < count; i++) ;
  29.     return i;
  30. }
  31.  
  32. /* find out how many bytes in a row are the same value */
  33. int bsame(char *s1, int count)
  34. {
  35.     char ch;
  36.     unsigned i;
  37.  
  38.     if (count == 0) return 0;
  39.     ch = *s1++;
  40.     for (i = 1; *s1++ == ch && i < count; i++) ;
  41.     return i;
  42. }
  43.  
  44. /* Find out how far until have the next match of mustmatch or more pixels */
  45.  
  46. unsigned int fii_tnskip(Pixel *s1, Pixel *s2, unsigned bcount, unsigned mustmatch)
  47. {
  48.     unsigned int difcount = 0;
  49.     unsigned int ax;
  50.  
  51.     while (1) {
  52.         ax = bcontrast((char *)s1, (char *)s2, bcount); /* calculate number of pixels different in s1 and s2 into ax */
  53.         s1 += ax;
  54.         s2 += ax;                /* move source pointers just past this different run */
  55.         difcount += ax;        /* add different count to return value */
  56.         bcount -= ax;
  57.         if (bcount < mustmatch) {    /* see if near the end... */
  58.             if (bcompare((char *) s1, (char *) s2, bcount) != bcount)    /* check last couple of pixels */
  59.                 difcount += bcount;                            /* if all of them match between s1 and s2 go home */
  60.             break;
  61.         }
  62.         if ((ax = bcompare((char *) s1, (char *) s2, mustmatch)) == mustmatch)    /* see if enough in a row match to break out of this */
  63.             break;        /* if all of them match between s1 and s2 go home */
  64.  
  65.         difcount += ax;            /* Add ones that do match into difcount */
  66.         bcount -= ax;                /* sub it from pixels left to examine */
  67.         s1 += ax;
  68.         s2 += ax;                    /* update s1,s2 pointers */
  69.     }
  70.     return    difcount;
  71. }
  72.  
  73. /* Find out how far until next run of identical pixels mustmatch long */
  74.  
  75. unsigned int fii_tnsame(Pixel *s, unsigned int wcount, unsigned int mustmatch)
  76. {
  77.     unsigned bx = wcount;            /* Number of pixels left */
  78.     unsigned difcount = wcount;
  79.     unsigned si = 0;                    /* si is # of pixels examined */
  80.     unsigned same_count;
  81.  
  82.     while (bx > mustmatch) {        /* break out of loop if less than 4 pixels left to examine */
  83.         same_count = bsame((char *) s, wcount);
  84.         s += same_count - 1;
  85.         if (same_count >= mustmatch)    return si;            /* if mustmatch or more, go truncate dif_count */
  86.         si += same_count;
  87.         s += same_count;  /* This may be a bug in the assembler program */
  88.         bx -= same_count;
  89.     }
  90.     return difcount;
  91. }
  92.  
  93. UBYTE *wbuf(UBYTE *p, unsigned x)
  94. {
  95.     *p++ = x         & 0xff;
  96.     *p++ = (x >>  8) & 0xff;
  97.     return p;
  98. }
  99.  
  100. UBYTE *lbuf(UBYTE *p, unsigned long x)
  101. {
  102.     p = wbuf(p, (unsigned)(x & 0xffffL));
  103.     p = wbuf(p, (unsigned)((x >> 16) & 0xffffL));
  104.     return p;
  105. }
  106.