Jump to content
How to Install Plugins ×

Rainbowify


Reptillian

Recommended Posts

This plugin converts the average of RGB channel into Hue Range, and then add a gradient, and finally wrap it around to [0-1) range. This results in a image that has rainbow following the contour of the original image. Inspired by Rainbowify effect made by Jonathan Frech.

 

There are three parameters: Hue Shift, Angle, and Gradient Scale. Self-Explanatory.

 

Output of Effect:

 

zu6y8lzu5dd71.png?width=640&auto=webp&s=

 

Installation:

Plugin Files -> Rainbowify.zip

1. Insert the .dll into effect folder of paint.net installation

2. Find it under Artistic. I want it under Stylize though, but this can do.

 

Source code:

 

PDN C#

Spoiler
// Name: Rainbowify
// Submenu: Artistic
// Author: Reptorian
// Title: Rainbowify
// Version:
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
IntSliderControl Amount1 = 0; // [-180,180] Hue Shift
AngleControl grad_ang = 45; // [-180,180] Gradient Angle
DoubleSliderControl grad_scale = 100; // [50,200] Gradient Scale (%)
#endregion

double rot_y(double a,double b,double cos_ang,double sin_ang){
    return a*sin_ang-b*cos_ang;
}

double fmod(double a){
    return a - 360 * Math.Floor(a/360);
}

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need

    int hue_shift = Amount1 + 180;
    double ang = -(grad_ang/180)*Math.PI;
    double cos_ang = Math.Cos(ang);
    double sin_ang = Math.Sin(ang);
    int i_w=src.Width - 1;
    int i_h=src.Height - 1;
    double d_w= (double)(i_w)-1;
    double d_h= (double)(i_h)-1;
    double cx = d_w/2;
    double cy = d_h/2;
    double sd = Math.Max(d_w,d_h)/Math.Min(d_w,d_h);
    double sx = i_w>i_h ? sd : 1;
    double sy = i_w>i_h ? 1 : sd;
    double cxsx=cx/sx;
    double cysy=cy/sy;
    double rescale_pos=180*grad_scale/100;
    double m = 360 / 255;

    double px,py,pos,v,hue_out;

    HsvColor hsv;

    ColorBgra currentPixel;
    ColorBgra output;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            px = ((double)(x)-cx)/cxsx;
            py = ((double)(y)-cy)/cysy;
            pos = rot_y(px,py,cos_ang,sin_ang)*rescale_pos;
            currentPixel = src[x,y];
            v = (double)(currentPixel.B+currentPixel.G+currentPixel.R)/3;
            v *= m;
            hue_out = fmod(v+pos+(double)(hue_shift));
            hsv = new HsvColor((int)(hue_out),100,100);
            output = ColorBgra.FromColor(hsv.ToColor());
            output.A=currentPixel.A;
            dst[x,y]=output;
        }
    }
}

 

G'MIC

Spoiler
#@cli rep_rainbowify: -360<_hue_shift<360,-360<_gradient_angle<360,_gradient_scale[%]>0
#@cli : Apply rainbowify effect into image. Inspired by Rainbowify effect made by Jonathan Frech.
#@cli : Default values: '_hue_shift=0','_gradient_angle=0','_gradient_angle=100%'
rep_rainbowify:
skip ${1=0},${2=0},${3=100%}
repeat $! l[$>]
 if s<3 continue fi
 if s==4 sh. 0,2 fi
 f. "begin(
  const shift_hue=$1+180;
  const ang=($2/180)*pi;
  const cos_ang=cos(ang);
  const sin_ang=sin(ang);
  rot_x(a,b)=a*cos_ang-b*sin_ang;
  rot_y(a,b)=a*sin_ang+b*cos_ang;
  const sd=max(w,h)/min(w,h);
  const sx=w>h?sd:1;
  const sy=w>h?1:sd;
  const ww=w-1;
  const hh=h-1;
  const cx=ww/2;
  const cy=hh/2;
  const cxsx=cx/sx;
  const cysy=cy/sy;
  const m=360/255;
  const rescale_pos=180*$3;
  fmod(a)=a-360*floor(a/360);
 );
 px=(x-cx)/cxsx;
 py=(y-cy)/cysy;
 pos=rot_y(px,py)*rescale_pos;
 v=avg(I)*m;
 [fmod(v+pos+shift_hue),1,.5];
 "
 k[0]
 hsl2rgb
endl done
#@gui Rainbowify: fx_rep_rainbowify,fx_rep_rainbowify_preview(0)
#@gui :_=note("Apply rainbowify effect into image. Inspired by Rainbowify effect made by Jonathan Frech."),_=separator()
#@gui :Hue Shift=float(0,-180,180)
#@gui :Gradient Angle=float(0,-180,180)
#@gui :Gradient Scale(%)=float(100,50,200)
#@gui :_=separator(), Preview Type=choice("Full","Forward Horizontal","Forward Vertical","Backward Horizontal","Backward Vertical","Duplicate Top","Duplicate Left","Duplicate Bottom","Duplicate Right","Duplicate Horizontal","Duplicate Vertical","Checkered","Checkered Inverse"), Preview Split = point(50,50,0,0,200,200,200,0,10)_0
#@gui :_=separator(), _=note("<small>Author: Reptorian. Latest Update: <i>2021/7/25</i>.</small>")
fx_rep_rainbowify: rep_rainbowify ${1-2},$3%
fx_rep_rainbowify_preview:
gui_split_preview "fx_rep_rainbowify ${1-3}",${-3--1}

 

 

Edited by Reptillian
  • Like 2
  • Upvote 2

G'MIC Filter Developer

Link to comment
Share on other sites

Link to comment
Share on other sites

Very nice... however, malware detected by when downloaded in FireFox. I downloaded source, compiled in CodeLab and all is fine 👍

 

So, I did download, scanned it using Defender and was just fine.... however files sizes differ between the downloaded compiled version and the compiled version I did in CodeLab???

 

Very best regards

 

Edited by Panchdara
Link to comment
Share on other sites

6 hours ago, Panchdara said:

however files sizes differ between the downloaded compiled version and the compiled version I did in CodeLab???

 

Probably in CodeLab you compiled an effect without an icon and therefore got a difference of half a kilobyte.

Link to comment
Share on other sites

Here's something you can do with Rainbowify:

 

1SRRIKg.png

 

1. Load or create a image to use as base for Rainbowify.

2. Duplicate the image twice.

3. Desaturate the top two image.

4. Rainbowify the first layer.

5. Set the middle layer into Multiply Mode.

6. Set the top layer into Glow Mode.

 

You'd get something interesting here.

Edited by Reptillian
  • Like 2

G'MIC Filter Developer

Link to comment
Share on other sites

23 hours ago, Panchdara said:

Very nice... however, malware detected by when downloaded in FireFox. I downloaded source, compiled in CodeLab and all is fine 👍

 

So, I did download, scanned it using Defender and was just fine.... however files sizes differ between the downloaded compiled version and the compiled version I did in CodeLab???

 

Very best regards

 

EDIT: Well,I just downloaded again, 12 hours later, and it liked it. I reckon, I did not restart FireFox yesterday and FF had a little "usage fatigue". I just restarted it and it's fine. I did NOT restart or reboot the PC, I just restarted FF application. (Using FF 99.0b7)

 

Thanks again Reptillian. I like this plugin. 👍

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.

×
×
  • Create New...