Sign in to follow this  
BoltBait

RGB to CMYK (Plugin)

Recommended Posts

Well, according to Wiki,

    "conversions here are best described as "nominal". They will produce an invertible conversion between RGB and a subset of CMYK; that is, one can take an RGB color and convert to certain CMYK colors, and from these CMYK colors obtain the corresponding, original RGB equivalents. However, conversion of CMYK colors in general to RGB colors is not invertible; that is, given a CMYK color which is converted to RGB, performing the former conversion may not give the original CMYK color. In addition, CMYK colors may print wildly differently from how the RGB colors display on a monitor. There is no single "good" conversion rule between RGB and CMYK."
    "Use of four-color printing generates a good final printed result with greater contrast. However, the color seen on a computer screen is often different from the color of the same object on a printout since CMYK and RGB have different gamuts. For example, pure blue (rgb 0, 0, 100%) is impossible to produce in CMYK. The nearest equivalent in CMYK is a dissimilar shade of blue-violet."

But, since *you* might find this fun to play with... :D

The Effect DLL

Plugin: RGB2CMYK.dll (Updated 4/24/07)

Just "save" that DLL file in your C:/Program Files/Paint.net/Effects directory and you should be all set.

If you need help installing plugins, read this page: <!-- m -->http://boltbait.googlepages.com/install<!-- m -->

Instructions for Use

OK, taking this source picture (which I found on the Wiki page):

CMYK_Before.jpg

1. Open your image.

2. Duplicate it 3 times. You should now have 4 copies. Name them "C", "M", "Y", and "K" respectively.

3. Create a new layer and fill it with white.

4. Move the white layer to the bottom.

5. Select the "C" layer and run the effect. Move the slider to the first position (Cyan) and press OK.

6. Select the "M" layer and run the effect. Move the slider to the second position (Magenta) and press OK.

7. Select the "Y" layer and run the effect. Move the slider to the third position (Yellow) and press OK.

8. Select the "K" layer and run the effect. Move the slider to the last position (blacK) and press OK.

Here is the result:

CMYK_After.jpg

Here is the codelab script:

int Amount1=0;  //[0,3] Cyan   Magenta  Yellow    blacK
int Amount2=75; //[0,255] CMY Intensity

// http://en.wikipedia.org/wiki/CMYK_color_model 

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
    float R=0,G=0,B=0; 
    float C=0,M=0,Y=0,K=0; 
    byte A=0; 

    ColorBgra CurrentPixel; 
    
    for(int y = rect.Top; y < rect.Bottom; y++) 
    { 
        for (int x = rect.Left; x < rect.Right; x++) 
        { 
            if (selectionRegion.IsVisible(x, y)) 
            { 
                CurrentPixel = src[x,y]; 
                // Convert to RGB (float) 
                R = (float)CurrentPixel.R / 255; 
                G = (float)CurrentPixel.G / 255; 
                B = (float)CurrentPixel.B / 255; 
                // Convert to MYC 
                M = 1-G; 
                Y = 1-B; 
                C = 1-R; 
                // Convert to CMYK 
                if ((C==1) && (M==1) && (Y==1)) 
                { 
                    C=0;M=0;Y=0;K=1; 
                } 
                else 
                { 
                    K=C; 
                    if (K > M) K=M; 
                    if (K > Y) K=Y; 
                    C=(C-K)/(1-K); 
                    M=(M-K)/(1-K); 
                    Y=(Y-K)/(1-K); 
                } 
                switch(Amount1) 
                { 
                    case 0:   // Cyan 
                       A = (byte)(C*Amount2); 
                       R=0;G=255;B=255; 
                       break; 
                    case 1:   // Magenta 
                       A = (byte)(M*Amount2); 
                       R=255;G=0;B=255; 
                       break; 
                    case 2:   // Yellow 
                       A = (byte)(Y*Amount2); 
                       R=255;G=255;B=0; 
                       break; 
                    case 3:   // Black 
                       A = (byte)(K*255); 
                       R=0;G=0;B=0; 
                       break; 
                } 
                dst[x,y] = ColorBgra.FromBgra( 
                    Utility.ClampToByte(, 
                    Utility.ClampToByte(G), 
                    Utility.ClampToByte(R), 
                    Utility.ClampToByte(A)); 
            } 
        } 
    } 
} 

This is very rough, I know. Improvements welcome.

As always, more information here: <!-- m -->http://boltbait.googlepages.com/cmyk<!-- m -->

8)

Share this post


Link to post
Share on other sites

if ((C==1) && (M==1) && (Y==1)) 
{ 
   C=0;M=0;Y=0;K=1; 
} 

What about ...

if ((C==M) && (M==Y)) 
{ 
   C=0;M=0;Y=0;K=C; 
} 

Right now your K channel is a strict black-or-transparent bitmap. Not sure if this works though, I'm just hypothesizing.

Oh ... and v3.01?!

Share this post


Link to post
Share on other sites

Right now your K channel is a strict black-or-transparent bitmap.

erm... you sure about that?

@BoltBait: The effect washes out the colors, MOSTLY the blue. Maybe you could tweak it so the C channel is more intense, and it would probably go a long long way towards creating a more accurate conversion.

Then again, it might look like bloody potato. I don't know. But it's worth a try yeah?

EDIT:

PLaying around with the plugin (using the image you show in your example pics), i found that by duplicating the K layer, the image looked sooooo much better.

Share this post


Link to post
Share on other sites
@BoltBait: The effect washes out the colors, MOSTLY the blue. Maybe you could tweak it so the C channel is more intense, and it would probably go a long long way towards creating a more accurate conversion.

Then again, it might look like bloody potato. I don't know. But it's worth a try yeah?

EDIT:

PLaying around with the plugin (using the image you show in your example pics), i found that by duplicating the K layer, the image looked sooooo much better.

If you read the Wiki article http://en.wikipedia.org/wiki/CMYK_color_model you will see that a perfect conversion is not possible. In fact, you might want to read the discussion page of that article... it is quite entertaining. :D

I just wrote this effect because I wanted to play around with CMYK.

BTW, you see in the case statements where I'm multiplying by 75, it should be 255 (according to the algorithm) but I found that to be too strong. I scaled it back to 75 and it looked much better. Of course, this also washes out the colors somewhat. Hmmmm... Maybe I should make that settable. EDIT: Done. Script has 2 sliders now.

Oh, and Rick, I just followed the algorithm from the wiki article, I didn't optimize it for speed. I prefer readability during the prototype stage.

Share this post


Link to post
Share on other sites

I just updated the plugin to have 2 sliders now.

More tinkering = more fun, right?

:D

Share this post


Link to post
Share on other sites
I should check this forum more often. Let me know when I can add this to the (not released) Plugin Pack.

My original permission extends to all of my plugins (except for those noted in my permission statement).

Share this post


Link to post
Share on other sites

Hey guys! CMYK is subtractive color synthetisis. It can only work with layer blend mode multiply and no usage of alpha.

Yes, this is a very essential information! The plugin author should adment his 8-point "Instructions to use" and add that all the C,M,Y layers must have their layer blend mode set to Multiply (choose a layer and press F4; for the K layer it doesn't matter; This is because the C,M,Y colors are inks, while the black K is a pigment). Then the image composed of all the four layers looks identical to the original image, not so "washed out" as the presented sample result.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this