home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_devcs.ps < prev    next >
Text File  |  2003-12-13  |  6KB  |  235 lines

  1. %    Copyright (C) 2002 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: gs_devcs.ps,v 1.1.2.1 2003/12/12 22:07:58 giles Exp $
  14. % Device-specific color space method dictionaries.
  15.  
  16. %
  17. % This file implements the method dictionaries for the Device-specific
  18. % color spaces. See gs_cspace.ps for information.
  19. %
  20. % Note that, because these color spaces are parameter-less, no color
  21. % space validation is required: if we can get to the color space methods,
  22. % we know the color space is legitimate.
  23. %
  24. % The colorspace substitution routines for these color spaces
  25. % (cs_substitute) will fail in a Level 1 system, but this is not a
  26. % problem as .getuseciecolor will always return false for such systems.
  27. %
  28. .currentglobal true .setglobal
  29. .cspace_util begin
  30.  
  31. %
  32. %   <r>  <g>  <b>   rgb_2_gray   <gray>
  33. %
  34. % Convert RGB colors to gray. This includes a special check for
  35. % r == g == b, and avoids roundoff error if this is the case.
  36. %
  37. /rgb_2_gray
  38.   {
  39.     3 copy 1 index eq 3 1 roll eq and
  40.       { pop pop }
  41.       { .11 mul exch .59 mul add exch .3 mul add }
  42.     ifelse
  43.   }
  44. bind def
  45.  
  46. systemdict /..page_default_spaces 3 dict put
  47.  
  48. % <color_space_name> ..includecolorspace -
  49. /..includecolorspace
  50. { % Only includes ones explicitly defined by the document.
  51.   systemdict /..page_default_spaces get 1 index known {
  52.     pop
  53.   } {
  54.     mark exch
  55.     { dup /ColorSpace resourcestatus {
  56.         pop 0 eq {
  57.           systemdict /..page_default_spaces get 1 index //true put
  58.           gsave
  59.           { dup /ColorSpace findresource //_setcolorspace_nosub exec .includecolorspace
  60.           } stopped pop
  61.           grestore
  62.         } if
  63.       } if
  64.     } stopped pop
  65.     cleartomark
  66.   } ifelse
  67. } bind def
  68.  
  69. % <color_space> <color_space_name> cs_substitute_generic <color_space1> <color_space2>
  70. /cs_substitute_generic
  71. { .getuseciecolor
  72.     { NOSUBSTDEVICECOLORS 
  73.         { //..includecolorspace exec dup }
  74.         { /ColorSpace findresource }
  75.       ifelse
  76.     }
  77.     { pop dup }
  78.   ifelse
  79. }
  80. bind def
  81.  
  82.  
  83. colorspacedict
  84.  
  85. dup
  86. /DeviceGray
  87.   mark
  88.     /cs_potential_indexed_base true
  89.     /cs_potential_pattern_base true
  90.     /cs_potential_alternate true
  91.     /cs_potential_icc_alternate true
  92.     /cs_get_ncomps //ncomps_1
  93.     /cs_get_range  //get_range_1
  94.     /cs_get_default_color { pop 0 } bind
  95.     /cs_get_currentgray //pop_1
  96.     /cs_get_currentrgb { pop dup dup } bind
  97.     /cs_get_currentcmyk { pop 1 exch sub 0 0 0 4 -1 roll } bind
  98.     /cs_validate {}
  99.  
  100.     /cs_substitute
  101.       { /DefaultGray //cs_substitute_generic exec
  102.       }
  103.     bind
  104.  
  105.     /cs_prepare {}
  106.     /cs_install { pop 0 .setdevcspace } bind
  107.     /cs_prepare_color //validate_1
  108.     /cs_complete_setcolor //pop_1
  109.   .dicttomark
  110. put
  111.  
  112.  
  113. /DeviceRGB
  114.   mark
  115.     /cs_potential_indexed_base true
  116.     /cs_potential_pattern_base true
  117.     /cs_potential_alternate true
  118.     /cs_potential_icc_alternate true
  119.     /cs_get_ncomps //ncomps_3
  120.     /cs_get_range  //get_range_3
  121.     /cs_get_default_color { pop 0 0 0 } bind
  122.     /cs_get_currentgray { pop //rgb_2_gray exec } bind
  123.     /cs_get_currentrgb //pop_1
  124.  
  125.     % to convert to cmyk use blackgeneration and undercolorremoval
  126.     /cs_get_currentcmyk
  127.       {
  128.         pop
  129.  
  130.         % convert to subtractive (CMY) color space
  131.         3
  132.           { 1 exch sub 3 1 roll }
  133.         repeat
  134.  
  135.         % find the minimum (initial k component)
  136.         3 copy
  137.         2
  138.           {
  139.             2 copy gt
  140.               { exch }
  141.             if
  142.             pop
  143.           }
  144.         repeat
  145.  
  146.         % apply undercolorremoval
  147.         dup 5 1 roll currentundercolorremoval exec 4 1 roll
  148.         3
  149.           { 3 index sub //bound_0_1 exec 3 1 roll }
  150.         repeat
  151.  
  152.         % apply blackgeneration
  153.         5 3 roll pop currentblackgeneration exec //bound_0_1 exec
  154.       }
  155.     bind
  156.  
  157.     /cs_validate {}
  158.  
  159.     /cs_substitute
  160.       { /DefaultRGB //cs_substitute_generic exec
  161.       }
  162.     bind
  163.  
  164.     /cs_prepare {}
  165.     /cs_install { pop 1 .setdevcspace } bind
  166.     /cs_prepare_color //validate_3
  167.     /cs_complete_setcolor //pop_1
  168.   .dicttomark
  169. put
  170.  
  171. end     % .cspace_util
  172. .setglobal
  173.  
  174.  
  175. % Only create the DeviceCMYK color space if setcolorscreen is present
  176. /setcolorscreen where
  177.   { pop }
  178.   { currentfile closefile }
  179. ifelse
  180.  
  181.  
  182. .currentglobal true .setglobal
  183. .cspace_util begin
  184.  
  185. colorspacedict
  186. /DeviceCMYK
  187.   mark
  188.     /cs_potential_indexed_base true
  189.     /cs_potential_pattern_base true
  190.     /cs_potential_alternate true
  191.     /cs_potential_icc_alternate true
  192.     /cs_get_ncomps //ncomps_4
  193.     /cs_get_range  //get_range_4
  194.     /cs_get_default_color { pop 0 0 0 1 } bind
  195.  
  196.     /cs_get_currentgray
  197.       { pop 4 1 roll //rgb_2_gray exec add 1 exch sub //bound_0_1 exec }
  198.     bind
  199.  
  200.     /cs_get_currentrgb 
  201.       {
  202.         pop
  203.         4 1 roll 3
  204.           { 3 index add  1 exch sub //bound_0_1 exec 3 1 roll }
  205.         repeat
  206.         4 -1 roll pop
  207.       }
  208.     bind
  209.  
  210.     /cs_get_currentcmyk //pop_1
  211.  
  212.     /cs_validate {}
  213.  
  214.     /cs_substitute
  215.       { /DefaultCMYK //cs_substitute_generic exec
  216.       }
  217.     bind
  218.  
  219.     /cs_prepare {}
  220.     /cs_install { pop 2 .setdevcspace } bind
  221.     /cs_prepare_color //validate_4
  222.     /cs_complete_setcolor //pop_1
  223.   .dicttomark
  224. put
  225.  
  226. currentdict /..includecolorspace .undef
  227. currentdict /cs_substitute_generic .undef
  228.  
  229. end     % .cspace_util
  230. .setglobal
  231.  
  232.