home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / epsonx / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1980-02-03  |  4.1 KB  |  138 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. Transfer(PInfo, y, ptr, colors, BufOffset)
  28. struct PrtInfo *PInfo;
  29. UWORD y;        /* row # */
  30. UBYTE *ptr;        /* ptr to buffer */
  31. UWORD *colors;        /* indexes to color buffers */
  32. ULONG BufOffset;    /* used for interleaved printing */
  33. {
  34.     extern struct PrinterData *PD;
  35.     extern struct PrinterExtendedData *PED;
  36.  
  37.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  38.     union colorEntry *ColorInt;
  39.     UBYTE *bptr, *yptr, *mptr, *cptr, Black, Yellow, Magenta, Cyan;
  40.     UBYTE *dmatrix, dvalue, threshold;
  41.     UWORD x, width, sx, *sxptr, color, bit, x3;
  42.  
  43.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  44.     x = PInfo->pi_xpos;
  45.     ColorInt = PInfo->pi_ColorInt;
  46.     sxptr = PInfo->pi_ScaleX;
  47.     width = PInfo->pi_width;
  48.  
  49.     /* printer specific */
  50.     if (PED->ped_YDotsInch == 216) {
  51.         BufOffset *= y % 3;
  52.         y /= 3;
  53.     }
  54.     else if (PED->ped_YDotsInch == 144) {
  55.         BufOffset *= y & 1;
  56.         y /= 2;
  57.     }
  58.     else {
  59.         BufOffset = 0;
  60.     }
  61.     bit = bit_table[y & 7];
  62.     bptr = ptr + colors[0] + BufOffset;
  63.     yptr = ptr + colors[1] + BufOffset;
  64.     mptr = ptr + colors[2] + BufOffset;
  65.     cptr = ptr + colors[3] + BufOffset;
  66.  
  67.     /* pre-compute threshold; are we thresholding? */
  68.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  69.         dvalue = threshold ^ 15;
  70.         bptr += x;
  71.         do { /* for all source pixels */
  72.             /* pre-compute intensity values for Black component */
  73.             Black = ColorInt->colorByte[PCMBLACK];
  74.             ColorInt++;
  75.  
  76.             sx = *sxptr++;
  77.  
  78.             do { /* use this pixel 'sx' times */
  79.                 if (Black > dvalue) {
  80.                     *bptr |= bit;
  81.                 }
  82.                 bptr++; /* done 1 more printer pixel */
  83.             } while (--sx);
  84.         } while (--width);
  85.     }
  86.     else { /* not thresholding, pre-compute ptr to dither matrix */
  87.         dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  88.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  89.             do { /* for all source pixels */
  90.                 /* pre-compute intensity values for Black */
  91.                 Black = ColorInt->colorByte[PCMBLACK];
  92.                 ColorInt++;
  93.  
  94.                 sx = *sxptr++;
  95.  
  96.                 do { /* use this pixel 'sx' times */
  97.                     if (Black > dmatrix[x & 3]) {
  98.                         *(bptr + x) |= bit;
  99.                     }
  100.                     x++; /* done 1 more printer pixel */
  101.                 } while (--sx);
  102.             } while (--width);
  103.         }
  104.         else { /* color */
  105.             do { /* for all source pixels */
  106.                 /* compute intensity values for each color */
  107.                 Black = ColorInt->colorByte[PCMBLACK];
  108.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  109.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  110.                 Cyan = ColorInt->colorByte[PCMCYAN];
  111.                 ColorInt++;
  112.  
  113.                 sx = *sxptr++;
  114.  
  115.                 do { /* use this pixel 'sx' times */
  116.                     x3 = x >> 3;
  117.                     dvalue = dmatrix[x & 3];
  118.                     if (Black > dvalue) {
  119.                         *(bptr + x) |= bit;
  120.                     }
  121.                     else  { /* black not rendered */
  122.                         if (Yellow > dvalue) {
  123.                             *(yptr + x) |= bit;
  124.                         }
  125.                         if (Magenta > dvalue) {
  126.                             *(mptr + x) |= bit;
  127.                         }
  128.                         if (Cyan > dvalue) {
  129.                             *(cptr + x) |= bit;
  130.                         }
  131.                     }
  132.                     ++x; /* done 1 more printer pixel */
  133.                 } while (--sx);
  134.             } while (--width);
  135.         }
  136.     }
  137. }
  138.