home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / printing / ghostscrip / source / _gs / c / gspaint < prev    next >
Encoding:
Text File  |  1991-10-26  |  4.4 KB  |  155 lines

  1. /* Copyright (C) 1989, 1990 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gspaint.c */
  21. /* Painting procedures for GhostScript library */
  22. #include "gx.h"
  23. #include "gxfixed.h"
  24. #include "gxmatrix.h"            /* for gs_state */
  25. #include "gspaint.h"
  26. #include "gzpath.h"
  27. #include "gzstate.h"
  28. #include "gzdevice.h"
  29. #include "gzcolor.h"
  30. #include "gximage.h"
  31.  
  32. /* Erase the page */
  33. int
  34. gs_erasepage(gs_state *pgs)
  35. {    device *pdev = pgs->device;
  36.     gx_device *dev = pdev->info;
  37.     (*dev->procs->fill_rectangle)(dev, 0, 0, dev->width, dev->height, pdev->white);
  38.     return 0;
  39. }
  40.  
  41. /* Fill using the winding number rule */
  42. int
  43. gs_fill(gs_state *pgs)
  44. {    return gs_fill_adjust(pgs, (fixed)0);
  45. }
  46. /* This is a hack, see gx_fill_path and gs_type1_interpret. */
  47. int
  48. gs_fill_adjust(gs_state *pgs, fixed adjust)
  49. {    int code;
  50.     /* If we're inside a charpath, just merge the current path */
  51.     /* into the parent's path. */
  52.     if ( pgs->in_charpath )
  53.         code = gx_path_merge(pgs->path, pgs->saved->path);
  54.     else
  55.        {    gx_color_load(pgs->dev_color, pgs);
  56.         code = gx_fill_path(pgs->path, pgs->dev_color, pgs,
  57.                     gx_rule_winding_number, adjust);
  58.        }
  59.     if ( !code ) gs_newpath(pgs);
  60.     return code;
  61. }
  62.  
  63. /* Fill using the even/odd rule */
  64. int
  65. gs_eofill(gs_state *pgs)
  66. {    int code;
  67.     /* If we're inside a charpath, just merge the current path */
  68.     /* into the parent's path. */
  69.     if ( pgs->in_charpath )
  70.         code = gx_path_merge(pgs->path, pgs->saved->path);
  71.     else
  72.        {    gx_color_load(pgs->dev_color, pgs);
  73.         code = gx_fill_path(pgs->path, pgs->dev_color, pgs,
  74.                     gx_rule_even_odd, (fixed)0);
  75.        }
  76.     if ( !code ) gs_newpath(pgs);
  77.     return code;
  78. }
  79.  
  80. /* Stroke the current path */
  81. int
  82. gs_stroke(gs_state *pgs)
  83. {    int code;
  84.     /* If we're inside a charpath, just merge the current path */
  85.     /* into the parent's path. */
  86.     if ( pgs->in_charpath )
  87.         code = gx_path_merge(pgs->path, pgs->saved->path);
  88.     else
  89.        {    gx_color_load(pgs->dev_color, pgs);
  90.         code = gx_stroke_fill(pgs->path, pgs);
  91.        }
  92.     if ( !code ) gs_newpath(pgs);
  93.     return code;
  94. }
  95.  
  96. /* Compute the stroked outline of the current path */
  97. int
  98. gs_strokepath(gs_state *pgs)
  99. {    gx_path spath;
  100.     int code;
  101.     gx_path_init(&spath, &pgs->memory_procs);
  102.     code = gx_stroke_add(pgs->path, &spath, pgs);
  103.     if ( code < 0 ) return code;
  104.     gx_path_release(pgs->path);
  105.     *pgs->path = spath;
  106.     return 0;
  107. }
  108.  
  109. /* Render a sampled image */
  110. int
  111. gs_colorimage(gs_state *pgs, int width, int height, int bps, int spp,
  112.   gs_matrix *pmat, byte *data)
  113. {    gs_image_enum ienum;
  114.     int code;
  115.     if ( (code = gs_image_init(&ienum, pgs, width, height, bps, spp, pmat)) < 0 )
  116.         return code;
  117.     if ( spp > 0 )
  118.        {    uint size =
  119.             (((uint)width * bps * spp + 7) >> 3) * (uint)height;
  120.         code = gs_image_next(&ienum, data, size);
  121.        }
  122.     else
  123.        {    /* Deliver the colors separately */
  124.         uint plane_size =
  125.             (((uint)width * bps + 7) >> 3) * (uint)height;
  126.         byte *plane_data = data;
  127.         int count = spp;
  128.         do
  129.            {    code = gs_image_next(&ienum, plane_data, plane_size);
  130.             if ( code < 0 ) return code;
  131.             plane_data += plane_size;
  132.            }
  133.         while ( ++count );
  134.        }
  135.     return (code < 0 ? code : 0);
  136. }
  137. int
  138. gs_image(gs_state *pgs, int width, int height, int bps,
  139.   gs_matrix *pmat, byte *data)
  140. {    return gs_colorimage(pgs, width, height, bps, 1, pmat, data);
  141. }
  142.  
  143. /* Render a mask */
  144. int
  145. gs_imagemask(gs_state *pgs, int width, int height, int invert,
  146.   gs_matrix *pmat, byte *data, int adjust)
  147. {    gs_image_enum ienum;
  148.     int code;
  149.     uint size = (((uint)width + 7) >> 3) * (uint)height;
  150.     if ( (code = gs_imagemask_init(&ienum, pgs, width, height, invert, pmat, adjust)) < 0 )
  151.         return code;
  152.     code = gs_image_next(&ienum, data, size);
  153.     return (code < 0 ? code : 0);
  154. }
  155.