home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / CreativeComputers.iso / shareware / text / dvi_3.62 / source / dvisrc.lha / dvithin.c < prev    next >
C/C++ Source or Header  |  1993-10-26  |  2KB  |  158 lines

  1. /*
  2. ** Datei: DVITHIN.C
  3. ** Autor: Ingo Eichenseher
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdarg.h>
  8. #include "dvi.h"
  9. #include "dvihdcp.h"
  10. #include "dviframe.h"
  11.  
  12. #ifdef SLOW_METHOD
  13.  
  14. static unsigned char nb = 0;
  15.  
  16. void thin_init(void)
  17. {
  18. }
  19.  
  20. static void thin(register unsigned char *line, int width)
  21. {
  22.     register int i, l;
  23.     register unsigned char bit, b1, b2, *l1, *l2;
  24.  
  25.     l = 0; b1 = 64; b2 = 32; l1 = l2 = line;
  26.     for (i=width*8; i--; line++)
  27.     {
  28.     for (bit=128; bit; bit>>=1)
  29.     {
  30.         if (*line & bit)
  31.         {
  32.         switch(l)
  33.         {
  34.             case 0:
  35.             l = 1; 
  36.             break;
  37.             case 1: 
  38.             *line &= ~bit;
  39.             l = 2; 
  40.             break;
  41.             case 2:
  42.             if ( (*l1 & b1) && (*l2 & b2)==0)
  43.                 *line &= ~bit;
  44.             l = 3;
  45.             break;
  46.             case 3:
  47.             if (*l1 & b1)
  48.                 *line &= ~bit;
  49.             l = 2;
  50.             break;
  51.         }
  52.         }
  53.         else l=0;
  54.         if ((b1 >>= 1)==0)
  55.         {
  56.         b1 = 128;
  57.         if (i) l1++;
  58.         else l1 = &nb;
  59.         }
  60.         if ((b2 >>= 1)==0) 
  61.         {
  62.         b2 = 128; 
  63.         if (i) l2++;
  64.         else l2 = &nb;
  65.         }
  66.     }
  67.     }
  68. }
  69.  
  70. void thin_out(unsigned char *buffer, int lines, int width)
  71. {
  72.     int *x = Logbase();
  73.     while(lines--)
  74.     {
  75.     thin(buffer,width);
  76.     buffer += width;
  77.     *x ^= 0xFFFF;
  78.     }
  79. }
  80.  
  81. #else 
  82.  
  83. static int table[256*16];
  84.  
  85. static void thin_byte(int l_start, int b_end, int *table)
  86. {
  87.     register int i ,l;
  88.  
  89.     for (i=0; i<256; i++)
  90.     {
  91.     register unsigned char bit, bbyte, b;
  92.  
  93.     bbyte = i;
  94.     l = l_start;
  95.     for (bit=128; bit; bit>>=1)
  96.     {
  97.         if (bit==1) b = b_end;
  98.         else if (bit==2) b = ((bbyte&1)<<1) | ((b_end>>1)&1);
  99.         else b = (((bit>>1)&bbyte) ? 2:0) | (((bit>>2)&bbyte) ? 1:0);
  100.         if (bbyte & bit)
  101.         {
  102.         switch(l)
  103.         {
  104.             case 0: 
  105.             l = 1;
  106.             break;
  107.             case 1: 
  108.             bbyte &= ~bit;
  109.             l = 2; 
  110.             break;
  111.             case 2:
  112.             if (b==2)
  113.                 bbyte &= ~bit;
  114.             l = 3;
  115.             break;
  116.             case 3:
  117.             if (b>=2)
  118.                 bbyte &= ~bit;
  119.             l = 2;
  120.             break;
  121.         }
  122.         }
  123.         else l=0;
  124.     }
  125.     table[i] = (l<<10) | bbyte;
  126.     }
  127. }
  128.  
  129. void thin_init(void)
  130. {
  131.     register int l, b;
  132.     for (l=0; l<4; l++)
  133.     for (b=0; b<4; b++)
  134.         thin_byte(l,b,&table[(l*4+b)<<8]);
  135. }
  136.  
  137. void thin_out(int lines, int width)
  138. {
  139.     register unsigned int b, l = 0, w;
  140.     register long line = 0;
  141.  
  142.     while(lines--)
  143.     {
  144.     w = width;
  145.     while(--w)
  146.     {
  147.         b = (frame_get(line+1)&0xC0)<<2;
  148.         l = table[l|b|frame_get(line)];
  149.         frame_poke(line,l);
  150.         line++;
  151.         l &= 0xff00;
  152.     }
  153.     frame_poke(line,table[l|frame_get(line)]);
  154.     line++;
  155.     }
  156. }
  157. #endif
  158.