home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Printer / hp / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-03  |  4.1 KB  |  95 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.  *      Example transfer routine for HP_LaserJet driver.
  29.  *
  30.  *      Transfer() should be written in assembly code for speed
  31.  */
  32.  
  33. #include <exec/types.h>
  34. #include <devices/prtgfx.h>
  35.  
  36. Transfer(PInfo, y, ptr)
  37. struct PrtInfo *PInfo;
  38. UWORD y;        /* row # */
  39. UBYTE *ptr;     /* ptr to buffer */
  40. {
  41.         static UBYTE bit_table[] = {128, 64, 32, 16, 8, 4, 2, 1};
  42.         UBYTE *dmatrix, Black, dvalue, threshold;
  43.         union colorEntry *ColorInt;
  44.         UWORD x, width, sx, *sxptr, bit;
  45.  
  46.         /* pre-compute */
  47.         /* printer non-specific, MUST DO FOR EVERY PRINTER */
  48.         x = PInfo->pi_xpos; /* get starting x position */
  49.         ColorInt = PInfo->pi_ColorInt; /* get ptr to color intensities */
  50.         sxptr = PInfo->pi_ScaleX;
  51.         width = PInfo->pi_width; /* get # of source pixels */
  52.  
  53.         /* pre-compute threshold; are we thresholding? */
  54.         if (threshold = PInfo->pi_threshold) { /* thresholding */
  55.                 dvalue = threshold ^ 15; /* yes, so pre-compute dither value */
  56.                 do { /* for all source pixels */
  57.                         /* pre-compute intensity value for Black */
  58.                         Black = ColorInt->colorByte[PCMBLACK];
  59.                         ColorInt++; /* bump ptr for next time */
  60.  
  61.                         sx = *sxptr++;
  62.  
  63.                         /* dither and render pixel */
  64.                         do { /* use this pixel 'sx' times */
  65.                                 /* if we should render Black */
  66.                                 if (Black > dvalue) {
  67.                                         /* set bit */
  68.                                         *(ptr + (x >> 3)) |= bit_table[x & 7];
  69.                                 }
  70.                                 ++x; /* done 1 more printer pixel */
  71.                         } while (--sx);
  72.                 } while (--width);
  73.         }
  74.         else { /* not thresholding, pre-compute ptr to dither matrix */
  75.                 dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  76.                 do { /* for all source pixels */
  77.                         /* pre-compute intensity value for Black */
  78.                         Black = ColorInt->colorByte[PCMBLACK];
  79.                         ColorInt++; /* bump ptr for next time */
  80.  
  81.                         sx = *sxptr++;
  82.  
  83.                         /* dither and render pixel */
  84.                         do { /* use this pixel 'sx' times */
  85.                                 /* if we should render Black */
  86.                                 if (Black > dmatrix[x & 3]) {
  87.                                         /* set bit */
  88.                                         *(ptr + (x >> 3)) |= bit_table[x & 7];
  89.                                 }
  90.                                 ++x; /* done 1 more printer pixel */
  91.                         } while (--sx);
  92.                 } while (--width);
  93.         }
  94. }
  95.