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

  1. /* $Log:    pktopxl.c,v $
  2.  * Revision 0.8  92/11/23  19:46:53  19:46:53  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:38  02:41:38  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:48:35  21:48:35  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:42  16:25:42  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:58  02:45:58  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:48  12:45:48  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. int   repeat_count;
  28.  
  29. #include <stdio.h>
  30. #include "globals.h"
  31.  
  32. static char rcsid[] = "$Header: pktopxl.c,v 0.8 92/11/23 19:46:53 bt Exp $";
  33.  
  34. /*
  35.  * This routine converts a character coded in PK format into the appropriate
  36.  * byte aligned pixel pattern. After calling 'pkcharinfo(c)', besides the
  37.  * global variables 'dyn_f, c_flag, c_width, c_height, c_hoffset and c_voffset'
  38.  * a pointer to the first run count is returned and stored in the global var
  39.  * 'pk_ptr'. The produced pixel pattern is stored in the global array
  40.  * 'pxl_buffer', and the global pointer 'endofchardata' points to the next free
  41.  * byte in 'pxlbuffer'.
  42.  *----------------------------------------------------------------------------
  43.  * 'pktopxl' has two main branches: for those characters which are coded into
  44.  * run-repeat counts, indicated by a value of dyn_f < 14, the first branch is
  45.  * taken, while for bit mapped characters, indicated by dyn_f == 14, the
  46.  * second branch is taken.
  47.  */
  48. pktopxl(c)
  49. int c;
  50. {
  51.   static byte c_pad[]={'\0','\200','\300','\340','\360','\370','\374','\376'};
  52.   byte    *pxl, *row="", *p;
  53.   byte    pxl_byte;
  54.   int    pad_bits, pad_comp;
  55.   int   pad_mask;
  56.   int   width_bytes;
  57.   int   nrows,length;
  58.   int   l, m=0, n=0;
  59.   int   run_count;
  60.  
  61.   pk_ptr = pkcharinfo(c);
  62.   nrows = c_height;
  63.   width_bytes = (c_width + 7) / 8;
  64.   pad_bits = c_width % 8;
  65.   pad_mask = c_pad[pad_bits];
  66.   pxl = pxlbuffer;
  67.  
  68.   if(dyn_f<14){
  69.    /* Convert run/repeat counts to byte aligned pixels */
  70.     run_count = repeat_count = 0;
  71.     c_nib = 0;
  72.     c_black = (c_flag & 0x8) ? 0 : ~0;
  73.     while(nrows) {
  74.       if(repeat_count) {
  75.         while(repeat_count) {
  76.           repeat_count--;
  77.           m = width_bytes;
  78.           while(m--)
  79.             *pxl++ = *row++;
  80.           nrows--;
  81.         }
  82.       }
  83.       else {
  84.         if(!run_count)
  85.           run_count = pknum();
  86.         if(run_count >= c_width)
  87.           while(run_count >= c_width) {
  88.             run_count -= c_width;
  89.             m = pad_bits ? width_bytes : width_bytes + 1;
  90.             while(--m)
  91.               *pxl++ = c_black ? BLACKBYTE : WHITEBYTE;
  92.             if(pad_bits)
  93.               *pxl++ = c_black ? pad_mask : WHITEBYTE;
  94.             nrows--;
  95.           }
  96.         else {
  97.           row = pxl;
  98.           m = pad_bits ? width_bytes : width_bytes + 1;
  99.           while(--m) {
  100.             if(run_count < 8) {
  101.               pxl_byte = c_black ? c_pad[run_count] : ~c_pad[run_count];
  102.               while((run_count += pknum()) < 8)
  103.                 if(c_black)
  104.                   pxl_byte &= c_pad[run_count];
  105.               else
  106.                 pxl_byte |= ~c_pad[run_count];
  107.           *pxl++ = pxl_byte;
  108.         }
  109.         else
  110.           *pxl++ = c_black ? BLACKBYTE : WHITEBYTE;
  111.         run_count -= 8;
  112.       }
  113.       if(pad_bits) {
  114.         if(run_count < pad_bits) {
  115.           pxl_byte = c_black ? c_pad[run_count] : ~c_pad[run_count];
  116.           while((run_count += pknum()) < pad_bits)
  117.         if(c_black)
  118.           pxl_byte &=  c_pad[run_count];
  119.         else
  120.           pxl_byte |= ~c_pad[run_count];
  121.           *pxl++ = pxl_byte & pad_mask;
  122.         }
  123.         else
  124.           *pxl++ = c_black ? pad_mask : WHITEBYTE;
  125.       }
  126.       nrows--;
  127.       run_count -= pad_bits;
  128.     }
  129.       }
  130.     }
  131.   }
  132.   else {
  133.     /* Convert bit mapped character into byte aligned pixel */
  134.     p = pk_ptr;
  135.     pad_comp = 8 - pad_bits;
  136.     if(pad_bits) {
  137.       m=0;
  138.       while(nrows--) {
  139.     l = width_bytes;
  140.         while(--l)
  141.       *pxl++ = m ? (*p++) << m | (*p >> n) & ~c_pad[n] : *p++;
  142.         if(m)
  143.       *pxl++ = m <= pad_comp ? (*p << m) & pad_mask :
  144.         (*p++) << m | *p >> n & ~c_pad[n] & pad_mask;
  145.         else
  146.       *pxl++ = *p & pad_mask;
  147.         m = (m + c_width) % 8;
  148.         if(!m)
  149.       p++;
  150.         else
  151.       n = 8 - m;
  152.       }
  153.     }
  154.     else {
  155.       length = width_bytes*c_height;
  156.       if(!length)
  157.     *pxl++ = 0;        /* special case for empty char */
  158.       while(length--)
  159.     *pxl++ = *p++;
  160.     }
  161.   }
  162.   endofchardata = pxl;
  163. }
  164.  
  165.