gdevstc3.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevstc3.c,v 1.4 2002/02/21 22:24:52 giles Exp $*/
  14. /* Epson Stylus-Color Printer-Driver */
  15. /***
  16. This file holds the sample-implementation of a RGB-algorithm for
  17. the stcolor-driver. It is available via
  18. gs -sDEVICE=stcolor -sDithering=gsrgb ...
  19. Actually this is no dithering-algorithm, it lets ghostscript do the job.
  20. This achieved, by requesting BYTE-Values between 0 and 1 to be delivered,
  21. which causes a depth of 1-Bit by default.
  22. ***/
  23. /*
  24. * gdevstc.h holds all the includes and the driver-specific definitions, so
  25. * it is the only include you need. To add a new algorthim, STC_MODI in
  26. * gdevstc.h should be extended. (see the instructions there)
  27. */
  28. #include "gdevstc.h"
  29. /*
  30. * the routine required.
  31. */
  32. /*ARGSUSED*/
  33. int
  34. stc_gsrgb(stcolor_device *sdev,int npixel,byte *ip,byte *buf,byte *out)
  35. {
  36. int error = 0;
  37. /*
  38. * There are basically 3 Types of calls:
  39. * npixel < 0 => initialize buf, if this is required
  40. * (happens only if requested)
  41. * npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
  42. * in == NULL signals, that the basic-driver has decided
  43. * that this scanline is white. (Useful for really dithering
  44. * drivers)
  45. */
  46. /* ============================================================= */
  47. if(npixel > 0) { /* npixel > 0 -> scanline-processing */
  48. /* ============================================================= */
  49. int p;
  50. /*
  51. * simply merge the color-values into a single byte
  52. * (RED, GREEN, BLUE are defined in gdevstc.h)
  53. */
  54. for(p = 0; p < npixel; ++p,++out) { /* loop over pixels */
  55. *out = 0;
  56. if(*ip++) *out |= RED;
  57. if(*ip++) *out |= GREEN;
  58. if(*ip++) *out |= BLUE;
  59. } /* loop over pixels */
  60. /* ============================================================= */
  61. } else { /* npixel <= 0 -> initialisation */
  62. /* ============================================================= */
  63. /*
  64. * besides buffer-Initialisation, one may check the parameters in
  65. * the algorithm-table of the driver.
  66. */
  67. /* we didn't check for the white-calls above, so they would cause errors */
  68. if(sdev->stc.dither->flags & STC_WHITE) error = -1;
  69. /* if we're not setup for bytes, this is an error too */
  70. if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) error = -2;
  71. /* and rgb-mode is the only supported mode */
  72. if(sdev->color_info.num_components != 3) error = -3;
  73. /* we can't deal with ghostscript-data directly. */
  74. if(sdev->stc.dither->flags & STC_DIRECT) error = -4;
  75. /* ============================================================= */
  76. } /* scanline-processing or initialisation */
  77. /* ============================================================= */
  78. return error;
  79. }