Sign in to follow this  
ReMake

Color Range effect

Recommended Posts

This plugin can be useful for selecting objects in the image or for creation a color mask of object. The plugin is based on the script of Color Target plugin by rwp80.

 

You can find it: Effects -> Color -> Color Range

 

Compatible with both: v3.5.X and v4.0.X

 

ColorRange_en.zip

ColorRange_ru.zip

 

This effect allows you to create a color mask of object in the image. You can then select the object using Magic Wand ( :MagicWandTool:) for further work with him.

 

colorrangeenui.png

 

See short tutorial and examples of effect's work in the Color Range Test topic.

 

CodeLab script:

Hidden Content:
// Name: Color Range
// Submenu: Color
// Author: ReMake
// Title: Color Range v1.0    ReMake 2016
// Version: 1.0
// Desc:
// Keywords: paint.net|effect|color|range|color range
// URL: http://www.getpaint.net/redirect/plugins.html
#region UICode
byte Amount1 = 0; // Color|Custom|Red|Yellow|Green|Cyan|Blue|Magenta|White|Grey|Black
ColorBgra Amount2 = ColorBgra.FromBgr(0, 0, 0); //
int Amount3 = 225; // [0,255] Color Threshold
int Amount4 = 255; // [0,255] Brightness Tolerance
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra CurrentPixel;
    int R, G, B, A, CR, CG, CB, GtR, GtB, CGtR, CGtB;
    int ColThr = Amount3;
    int BriTol = Amount4;

    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x, y];
            CR = CG = CB = 0;
            B = CurrentPixel.B;
            G = CurrentPixel.G;
            R = CurrentPixel.R;
            A = CurrentPixel.A;
            switch (Amount1)
            {
                case 0: // Custom
                    CB = Amount2.B;
                    CG = Amount2.G;
                    CR = Amount2.R;
                    break;
                case 1: // Red
                    CR = 255;
                    break;
                case 2: // Yellow
                    CR = CG = 255;
                    break;
                case 3: // Green
                    CG = 128;
                    break;
                case 4: // Cyan
                    CG = CB = 255;
                    break;
                case 5: // Blue
                    CB = 255;
                    break;             
                case 6: // Magenta
                    CR = CB = 255;
                    break;
                case 7: // White
                    CR = CG = CB = 255;
                    break;
                case 8: // Grey
                    CR = CG = CB = 128;
                    break;
                case 9: // Black
                    CR = CG = CB = 0;
                    break;
            }

            GtR = R - G;
            GtB = B - G;
            CGtR = CR - CG;
            CGtB = CB - CG;

            if ((GtR <= CGtR - ColThr) || (GtR >= CGtR + ColThr) || (GtB <= CGtB - ColThr) || (GtB >= CGtB + ColThr) || (B <= CB - BriTol) || (B >= CB + BriTol) || (G <= CG - BriTol) || (G >= CG + BriTol) || (R <= CR - BriTol) || (R >= CR + BriTol))
            {
                A = 0;
            }

            CurrentPixel = ColorBgra.FromBgra(
              Int32Util.ClampToByte((int)CB),
              Int32Util.ClampToByte((int)CG),
              Int32Util.ClampToByte((int)CR),
              Int32Util.ClampToByte((int)A));

            dst[x, y] = CurrentPixel;
        }
    }
}

 

and icon: cricon.png

 

Examples of effect's technique you can found in How To Use Color Range effect topic.

 

Примеры работы эффекта и приемы работы с ним вы можете посмотреть в уроке Как использовать эффект 'Цветовой диапазон'.

  • Upvote 9

Share this post


Link to post
Share on other sites

I looked at the source code, and I am wondering: why are you using the double type for the color channels? Surely the int type would be sufficient, as there aren't any operations in the script that would produce numbers with decimal places.

  • Upvote 1

Share this post


Link to post
Share on other sites

... but it even though I used the color picker, the color doesn't appear in the plug-in, it defaults to white.

 

Hmm, I'm experiencing the same situation described above by AgentGoodSpeed.

 

Fixed. Primary color now color by default.

 

I looked at the source code, and I am wondering: why are you using the double type for the color channels? Surely the int type would be sufficient, as there aren't any operations in the script that would produce numbers with decimal places.

 

I'll work on it today. Thanks for the tip.

  • Upvote 2

Share this post


Link to post
Share on other sites

An unfortunate spelling error. My apologies to anyone who downloaded the English version of the effect. Re-download the fixed version, please. Thank to all for your comments, remarks and tips.

  • Upvote 2

Share this post


Link to post
Share on other sites

ReMake, this plugin is WONDERFUL!  It's easy to use and with very little tweaking, it achieves a near flawless recoloring. It just looks so smooth.....no splotches!

 

colorrange_01.png

 

 

Thank you, ReMake!     :mrviolet:     :star:  :star:  :star:       :beer:  :pizza:  :mtdew:  :cake:

Edited by lynxster4
re-hosted image
  • Upvote 2

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