gdevstc1.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Copyright (C) 1995, 1996 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gdevstc1.c,v 1.2 2000/09/19 19:00:22 lpd Exp $*/
  16. /* Epson Stylus-Color Printer-Driver */
  17. /***
  18. This file holds the sample-implementation of a monochrome-algorithm for
  19. the stcolor-driver. It is available via
  20. gs -sDEVICE=stcolor -sDithering=gsmono ...
  21. Actually this is no dithering-algorithm, it lets ghostscript do the job.
  22. This achieved, by requesting BYTE-Values between 0 and 1 to be delivered,
  23. which causes a depth of 1-Bit by default.
  24. ***/
  25. /*
  26. * gdevstc.h holds all the includes and the driver-specific definitions, so
  27. * it is the only include you need. To add a new algorthim, STC_MODI in
  28. * gdevstc.h should be extended. (see the instructions there)
  29. */
  30. #include "gdevstc.h"
  31. /*
  32. * the routine required.
  33. */
  34. /*ARGSUSED*/
  35. int
  36. stc_gsmono(stcolor_device *sdev,int npixel,byte *in,byte *buf,byte *out)
  37. {
  38. /*
  39. * There are basically 3 Types of calls:
  40. * npixel < 0 => initialize buf, if this is required
  41. * (happens only if requested)
  42. * npixel > 0 => process next scanline, if the flag STC_WHITE is set, then
  43. * in == NULL signals, that the basic-driver has decided
  44. * that this scanline is white. (Useful for really dithering
  45. * drivers)
  46. */
  47. /* ============================================================= */
  48. if(npixel > 0) { /* npixel > 0 -> scanline-processing */
  49. /* ============================================================= */
  50. /* -----------------------------------------------*/
  51. if(in != NULL) { /* normal processing */
  52. /* -----------------------------------------------*/
  53. memcpy(out,in,npixel); /* really simple algorithm */
  54. /* -----------------------------------------------*/
  55. } else { /* skip-notification */
  56. /* -----------------------------------------------*/
  57. /* An algorithm may use the output-line as a buffer.
  58. So it might need to be cleared on white-lines.
  59. */
  60. memset(out,0,npixel);
  61. /* -----------------------------------------------*/
  62. } /* normal / skip */
  63. /* -----------------------------------------------*/
  64. /* ============================================================= */
  65. } else { /* npixel <= 0 -> initialisation */
  66. /* ============================================================= */
  67. /*
  68. * the optional buffer is already allocated by the basic-driver, here
  69. * you just need to fill it, for instance, set it all to zeros:
  70. */
  71. int buf_size;
  72. /*
  73. * compute the size of the buffer, according to the requested values
  74. * the buffer consists of a constant part, e.g. related to the number
  75. * of color-components, and a number of arrays, which are multiples of
  76. * the size of a scanline times the number of components.
  77. * additionally, the size of the scanlines may be expanded by one to the
  78. * right and to the left.
  79. */
  80. buf_size =
  81. sdev->stc.dither->bufadd /* scanline-independend size */
  82. + (-npixel) /* pixels */
  83. * (sdev->stc.dither->flags/STC_SCAN) /* * scanlines */
  84. * sdev->color_info.num_components; /* * comp */
  85. if(buf_size > 0) { /* we obviously have a buffer */
  86. memset(buf,0,buf_size * sdev->stc.alg_item);
  87. } /* we obviously have a buffer */
  88. /*
  89. * Usually one should check parameters upon initializaon
  90. */
  91. if(sdev->color_info.num_components != 1) return -1;
  92. if((sdev->stc.dither->flags & STC_TYPE) != STC_BYTE) return -2;
  93. /*
  94. * must neither have STC_DIRECT nor STC_WHITE
  95. */
  96. if((sdev->stc.dither->flags & STC_DIRECT) != 0) return -3;
  97. } /* scanline-processing or initialisation */
  98. return 0; /* negative values are error-codes, that abort printing */
  99. }