home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_03 / 2n03009a < prev    next >
Text File  |  1991-01-14  |  2KB  |  61 lines

  1. /*
  2.  * Listing 3: print_stripe() for an AT&T 477 color printer.
  3.  * Assumes get_pixel() returns direct-mapped color (RGB).
  4.  */
  5. void print_stripe( int y_start )
  6.     {
  7.     int num_pix, x, y, bit_num, which_color;
  8.     unsigned char out_pixel, c, mask;
  9.     static char graph_cmd[4] = {ESC, 'L', 0, 0};
  10.     static char color_sel[3] = {ESC, 'r', 0};
  11.  
  12.     /* Send three sets of data.  Have to prefix each set with
  13.      * ESC r [1, 2, or 4] for magenta, cyan, yellow respectively.
  14.      */
  15.     for (which_color = 1; which_color <= 4; which_color <<= 1)
  16.         {
  17.         color_sel[2] = which_color + '0';
  18.         write(print_fh, color_sel, 3);
  19.         switch (which_color)    /* generate proper bit mask */
  20.             {                    /* for this data set */
  21.             case 1:
  22.                 mask = 2;    /* if magenta, mask is 2 for green */
  23.                 break;
  24.             case 2:
  25.                 mask = 4;    /* if cyan, mask is 4 for red */
  26.                 break;
  27.             case 4:
  28.                 mask = 1;    /* if yellow, mask is 1 for blue */
  29.                 break;
  30.             }
  31.  
  32.         /* Send ESC L n1 n2, where (256 * n2) + n1 is the
  33.          * number of pixels across a line.
  34.          */
  35.         num_pix = x_max + 1;
  36.         graph_cmd[2] = num_pix & 0xff;
  37.         graph_cmd[3] = num_pix >> 8;
  38.         write(print_fh, graph_cmd, 4);
  39.  
  40.         for (x = 0; x < num_pix; ++x)
  41.             {
  42.             /* Accumulate 8 pixels, vertically, into out_pixel.
  43.              */
  44.             out_pixel = 0;
  45.             y = y_start;
  46.             for (bit_num = 7; bit_num >= 0; --bit_num, ++y)
  47.                 {
  48.                 if ((getpixel(x, y) & mask) == 0)
  49.                     out_pixel |= (1 << bit_num);
  50.                 }
  51.             write(print_fh, &out_pixel, 1);
  52.             }
  53.  
  54.         c = CR;        /* send CR after each data set */
  55.         write(print_fh, &c, 1);
  56.         }
  57.  
  58.     c = LF;        /* send LF after all three sets */
  59.     write(print_fh, &c, 1);
  60.     }
  61.