@@ -127,4 +127,43 @@ function hslToRgb(hue, sat, light) {
127
127
else if ( hue < 3 ) return t2 ;
128
128
else if ( hue < 4 ) return ( t2 - t1 ) * ( 4 - hue ) + t1 ;
129
129
else return t1 ;
130
- }
130
+ }
131
+
132
+ // These are the naive algorithms from CS Color 4
133
+
134
+ function naive_CMYK_to_sRGB ( CMYK ) {
135
+ // CMYK is an array of four values
136
+ // in the range [0.0, 1.0]
137
+ // the optput is an array of [RGB]
138
+ // also in the [0.0, 1.0] range
139
+ // because the naive algorithm does not generate out of gamut colors
140
+ // neither does it generate accurate simulations of practical CMYK colors
141
+
142
+ var cyan = CMYK [ 0 ] , magenta = CMYK [ 1 ] , yellow = CMYK [ 2 ] , black = CMYK [ 3 ] ;
143
+
144
+ var red = 1 - Math . min ( 1 , cyan * ( 1 - black ) + black ) ;
145
+ var green = 1 - Math . min ( 1 , magenta * ( 1 - black ) + black ) ;
146
+ var blue = 1 - Math . min ( 1 , yellow * ( 1 - black ) + black ) ;
147
+
148
+ return [ red , green , blue ] ;
149
+
150
+ }
151
+
152
+ function naive_sRGB_to_CMYK ( RGB ) {
153
+ // RGB is an arravy of three values
154
+ // in the range [0.0, 1.0]
155
+ // the output is an array of [CMYK]
156
+ // also in the [0.0, 1.0] range
157
+ // with maximum GCR and (I think) 200% TAC
158
+ // the naive algorithm does not generate out of gamut colors
159
+ // neither does it generate accurate simulations of practical CMYK colors
160
+
161
+ var red = RGB [ 0 ] , green = RGB [ 1 ] , blue = RGB [ 2 ] ;
162
+
163
+ var black = 1 - Math . max ( red , green , blue ) ;
164
+ var cyan = ( black = 1.0 ) ? 0 : ( 1 - red - black ) / ( 1 - black ) ;
165
+ var magenta = ( black = 1.0 ) ? 0 : ( 1 - green - black ) / ( 1 - black ) ;
166
+ var yellow = ( black = 1.0 ) ? 0 : ( 1 - blue - black ) / ( 1 - black ) ;
167
+
168
+ return [ cyan , magenta , yellow , black ] ;
169
+ }
0 commit comments