Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Anyone know how? I imagined there would be some mod, but i can't seem to find it.

Replies are listed 'Best First'.
(z) Re: Converting CMYK values to RGB values
by zigdon (Deacon) on Dec 26, 2002 at 20:42 UTC
    No module, but it seems easy enough - a simple Google search came up with this.

    -- Dan

Re: Converting CMYK values to RGB values
by dws (Chancellor) on Dec 26, 2002 at 21:47 UTC
    Anyone know how [to convert CMYK values to RGB]?

    This, and many other questions about color, are answered (though sometimes not directly) in Poynton's Color FAQ. Look for "24. Is CMY just one-minus-RGB?".

Re: Converting CMYK values to RGB values
by poj (Abbot) on Dec 26, 2002 at 23:13 UTC
    Using the formulae from the page zigdon suggested ;
    # see http://adaptiveview.com/cw/doc5a.html # red = 255 - minimum(255,((cyan/255) * (255 - black) + black)) # green = 255 - minimum(255,((magenta/255) * (255 - black) + black)) # blue = 255 - minimum(255,((yellow/255) * (255 - black) + black)) use strict; use warnings; # some test data my @cmyk = qw(0 128 255 127 ); # convert my @rgb = cmyk2rgb(@cmyk); # result foreach (0..2){ print "$_ $rgb[$_]\n"; } sub cmyk2rgb { my (@cmyk) = @_; my $bk = $cmyk[3]; my $wh = 255 - $bk; my @rgb=(); my $tmp=0; for (0..2){ $tmp = ( ($cmyk[$_]/255) * $wh ) + $bk; $tmp = ($tmp > 255) ? 255 : $tmp; $rgb[$_] = 255 - int ($tmp + 0.5); } return @rgb; }

    poj

      Using map allows for code that is (IMHO) somewhat clearer and more concise.

      sub cmyk2rgb { my ($cyan, $magenta, $yellow, $black) = @_; my $white = 255 - $black; use integer; return map $_ > 255 ? 0 : 255 - $_ => map $_ * $white / 255 + $black => ($cyan, $magenta, $yellow); }

      — Arien

Re: Converting CMYK values to RGB values
by BrowserUk (Patriarch) on Dec 27, 2002 at 00:31 UTC

    This may be of some use to you.


    Examine what is said, not who speaks.