[gs-code-review] Partial fix for 06-09.ps

Alex Cherepanov alexcher at quadnet.net
Thu Nov 2 21:38:55 PST 2006


The proposed patch fixes all issues in CET 09-06.ps except /limitcheck
for a DeviceN color space with 250 components. PLRM leaves the number
of supported separation names up to the implementation.

Proposed log message:
Change attributes of the array form of the device color spaces.
Fix a bug in HSB to RGB conversion introduced in rev. 7124.
Simplify equality testing of color spaces: names match corresponding
array forms, all other match when color space arrays are equal.
Accept float value as a color value for an indexed color space.
Fixes CET 06-09.PS and many other test cases.

DIFFERENCES:
Progression in colorcir.ps compared to a short-lived rev. 7124.

-------------- next part --------------
Index: gs/lib/gs_cspace.ps
===================================================================
--- gs/lib/gs_cspace.ps	(revision 7149)
+++ gs/lib/gs_cspace.ps	(working copy)
@@ -237,7 +237,14 @@
 userdict /.cspace_util 80 dict put
 .cspace_util begin
 
+
+% Global, read-only, unpacked, array-form device color spaces
 %
+/DeviceGray_array /DeviceGray 1 array astore readonly def
+/DeviceRGB_array  /DeviceRGB  1 array astore readonly def
+/DeviceCMYK_array /DeviceCMYK 1 array astore readonly def
+
+%
 % Colorspacedict is initially in .cspace_util; it is copied to level2dict
 % in the Level 2 initialization code to retain compatibility with 
 % earlier implementations.
@@ -255,7 +262,9 @@
 /make_array1
   {
     dup type /nametype eq
-      { currentglobal true setglobal exch 1 array astore exch setglobal }
+      {
+        currentglobal true setglobal exch 1 array astore exch setglobal
+      }
     if
   }
 bind def
@@ -387,9 +396,8 @@
 % NB: This should come prior to the redefinition of setcolorspace, and
 %     must use an array operand.
 %
-[ /DeviceGray ] setcolorspace
+//DeviceGray_array setcolorspace
 
-
 %
 %   <c1> ... <cn>   setcolor   -
 %
@@ -461,22 +469,18 @@
 %
 /_setcolorspace
   {
-      {
-        % see if the operand space is the same as the current space
-        currentcolorspace dup length 1 eq
-          {
-            0 get
-            2 index dup type dup /arraytype eq exch /packedarraytype eq or
-              {
-                dup length 1 eq
-                  { 0 get }
-                if
-              }
-            if
+      { % See if the operand space is the same as the current space.
+        % The test is intentionaly conservative to meet CET 09-06.
+        1 index                       % [/new] bool [/new]
+        type /nametype eq
+          { currentcolorspace 0 get   % [/new] bool /old
+            2 index eq                % [/new] bool bool
           }
-          { 2 index }
+          { currentcolorspace         % [/new] bool [/old] 
+            2 index eq                % [/new] bool eq
+          }
         ifelse
-        eq and dup
+        and dup
           {
             %
             % If PDFfile is defined on the dictionary stack, this is a
@@ -532,7 +536,7 @@
 %
 %
 /initgraphics
-  { initgraphics { /DeviceGray } cvlit forcesetcolorspace }
+  { initgraphics //DeviceGray_array forcesetcolorspace }
 .bind systemdict begin odef end
 
 systemdict /setcolorspace .undef
@@ -551,7 +555,7 @@
 %
 /setgray
   {
-      { { /DeviceGray } cvlit  //setcolorspace //setcolor }
+      { //DeviceGray_array //setcolorspace //setcolor }
     stopped
       { /setgray .systemvar $error /errorname get signalerror }
     if
@@ -560,7 +564,7 @@
 
 /setrgbcolor
   {
-      { { /DeviceRGB } cvlit //setcolorspace //setcolor }
+      { //DeviceRGB_array //setcolorspace //setcolor }
     stopped
       { /setrgbcolor .systemvar $error /errorname get signalerror }
     if
@@ -572,7 +576,7 @@
     pop
     /setcmykcolor
       {
-          { { /DeviceCMYK } cvlit //setcolorspace //setcolor }
+          { //DeviceCMYK_array //setcolorspace //setcolor }
         stopped
           { /setcmykcolor .systemvar $error /errorname get signalerror }
         if
@@ -925,21 +929,21 @@
 
 /.hsb_2_rgb
   {
-    3 { 0.0 max 1.0 min 3 1 roll } repeat
-    1.0 2 index sub 1 index mul      % (1 - s) * br
-    3 -1 roll 2 index mul 6.0 mul    % 6 * s * br
-    4 -1 roll                      % stack: <br>  <(1 - s) * br>  <6 * s * br>  <h>
+    3 { 0.0 max 1.0 min 3 1 roll } repeat % h s b
+    1.0 2 index sub 1 index mul           % h s b (1-s)*b
+    3 -1 roll 2 index mul 6.0 mul         % h b (1-s)*b 6*s*b 
+    4 -1 roll                             % b (1-s)*b=nm 6*s*b=md h
 
     % array of procedures for the 7 hue cases
       {
-        % 0 ==> r >= g >= b
-        { mul 1 index add exch }
+        % 0 ==> r >= g >= b               % b nm md h
+        { mul 1 index add exch }          
 
         % 1 ==> g >= r >= b
         { //.f1_3 exch sub mul 1 index add 3 1 roll }
 
         % 2 ==> g >= b >= r
-        { //.f1_3 mul 1 index add 3 1 roll exch 3 -1 roll }
+        { //.f1_3 sub mul 1 index add 3 1 roll exch 3 -1 roll }
 
         % 3 ==> b >= g >= r
         { //.f2_3 exch sub mul 1 index add 3 -1 roll }
@@ -955,7 +959,7 @@
 	% the calculations.
         { pop pop dup }
       }
-    1 index 6.0 mul cvi              % (int)(6 * h)
+    1 index 6.0 mul cvi                   % b (1-s)*b 6*s*b h {} int(6*h)
     get exec    
   }
 bind def
@@ -984,5 +988,9 @@
   }
 bind systemdict begin odef end
 
+currentdict /DeviceGray_array .undef
+currentdict /DeviceRGB_array  .undef
+currentdict /DeviceCMYK_array .undef
+
 end     % .cspace_util
 .setglobal
Index: gs/lib/gs_indxd.ps
===================================================================
--- gs/lib/gs_indxd.ps	(revision 7149)
+++ gs/lib/gs_indxd.ps	(working copy)
@@ -176,7 +176,8 @@
       }
     bind
 
-    /cs_prepare_color //validate_1
+    % Atobe implementations accept floating point values
+    /cs_prepare_color { //validate_1 exec cvi } bind
 
     %
     % Adobe implementations always execute a lookup procedure when setcolor


More information about the gs-code-review mailing list