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

  1. /*
  2.         Example transfer routine for HP_LaserJet driver.
  3.  
  4.         Transfer() should be written in assembly code for speed
  5. */
  6.  
  7. #include <exec/types.h>
  8. #include <devices/prtgfx.h>
  9.  
  10. Transfer(PInfo, y, ptr)
  11. struct PrtInfo *PInfo;
  12. UWORD y;        /* row # */
  13. UBYTE *ptr;     /* ptr to buffer */
  14. {
  15.         static UBYTE bit_table[] = {128, 64, 32, 16, 8, 4, 2, 1};
  16.         UBYTE *dmatrix, Black, dvalue, threshold;
  17.         union colorEntry *ColorInt;
  18.         UWORD x, width, sx, *sxptr, bit;
  19.  
  20.         /* pre-compute */
  21.         /* printer non-specific, MUST DO FOR EVERY PRINTER */
  22.         x = PInfo->pi_xpos; /* get starting x position */
  23.         ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  24.         sxptr = PInfo->pi_ScaleX;
  25.         width = PInfo->pi_width; /* get # of source pixels */
  26.  
  27.         /* pre-compute threshold; are we thresholding? */
  28.         if (threshold = PInfo->pi_threshold) { /* thresholding */
  29.                 dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  30.                 do { /* for all source pixels */
  31.                         /* pre-compute intensity value for Black */
  32.                         Black = ColorInt->colorByte[PCMBLACK];
  33.                         ColorInt++; /* bump ptr for next time */
  34.  
  35.                         sx = *sxptr++;
  36.  
  37.                         /* dither and render pixel */
  38.                         do { /* use this pixel 'sx' times */
  39.                                 /* if we should render Black */
  40.                                 if (Black > dvalue) {
  41.                                         /* set bit */
  42.                                         *(ptr + (x >> 3)) |= bit_table[x & 7];
  43.                                 }
  44.                                 ++x; /* done 1 more printer pixel */
  45.                         } while (--sx);
  46.                 } while (--width);
  47.         }
  48.         else { /* not thresholding, pre-compute ptr to dither matrix */
  49.                 dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  50.                 do { /* for all source pixels */
  51.                         /* pre-compute intensity value for Black */
  52.                         Black = ColorInt->colorByte[PCMBLACK];
  53.                         ColorInt++; /* bump ptr for next time */
  54.  
  55.                         sx = *sxptr++;
  56.  
  57.                         /* dither and render pixel */
  58.                         do { /* use this pixel 'sx' times */
  59.                                 /* if we should render Black */
  60.                                 if (Black > dmatrix[x & 3]) {
  61.                                         /* set bit */
  62.                                         *(ptr + (x >> 3)) |= bit_table[x & 7];
  63.                                 }
  64.                                 ++x; /* done 1 more printer pixel */
  65.                         } while (--sx);
  66.                 } while (--width);
  67.         }
  68. }
  69.