Conv-Color RGB-16 to CMYK

From Vectorlab
Jump to: navigation, search


Converts RGB to CMYK returning a sequence separated by colon ";". This is an adaptation from Eric Gorr, BetaList 24.07.08. ( Orso ).


{ *********************************************** }
{ adapted from Eric Gorr, BetaList 24.07.08 }
{ Converts RGB to CMYK, rgb values must be 16-bit (range 0-65535) }
FUNCTION C_RGBtoCMYK(r, g, b: LONGINT; VAR c, m, y, k: REAL; prec : INTEGER): STRING;
	VAR
		maxRGB, minRGB : REAL;
		temp_l : LONGINT;
		
	BEGIN
		c := 1 - r;
		m := 1 - g;
		y := 1 - b;
		
		k := Min(c, m);
		k := Min(k, y);
		
		c := (c - k)/65535;
		m := (m - k)/65535;
		y := (y - k)/65535;
		
		IF k = -65534 THEN
			k := 0
		ELSE
			k := 1 + k/65535;
		
		C_RGBtoCMYK := Concat(Num2Str(prec, c), '; ', Num2Str(prec, m), '; ', Num2Str(prec, y), '; ', Num2Str(prec, k));
	END;