Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   FreePascal RGB/CMK/CMYK conversions (https://www.delphipraxis.net/165478-rgb-cmk-cmyk-conversions.html)

WojTec 2. Jan 2012 14:01

RGB/CMK/CMYK conversions
 
Delphi-Quellcode:
procedure _CMYToCMYK(const C, M, Y: Single; out Cyan, Magenta, Yellow, Black: Single);
var
  var_K: Single;
begin
  var_K := 1;

  if C < var_K then var_K := C;
  if M < var_K then var_K := M;
  if Y < var_K then var_K := Y;

  if var_K = 1 then
  begin //Black
     Cyan := 0;
     Magenta := 0;
     Yellow := 0;
  end
  else
  begin
     Cyan := (C - var_K) / (1 - var_K);
     Magenta := (M - var_K) / (1 - var_K);
     Yellow := (Y - var_K) / (1 - var_K);
  end;

  Black := var_K;
end;

procedure _CMYKToCMY(const C, M, Y, K: Single; out Cyan, Magenta, Yellow: Single);
begin
  Cyan := (C * (1 - K) + K);
  Magenta := (M * (1 - K) + K);
  Yellow := (Y * (1 - K) + K);
end;

procedure _RGBToCMY(const R, G, B: Byte; out C, M, Y: Single);
begin
  C := 1 - (R / 255);
  M := 1 - (G / 255);
  Y := 1 - (B / 255);
end;

procedure _CMYToRGB(const C, M, Y: Single; out R, G, B: Byte);
begin
  R := Round((1 - C) * 255);
  G := Round((1 - M) * 255);
  B := Round((1 - Y) * 255);
end;

procedure _RGBToCMYK(const R, G, B: Byte; out C, M, Y, K: Single);
var
  Cyan, Magenta, Yellow: Single;
begin
  _RGBToCMY(R, G, B, Cyan, Magenta, Yellow);
  _CMYToCMYK(Cyan, Magenta, Yellow, C, M, Y, K)
end;

procedure _CMYKToRGB(const C, M, Y, K: Single; out R, G, B: Byte);
var
  Cyan, Magenta, Yellow: Single;
begin
  _CMYKToCMY(C, M, Y, K, Cyan, Magenta, Yellow);
  _CMYToRGB(Cyan, Magenta, Yellow, R, G, B);
end;
Formulas I got from EasyRGB. Result are different in this code and Photoshop:

Code:
_CMYKToRGB(0.11, 0.13, 0.99, 0, R, G, B); // 227 222 3; ps: 232, 207, 30
_CMYKToRGB(0, 0, 0.5, 0.5, R, G, B); // 124 124 64; ps: 150 145 91
Where is bug? :sad:

himitsu 2. Jan 2012 14:16

AW: RGB/CMK/CMYK conversions
 
Zitat:

Zitat von WojTec (Beitrag 1143996)
Where is bug? :sad:

Total falsche Formeln?

Zitat:

Delphi-Quellcode:
procedure _RGBToCMY(const R, G, B: Byte; out C, M, Y: Single);
begin
  C := 1 - (R / 255);
  M := 1 - (G / 255);
  Y := 1 - (B / 255);
end;

procedure _CMYToRGB(const C, M, Y: Single; out R, G, B: Byte);
begin
  R := Round((1 - C) * 255);
  G := Round((1 - M) * 255);
  B := Round((1 - Y) * 255);
end;

Cyan <=> Red
Mngenta <=> Green
Yellow <=> Blue

Aber eigentlich ist es so:

Cyan <=> Blue und Green
Mangenta <=> Blue und Red
Yellow <=> Red und Green

WojTec 2. Jan 2012 14:39

Re: RGB/CMK/CMYK conversions
 
Hm, what is valid formula? I saw on the Internet only this one.

Sir Rufo 2. Jan 2012 17:44

AW: RGB/CMK/CMYK conversions
 
Except from the rounding mismatches in ur formula Online Color Conversion

did u switch off the Color Management in PS? ;)

WojTec 2. Jan 2012 18:29

Re: RGB/CMK/CMYK conversions
 
@Sir Rufo, what is wrong in this code, please tell me :(

I set color management policies to off, when was off the same as now.

Sir Rufo 2. Jan 2012 19:47

AW: RGB/CMK/CMYK conversions
 
try Extended instead of Single

WojTec 2. Jan 2012 20:19

Re: RGB/CMK/CMYK conversions
 
Could you please explain me why? Why is required extended precision?

jus 11. Jan 2012 15:31

AW: RGB/CMK/CMYK conversions
 
Hi WojTec,

have you already found a solution for this?

jus

DonAlfredo 16. Jan 2012 14:57

AW: RGB/CMK/CMYK conversions
 
This could help !

http://www.koders.com/delphi/fid212A...FBC.aspx?s=ftp

Keyword: RealColorLibrary

Greetings, Alfred.

jus 19. Jan 2012 12:54

AW: RGB/CMK/CMYK conversions
 
The formulas in the link from donalfredo seems to be very similiar to Wojtec. I did some research for myself. I get also very similiar results from photoshop as wojtec depending on which profiles i set. I think the differences come from the adobe colormanagement engine. So the photoshop does a full color space conversion between icc profiles and such approximation formulas like "C:=1-(R/255)..." don't work any more.

:)
jus


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:02 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz