home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / gs_indxd.ps < prev    next >
Text File  |  2002-11-14  |  6KB  |  205 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_indxd.ps,v 1.2 2002/11/13 20:23:10 alexcher Exp $
  14. % Indexed color space method dictionary
  15.  
  16.  
  17. % verify that Indexed color spaces are supported
  18. /.setindexedspace where
  19.   { pop }
  20.   { currentfile closefile }
  21. ifelse
  22.  
  23. .currentglobal true .setglobal
  24. .cspace_util begin
  25.  
  26. %
  27. %   <num>  <array>   restrict_index   <int>  <array>
  28. %
  29. % Restrict the operand to setcolor for an Indexed color space to be an
  30. % integer in the applicable range.
  31. %
  32. /restrict_index
  33.   {
  34.     exch round cvi
  35.     dup 0 lt
  36.       { pop 0 }
  37.       {
  38.         1 index 2 get 2 copy gt
  39.           { exch }
  40.         if
  41.         pop
  42.       } 
  43.     ifelse
  44.     exch
  45.   }
  46. bind def
  47.  
  48. %
  49. %   <num>  <array>   get_indexed_base_color   <c1> ... <cn>  <array>
  50. %
  51. % Get the base color corresponding to an indexed color value.
  52. %
  53. /get_indexed_base_color
  54.   {
  55.     % just in case, set the index into the appropriate range
  56.     //restrict_index exec
  57.  
  58.     % lookup in the string or use the lookup proc
  59.     mark 1 index 3 get dup type /stringtype eq
  60.       {
  61.         2 index 1 get //.cs_get_ncomps exec dup 6 -1 roll mul exch getinterval
  62.           { 255 div }
  63.         forall
  64.       }
  65.       { 4 -1 roll exch exec }
  66.     ifelse
  67.     counttomark 2 add -2 roll pop
  68.   }
  69. bind def
  70.  
  71.  
  72. colorspacedict
  73. /Indexed
  74.   mark
  75.     /cs_potential_indexed_base false
  76.     /cs_potential_pattern_base true
  77.     /cs_potential_alternate false
  78.     /cs_potential_icc_alternate false
  79.     /cs_get_ncomps //ncomps_1
  80.     /cs_get_range { 0 exch 2 get 2 array astore } bind
  81.     /cs_get_default_color { pop 0 } bind
  82.  
  83.     /cs_get_currentgray
  84.       { //get_indexed_base_color exec 1 get //.cs_get_currentgray exec }
  85.     bind
  86.     /cs_get_currentrgb
  87.       { //get_indexed_base_color exec 1 get //.cs_get_currentrgb exec }
  88.     bind
  89.     /cs_get_currentcmyk
  90.       { //get_indexed_base_color exec 1 get //.cs_get_currentcmyk exec }
  91.     bind
  92.  
  93.     % a lot of validation is done by the cs_validate method
  94.     /cs_validate
  95.       {
  96.         //check_array exec
  97.         dup 1 get //.cs_validate exec //.cs_potential_indexed_base exec not
  98.           //setcspace_rangecheck
  99.         if
  100.         dup 2 get dup type /integertype ne
  101.           //setcspace_typecheck
  102.           {
  103.             dup 0 lt exch 4095 gt or
  104.               //setcspace_rangecheck
  105.             if
  106.           }
  107.         ifelse
  108.         dup 3 get dup type /stringtype eq
  109.           {
  110.             length
  111.             1 index dup 2 get 1 add exch 1 get //.cs_get_ncomps exec mul
  112.             lt
  113.               //setcspace_rangecheck
  114.             if
  115.           }
  116.           {
  117.             //check_array exec xcheck not
  118.               //setcspace_typecheck
  119.             if
  120.           }
  121.         ifelse
  122.       }
  123.     bind
  124.  
  125.     % substitute the base space if appropriate
  126.     /cs_substitute
  127.       {
  128.         dup 1 get //.cs_substitute exec 2 copy eq
  129.           { pop pop dup }
  130.           {
  131.             % retain only the new base space
  132.             exch pop
  133.  
  134.             % build all new structures in local VM
  135.             .currentglobal 3 1 roll //false .setglobal
  136.  
  137.             % construct a new array and insert the new base color space            
  138.             1 index dup length array copy dup 1 4 -1 roll put
  139.  
  140.             % restore VM mode
  141.             3 -1 roll .setglobal
  142.           }
  143.         ifelse
  144.       }
  145.     bind
  146.  
  147.     /cs_prepare {}
  148.  
  149.     %
  150.     % Install the current color space. Note that the alternative color
  151.     % space will already have been set as the current color space.
  152.     %
  153.     % The current Ghostscript color space implementation requires that
  154.     % color spaces that provide a base or alternative color space set
  155.     % that base/alternative color space to be the current color space
  156.     % before attempting to set the original color space.
  157.     %
  158.     /cs_install
  159.       {
  160.         % save the current color space
  161.         currentcolorspace
  162.  
  163.         % set the base color space as the current color space
  164.         1 index 1 get //forcesetcolorspace
  165.  
  166.         % set the indexed color space; restore the earlier space on error
  167.         mark 2 index
  168.           { .setindexedspace }
  169.         stopped
  170.           { cleartomark setcolorspace stop }
  171.           { pop pop pop }
  172.         ifelse
  173.       }
  174.     bind
  175.  
  176.     /cs_prepare_color //validate_1
  177.  
  178.     %
  179.     % Adobe implementations always execute a lookup procedure when setcolor
  180.     % is invoked. Ghostscript samples the lookup procedure when
  181.     % setcolorspace is invoked, and then does not access it again. In the
  182.     % unlikely event that an application depends on the Adobe-specific
  183.     % behavior, it is replicated in this method.
  184.     %
  185.     /cs_complete_setcolor
  186.       {
  187.         3 get dup type /stringtype eq
  188.           { pop }
  189.           {
  190.             currentcolor exch exec
  191.             currentcolorspace 1 get //clear_setcolor_operands exec
  192.           }
  193.         ifelse
  194.       }
  195.     bind
  196.  
  197.   .dicttomark
  198. put
  199.  
  200. end     % .cspace_util
  201. .setglobal
  202.