gdevstc1.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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: gdevstc1.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 monochrome-algorithm for
  17. the stcolor-driver. It is available via
  18. gs -sDEVICE=stcolor -sDithering=gsmono ...
  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_gsmono(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
  35. {
  36. /*
  37. * There are basically 3 Types of calls:
  38. * npixel < 0 => initialize buf, if this is required
  39. * (happens only if requested)
  40. * npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
  41. * in == NULL signals, that the basic-driver has decided
  42. * that this scanline is white. (Useful for really dithering
  43. * drivers)
  44. */
  45. /* ============================================================= */
  46. if(npixel > 0) { /* npixel > 0 -> scanline-processing */
  47. /* ============================================================= */
  48. /* -----------------------------------------------*/
  49. if(in != NULL) { /* normal processing */
  50. /* -----------------------------------------------*/
  51. memcpy(out,in,npixel); /* really simple algorithm */
  52. /* -----------------------------------------------*/
  53. } else { /* skip-notification */
  54. /* -----------------------------------------------*/
  55. /* An algorithm may use the output-line as a buffer.
  56. So it might need to be cleared on white-lines.
  57. */
  58. memset(out,0,npixel);
  59. /* -----------------------------------------------*/
  60. } /* normal / skip */
  61. /* -----------------------------------------------*/
  62. /* ============================================================= */
  63. } else { /* npixel <= 0 -> initialisation */
  64. /* ============================================================= */
  65. /*
  66. * the optional buffer is already allocated by the basic-driver, here
  67. * you just need to fill it, for instance, set it all to zeros:
  68. */
  69. int buf_size;
  70. /*
  71. * compute the size of the buffer, according to the requested values
  72. * the buffer consists of a constant part, e.g. related to the number
  73. * of color-components, and a number of arrays, which are multiples of
  74. * the size of a scanline times the number of components.
  75. * additionally, the size of the scanlines may be expanded by one to the
  76. * right and to the left.
  77. */
  78. buf_size =
  79. sdev->stc.dither->bufadd /* scanline-independend size */
  80. + (-npixel) /* pixels */
  81. * (sdev->stc.dither->flags/STC_SCAN) /* * scanlines */
  82. * sdev->color_info.num_components; /* * comp */
  83. if(buf_size > 0) { /* we obviously have a buffer */
  84. memset(buf,0,buf_size * sdev->stc.alg_item);
  85. } /* we obviously have a buffer */
  86. /*
  87. * Usually one should check parameters upon initializaon
  88. */
  89. if(sdev->color_info.num_components != 1) return -1;
  90. if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) return -2;
  91. /*
  92. * must neither have STC_DIRECT nor STC_WHITE
  93. */
  94. if((sdev->stc.dither->flags & STC_DIRECT) != 0) return -3;
  95. } /* scanline-processing or initialisation */
  96. return 0; /* negative values are error-codes, that abort printing */
  97. }