Jump to content

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):

http://boltbait.googlepages.com/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:

http://boltbait.googlepages.com/CMYK_After.jpg

Here is the codelab script:

#region UICode
IntSliderControl Amount1 = 0; // [0,3] Cyan          Magenta        Yellow         blacK
IntSliderControl Amount2 = 75; // [0,255] CMY Intensity
#endregion

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

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
    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++) 
        { 
                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( 
                    Int32Util.ClampToByte((int)B), 
                    Int32Util.ClampToByte((int)G), 
                    Int32Util.ClampToByte((int)R), 
                    Int32Util.ClampToByte(A)); 
        } 
    } 
} 
 

This is very rough, I know. Improvements welcome.

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

😎

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
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?!

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
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.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
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.

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

  • 4 months later...
  • 4 years later...

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.

Link to comment
Share on other sites

  • 9 years later...
1 hour ago, AndrewDavid said:

Could you please update the Codelab code for Net 6.0. I'm pulling my hair out trying to get the last four lines to work. :)

 

Did you read the error message?  It literally tells you how to fix the problem.

 

BTW, I updated the code above.

  • Thanks 1

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...