home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / xerox / transfer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  4.7 KB  |  145 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. #include <exec/types.h>
  23. #include <devices/printer.h>
  24. #include <devices/prtbase.h>
  25. #include <devices/prtgfx.h>
  26.  
  27. void Transfer(struct PrtInfo *, UWORD, UBYTE *, UWORD *);
  28.  
  29. void Transfer(PInfo, y, ptr, colors)
  30. struct PrtInfo *PInfo;
  31. UWORD y;    /* row # */
  32. UBYTE *ptr;    /* ptr to buffer */
  33. UWORD *colors; /* indexes to color buffers */
  34. {
  35.     extern struct PrinterData *PD;
  36.  
  37.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  38.     UBYTE *dmatrix, *bptr, *yptr, *mptr, *cptr;
  39.     UBYTE dvalue, Black, Yellow, Magenta, Cyan, threshold;
  40.     UBYTE bit, y3;
  41.     union colorEntry *ColorInt;
  42.     UWORD x, x3, width, sx, *sxptr;
  43.  
  44.     /* pre-compute */
  45.     /* printer specific */
  46.     y3 = y & 3;
  47.     bptr = ptr + colors[y3];
  48.     yptr = ptr + colors[4 + y3];
  49.     mptr = ptr + colors[8 + y3];
  50.     cptr = ptr + colors[12 + y3];
  51.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  52.     x = PInfo->pi_xpos; /* get starting x position */
  53.     ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  54.     sxptr = PInfo->pi_ScaleX;
  55.     width = PInfo->pi_width; /* get # of source pixels */
  56.  
  57.     /* pre-compute threshold; are we thresholding? */
  58.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  59.         dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  60.         do { /* for all source pixels */
  61.             /* pre-compute intensity values for Black component */
  62.             Black = ColorInt->colorByte[PCMBLACK];
  63.             ColorInt++; /* bump ptr for next time */
  64.  
  65.             sx = *sxptr++;
  66.  
  67.             do { /* use this pixel 'sx' times */
  68.                 /* if should render black */
  69.                 if (Black > dvalue) {
  70.                     /* set bit in black buffer */
  71.                     *(bptr + (x >> 3)) |= bit_table[x & 7];
  72.                 }
  73.                 ++x; /* done 1 more printer pixel */
  74.             } while (--sx);
  75.         } while (--width);
  76.     }
  77.     else { /* not thresholding, pre-compute ptr to dither matrix */
  78.         dmatrix = PInfo->pi_dmatrix + (y3 << 2);
  79.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  80.             do { /* for all source pixels */
  81.                 /* pre-compute intensity values for Black */
  82.                 Black = ColorInt->colorByte[PCMBLACK];
  83.                 ColorInt++; /* bump ptr for next time */
  84.  
  85.                 sx = *sxptr++;
  86.  
  87.                 do { /* use this pixel 'sx' times */
  88.                     /* if should render black */
  89.                     if (Black > dmatrix[x & 3]) {
  90.                         /* set bit in black buffer */
  91.                         *(bptr + (x >> 3)) |=
  92.                             bit_table[x & 7];
  93.                     }
  94.                     ++x; /* done 1 more printer pixel */
  95.                 } while (--sx);
  96.             } while (--width);
  97.         }
  98.         else { /* color */
  99.             do { /* for all source pixels */
  100.                 /* pre-compute intensity vals for each color */
  101.                 Black = ColorInt->colorByte[PCMBLACK];
  102.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  103.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  104.                 Cyan = ColorInt->colorByte[PCMCYAN];
  105.                 ColorInt++; /* bump ptr for next time */
  106.  
  107.                 sx = *sxptr++;
  108.  
  109.                 do { /* use this pixel 'sx' times */
  110.                     /* pre-compute 'byte to set' value */
  111.                     x3 = x >> 3;
  112.                     /* pre-compute 'bit to set' val */
  113.                     bit = bit_table[x & 7];
  114.                     /* pre-compute dither value */
  115.                     dvalue = dmatrix[x & 3];
  116.                     /* if should render black */
  117.                     if (Black > dvalue) {
  118.                         /* set bit in black buffer */
  119.                         *(bptr + x3) |= bit;
  120.                     }
  121.                     /* black not rendered, check color */
  122.                     else  {
  123.                         /* if should render yellow */
  124.                         if (Yellow > dvalue) {
  125.                             /* set bit in Y buf */
  126.                             *(yptr + x3) |= bit;
  127.                         }
  128.                         /* if should render magenta */
  129.                         if (Magenta > dvalue) {
  130.                             /* set bit in M buf */
  131.                             *(mptr + x3) |= bit;
  132.                         }
  133.                         /* if should render cyan */
  134.                         if (Cyan > dvalue) {
  135.                             /* set bit in C buf */
  136.                             *(cptr + x3) |= bit;
  137.                         }
  138.                     }
  139.                     ++x; /* done 1 more printer pixel */
  140.                 } while (--sx);
  141.             } while (--width);
  142.         }
  143.     }
  144. }
  145.