home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / epsonx_transfer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  5.3 KB  |  137 lines

  1. /*
  2.         C-language Transfer routine for EpsonX driver.
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <devices/printer.h>
  7. #include <devices/prtbase.h>
  8. #include <devices/prtgfx.h>
  9.  
  10. Transfer(PInfo, y, ptr, colors, BufOffset)
  11. struct PrtInfo *PInfo;
  12. UWORD y;                /* row # */
  13. UBYTE *ptr;             /* ptr to buffer */
  14. UWORD *colors;          /* indexes to color buffers */
  15. ULONG BufOffset;        /* used for interleaved printing */
  16. {
  17.         extern struct PrinterData *PD;
  18.         extern struct PrinterExtendedData *PED;
  19.  
  20.         static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  21.         union colorEntry *ColorInt;
  22.         UBYTE *bptr, *yptr, *mptr, *cptr, Black, Yellow, Magenta, Cyan;
  23.         UBYTE *dmatrix, dvalue, threshold;
  24.         UWORD x, width, sx, *sxptr, color, bit, x3;
  25.  
  26.         /* printer non-specific, MUST DO FOR EVERY PRINTER */
  27.         x = PInfo->pi_xpos;
  28.         ColorInt = PInfo->pi_ColorInt;
  29.         sxptr = PInfo->pi_ScaleX;
  30.         width = PInfo->pi_width;
  31.  
  32.         /* printer specific */
  33.         if (PED->ped_YDotsInch == 216)
  34.         {
  35.                 BufOffset *= y % 3;
  36.                 y /= 3;
  37.         }
  38.         else if (PED->ped_YDotsInch == 144)
  39.         {
  40.                 BufOffset *= y & 1;
  41.                 y /= 2;
  42.         }
  43.         else
  44.         {
  45.                 BufOffset = 0;
  46.         }
  47.         bit = bit_table[y & 7];
  48.         bptr = ptr + colors[0] + BufOffset;
  49.         yptr = ptr + colors[1] + BufOffset;
  50.         mptr = ptr + colors[2] + BufOffset;
  51.         cptr = ptr + colors[3] + BufOffset;
  52.  
  53.         /* pre-compute threshold; are we thresholding? */
  54.         if (threshold = PInfo->pi_threshold)
  55.         { /* thresholding */
  56.                 dvalue = threshold ^ 15;
  57.                 bptr += x;
  58.                 do { /* for all source pixels */
  59.                         /* pre-compute intensity values for Black component */
  60.                         Black = ColorInt->colorByte[PCMBLACK];
  61.                         ColorInt++;
  62.  
  63.                         sx = *sxptr++;
  64.  
  65.                         do { /* use this pixel 'sx' times */
  66.                                 if (Black > dvalue)
  67.                                 {
  68.                                         *bptr |= bit;
  69.                                 }
  70.                                 bptr++; /* done 1 more printer pixel */
  71.                         } while (--sx);
  72.                 } while (--width);
  73.         }
  74.  
  75.         else
  76.         { /* not thresholding, pre-compute ptr to dither matrix */
  77.                 dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  78.                 if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE)
  79.                 {
  80.                         do { /* for all source pixels */
  81.                                 /* pre-compute intensity values for Black */
  82.                                 Black = ColorInt->colorByte[PCMBLACK];
  83.                                 ColorInt++;
  84.  
  85.                                 sx = *sxptr++;
  86.  
  87.                                 do { /* use this pixel 'sx' times */
  88.                                         if (Black > dmatrix[x & 3])
  89.                                         {
  90.                                                 *(bptr + x) |= bit;
  91.                                         }
  92.                                         x++; /* done 1 more printer pixel */
  93.                                 } while (--sx);
  94.                         } while (--width);
  95.                 }
  96.                 else
  97.                 { /* color */
  98.                         do { /* for all source pixels */
  99.                                 /* compute intensity values for each color */
  100.                                 Black = ColorInt->colorByte[PCMBLACK];
  101.                                 Yellow = ColorInt->colorByte[PCMYELLOW];
  102.                                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  103.                                 Cyan = ColorInt->colorByte[PCMCYAN];
  104.                                 ColorInt++;
  105.  
  106.                                 sx = *sxptr++;
  107.  
  108.                                 do { /* use this pixel 'sx' times */
  109.                                         x3 = x >> 3;
  110.                                         dvalue = dmatrix[x & 3];
  111.                                         if (Black > dvalue)
  112.                                         {
  113.                                                 *(bptr + x) |= bit;
  114.                                         }
  115.                                         else
  116.                                         { /* black not rendered */
  117.                                                 if (Yellow > dvalue)
  118.                                                 {
  119.                                                         *(yptr + x) |= bit;
  120.                                                 }
  121.                                                 if (Magenta > dvalue)
  122.                                                 {
  123.                                                         *(mptr + x) |= bit;
  124.                                                 }
  125.                                                 if (Cyan > dvalue)
  126.                                                 {
  127.                                                         *(cptr + x) |= bit;
  128.                                                 }
  129.                                         }
  130.                                         ++x; /* done 1 more printer pixel */
  131.                                 } while (--sx);
  132.                         } while (--width);
  133.                 }
  134.         }
  135. }
  136.  
  137.