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

  1. %    Copyright (C) 2001, 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_sepr.ps,v 1.2.2.1 2003/12/12 22:07:58 giles Exp $
  14. % Separation color space method dictionary
  15.  
  16.  
  17. % verify that Separation color spaces are supported
  18. /.setseparationspace where
  19.   { pop }
  20.   { currentfile closefile }
  21. ifelse
  22.  
  23. .currentglobal true .setglobal
  24. .cspace_util begin
  25.  
  26.  
  27. %
  28. %   <c1>  <array>   apply_sepr_tint_xform   <c1>' ... <cn>'  <array>
  29. %
  30. % Apply the tint transform for a Separation color space color intensity
  31. % value.
  32. %
  33. /apply_sepr_tint_xform
  34.   {
  35.     exch //bound_0_1 exec
  36.     mark exch 2 index 3 get exec
  37.     counttomark 2 add -2 roll pop
  38.   }
  39. bind def
  40.  
  41.  
  42. %
  43. %  <cspace_array>   build_tintxform_function   <cspace_array>  <proc>
  44. %
  45. % Convert a tint transformation into a function, if possible. If this is
  46. % successful, <proc> will be a function procedure (a two-element,
  47. % execute-only, executable array whose first element is the function
  48. % data structure and whose second element is the operator %execfunction.
  49. % If it is not successful, <proc> will be the same as the tint transform
  50. % in <cspace_array>.
  51. %
  52. % Note that, for PDF files, the tint transform will likely already be a
  53. % function-array. In this case, <proc> will be this array, and thus will
  54. % also be identical to the original tint transform.
  55. %
  56. % This procedure is used for both Separation and DeviceN color spaces.
  57. %
  58. /build_tintxform_function
  59.   {
  60.     dup 3 get dup .isencapfunction not
  61.       {
  62.         % Try a FunctionType 4 function first; build the function dictionary
  63.         % in local VM.
  64.         .currentglobal exch //false .setglobal
  65.     % Make the dictionary a couple of elements large in case this fails
  66.     % and we need the dictionary to build a sampled function.
  67.         6 dict begin
  68.         /FunctionType 4 def
  69.         /Function exch def
  70.         /Domain 2 index //.cs_get_range exec def
  71.         /Range 2 index 2 get //.cs_get_range exec def
  72.         currentdict end
  73.         { .buildfunction }
  74.         .internalstopped    % If .buildfunction fails then not type 4 func.
  75.         {            % If not then try building a sampled (type 0) func.
  76.       % We are using the dictionary which was created before .buildfunction
  77.           dup /Order 3 put
  78.           dup /BitsPerSample 16 put
  79.           { .buildsampledfunction }
  80.           .internalstopped    % If .buildsamplefunction fails then invalid func.
  81.           {            % Failed - Create a dummy tint transform function
  82.         % We are using the dictionary which was created before .buildfunction
  83.             dup /Function {} put    % Replace invalid tint transform with dummy
  84.             .buildfunction
  85.           }
  86.           if        % Check status from .buildsamplefunction/.internalstopped
  87.     }
  88.     if        % check status from .buildfunction/.intermalstopped
  89.         % restore the VM mode
  90.         exch .setglobal
  91.       }
  92.     if
  93.   }
  94. bind def
  95.  
  96. %
  97. %  <array1>  <array2>   converttinttransform   <array1>  <array2'>
  98. %
  99. % Convert a Separation/DeviceN color space to use a function as a tint
  100. % transformation, if this is possible. Possible outcomes are:
  101. %
  102. %  1. The tint transform already is a function, or is a procedure that
  103. %     cannot be converted to a function. In either case, <array2> is
  104. %     left unchanged (<array2> == <array2'>).
  105. %
  106. %  2. The tint transform is not already a function but can be converted
  107. %     to a function, and <array1> != <array2>. In this case, <array2>
  108. %     is modified directly.
  109. %
  110. %  3. The tint transform is not already a function but can be converted
  111. %     to a function, and <array1> == <array2>. In this case, <array2>
  112. %     is copied, and the copy is modified (i.e., after the operation
  113. %     <array1> != <array2>
  114. %
  115. % This slightly complex approach avoids creating an extra color space
  116. % array unnecessarily.
  117. %
  118. /converttinttransform
  119.   {
  120.     % convert the tint transform to a fucntion
  121.     //build_tintxform_function exec
  122.  
  123.     % see if anything needs to be modified
  124.     1 index 3 get 2 copy eq
  125.       { pop pop }
  126.       {
  127.         pop
  128.  
  129.         % see if the color space must be copied
  130.         3 copy pop eq
  131.           {
  132.             % copy the array into local VM
  133.             .currentglobal //false .setglobal
  134.             3 -1 roll dup length array copy 3 1 roll
  135.             .setglobal
  136.           }
  137.         if
  138.         1 index exch 3 exch put
  139.       }
  140.     ifelse
  141.   }
  142. bind def
  143.  
  144.  
  145. colorspacedict
  146. /Separation
  147.   mark
  148.     /cs_potential_indexed_base true
  149.     /cs_potential_pattern_base true
  150.     /cs_potential_alternate false
  151.     /cs_potential_icc_alternate false
  152.     /cs_get_ncomps //ncomps_1
  153.     /cs_get_range //get_range_1
  154.     /cs_get_default_color { pop 1 } bind
  155.  
  156.     /cs_get_currentgray
  157.       { //apply_sepr_tint_xform exec 2 get //.cs_get_currentgray exec }
  158.     bind
  159.     /cs_get_currentrgb
  160.       { //apply_sepr_tint_xform exec 2 get //.cs_get_currentrgb exec }
  161.     bind
  162.     /cs_get_currentcmyk
  163.       { //apply_sepr_tint_xform exec 2 get //.cs_get_currentcmyk exec }
  164.     bind
  165.  
  166.     % a lot of validation is done by the cs_validate method
  167.     /cs_validate
  168.       {
  169.         //check_array exec
  170.         dup 1 get type dup /nametype ne exch /stringtype ne and
  171.           //setcspace_typecheck
  172.         if
  173.         dup 2 get //.cs_validate exec //.cs_potential_alternate exec not
  174.           //setcspace_rangecheck
  175.         if
  176.         dup 3 get //check_array exec xcheck not
  177.           //setcspace_typecheck
  178.         if
  179.       }
  180.     bind
  181.  
  182.     % substitute the base space if appropriate
  183.     /cs_substitute
  184.       {
  185.         dup 2 get //.cs_substitute exec 2 copy eq
  186.           { pop pop dup }
  187.           {
  188.             % retain only the new alternate space
  189.             exch pop
  190.  
  191.             % build all new structures in local VM
  192.             .currentglobal 3 1 roll //false .setglobal
  193.  
  194.             % construct a new array and insert the new base color space
  195.             1 index dup length array copy dup 2 4 -1 roll put
  196.  
  197.             % restore VM mode
  198.             3 -1 roll .setglobal
  199.           }
  200.         ifelse
  201.       }
  202.     bind
  203.  
  204.     %
  205.     % The Ghostscript interpreter works better when tinttransform procedures
  206.     % are translated into functions. Attempt to do that here.
  207.     %
  208.     /cs_prepare //converttinttransform
  209.  
  210.     %
  211.     % Install the current color space.
  212.     %
  213.     % The current Ghostscript color space implementation requires that
  214.     % color spaces that provide a base or alternative color space set
  215.     % that base/alternative color space to be the current color space
  216.     % before attempting to set the original color space.
  217.     %
  218.     /cs_install
  219.       {
  220.         % save the current color space
  221.         currentcolorspace
  222.  
  223.         % set the base color space as the current color space
  224.         1 index 2 get //forcesetcolorspace
  225.  
  226.         % set the indexed color space; restore the earlier space on error
  227.         mark 2 index
  228.           { .setseparationspace }
  229.         stopped
  230.           { cleartomark setcolorspace stop }
  231.           { pop pop pop }
  232.         ifelse
  233.       }
  234.     bind
  235.  
  236.     /cs_prepare_color //validate_1
  237.  
  238.     %
  239.     % If a Separation color space is not supported in native mode by
  240.     % the current process color model, Adobe implementations will always
  241.     % execute the tint transform procedure when setcolor is invoked.
  242.     % Ghostscript may have turned this transform into a sampled function,
  243.     % and even if this is not the case, will have sampled the transform
  244.     % when the color space is first set. Some applications may depend
  245.     % on the Adobe behavior, so we implement it via the
  246.     % cs_complete_setcolor method.
  247.     %
  248.     /cs_complete_setcolor
  249.       {
  250.         .usealternate
  251.           {
  252.             currentcolor exch 3 get exec
  253.             currentcolorspace 2 get //clear_setcolor_operands exec
  254.           }
  255.           { pop }
  256.         ifelse
  257.       }
  258.     bind
  259.  
  260.   .dicttomark
  261. put
  262.  
  263. end     % .cspace_util
  264. .setglobal
  265.