home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Printer / epsonx / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-03  |  6.7 KB  |  162 lines

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