home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / hp / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1980-02-03  |  3.0 KB  |  84 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/prtgfx.h>
  24.  
  25. Transfer(PInfo, y, ptr)
  26. struct PrtInfo *PInfo;
  27. UWORD y;    /* row # */
  28. UBYTE *ptr;    /* ptr to buffer */
  29. {
  30.     static UBYTE bit_table[] = {128, 64, 32, 16, 8, 4, 2, 1};
  31.     UBYTE *dmatrix, Black, dvalue, threshold;
  32.     union colorEntry *ColorInt;
  33.     UWORD x, width, sx, *sxptr, bit;
  34.  
  35.     /* pre-compute */
  36.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  37.     x = PInfo->pi_xpos; /* get starting x position */
  38.     ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  39.     sxptr = PInfo->pi_ScaleX;
  40.     width = PInfo->pi_width; /* get # of source pixels */
  41.  
  42.     /* pre-compute threshold; are we thresholding? */
  43.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  44.         dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  45.         do { /* for all source pixels */
  46.             /* pre-compute intensity value for Black */
  47.             Black = ColorInt->colorByte[PCMBLACK];
  48.             ColorInt++; /* bump ptr for next time */
  49.  
  50.             sx = *sxptr++;
  51.  
  52.             /* dither and render pixel */
  53.             do { /* use this pixel 'sx' times */
  54.                 /* if we should render Black */
  55.                 if (Black > dvalue) {
  56.                     /* set bit */
  57.                     *(ptr + (x >> 3)) |= bit_table[x & 7];
  58.                 }
  59.                 ++x; /* done 1 more printer pixel */
  60.             } while (--sx);
  61.         } while (--width);
  62.     }
  63.     else { /* not thresholding, pre-compute ptr to dither matrix */
  64.         dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  65.         do { /* for all source pixels */
  66.             /* pre-compute intensity value for Black */
  67.             Black = ColorInt->colorByte[PCMBLACK];
  68.             ColorInt++; /* bump ptr for next time */
  69.  
  70.             sx = *sxptr++;
  71.  
  72.             /* dither and render pixel */
  73.             do { /* use this pixel 'sx' times */
  74.                 /* if we should render Black */
  75.                 if (Black > dmatrix[x & 3]) {
  76.                     /* set bit */
  77.                     *(ptr + (x >> 3)) |= bit_table[x & 7];
  78.                 }
  79.                 ++x; /* done 1 more printer pixel */
  80.             } while (--sx);
  81.         } while (--width);
  82.     }
  83. }
  84.