home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / printer / dvi2pcl.lha / pknum.c < prev    next >
C/C++ Source or Header  |  1992-11-25  |  3KB  |  80 lines

  1. /* $Log:    pknum.c,v $
  2.  * Revision 0.8  92/11/23  19:46:52  19:46:52  bt (Bo Thide')
  3.  * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
  4.  * 
  5.  * Revision 0.7  92/11/13  02:41:37  02:41:37  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:48:34  21:48:34  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:40  16:25:40  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:56  02:45:56  bt (Bo Thide')
  15.  * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's.
  16.  * 
  17.  * Revision 0.3  92/08/24  12:45:47  12:45:47  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:28:59  17:28:59  bt (Bo Thide')
  21.  * Source cleaned up.  Changed certain function calls.  Removed globals.
  22.  * 
  23.  * Revision 0.1  92/08/22  23:58:48  23:58:48  bt (Bo Thide')
  24.  * First Release.
  25.  *  */
  26.  
  27. /*
  28.  * This routine provides the final algorithm for decoding the run counts,
  29.  * assuming a procedure (macro) 'getnib()' is available to get the next
  30.  * nibble from the 'pkbuffer'. It returns the next run_count as an integer,
  31.  * and if the row needs to be repeated it returns additionally the repeat
  32.  * value to the global variable 'repeat_count'. Since a repeat count can
  33.  * occur only once within a row, namely after the first transition within a
  34.  * row, it is the responsibility of the calling procedure to repeat such a
  35.  * row and to reset 'repeat_count' to zero, before calling the next run count
  36.  * for the next row.  The global variable 'c_black' changes from 0 to -1 and
  37.  * back to 0 each time 'pknum' is called, indicating a run count for
  38.  * black pixels by 'c_black = -1' or for white pixels by 'c_black = 0', resp.
  39.  * Note that this routine is recursive, but since a repeat count can never
  40.  * directly follow another repeat count, it can only be recursive to one level
  41.  */
  42.  
  43. #include "globals.h"
  44. #include "macros.h"
  45.  
  46. #define getnib() ((c_nib = ~c_nib) ? (*pk_ptr & 0xf0) >> 4 : *pk_ptr++ & 0xf)
  47.  
  48. static char rcsid[] = "$Header: pknum.c,v 0.8 92/11/23 19:46:52 bt Exp $";
  49.  
  50. pknum()
  51. {
  52.     int    i,j;
  53.     extern    int repeat_count;
  54.  
  55.     c_black = ~c_black;
  56.     if(!(i = getnib())) {
  57.         do
  58.             i++;
  59.         while(!(j = getnib()));
  60.         while(i--)
  61.             j = (j << 4) | getnib();
  62.         return(j - 15 + ((13 - dyn_f)<<4) + dyn_f);
  63.     }
  64.     else if(i <= dyn_f)
  65.          return(i);
  66.     else if(i < 14)
  67.         return(((i - dyn_f - 1)<<4) + getnib() + dyn_f + 1);
  68.     else {
  69.         if(repeat_count)
  70.             prerror("Extra repeat count\n");
  71.         if(i == 14)
  72.             repeat_count = pknum();
  73.         else {
  74.             repeat_count = 1;
  75.             c_black = ~c_black;
  76.         }
  77.         return(pknum());
  78.     }
  79. }
  80.