Jump to content
How to Install Plugins ×

TR's Fish Eye Plugin - Feb. 24, 2015


TechnoRobbo

Recommended Posts

Technorobbo's Fish Eye 2.2

 

v2.2 adds color cast to highlight and specular control

v2.1 fixes a bug in the highlight

V2.0 adds shadow, rotation and specular highlight

 

 

It's not a Bulge Filter. 

 

It takes your image, creates a Pixel Cloud then maps it via the Pythagorean theorem. Then renders it using a standard 3D Mapping algorithm.

 

Here is a Youtube tutorial http://youtu.be/DOOwh8ul3gc

V2 Demo http://youtu.be/oqaHRlxdARs

 

Fisheye.png?raw=1

 

Here's the code:

Hidden Content:
// Submenu: Distort
// Name: TR's Fish Eye
// Title: Fish Eye - v2.2
// Author: TechnoRobbo
// URL: http://www.technorobbo.com

#region UICode
double Amount1 = 0.25; // [0.01,1] Control
Pair<double, double> Amount2 = Pair.Create( 0.0 , 0.0 ); // Rotate
Pair<double, double> Amount3 = Pair.Create( 0.0 , 0.0 ); // Light Source
double Amount4 = 0; // [0,2] Spot Light
double Amount5 = 2; // [0,5] Light Intensity
double Amount6 = 0; // [0,1.5] Highlight
double Amount7 = 1; // [0.01,10] Specularity
ColorBgra Amount8 = ColorBgra.FromBgr(0,0,0); // Color Cast
#endregion

private ColorBgra getblend(int x, ColorBgra a, ColorBgra 
{
    UserBlendOp bop = new UserBlendOps.NormalBlendOp();
    switch (x)
    {
        case 0:
            bop = new UserBlendOps.NormalBlendOp(); // Normal
            break;

        case 1:
            bop = new UserBlendOps.MultiplyBlendOp(); // Multiply
            break;

        case 2:
            bop = new UserBlendOps.AdditiveBlendOp(); // Additive
            break;
        case 3:
            bop = new UserBlendOps.ColorBurnBlendOp(); // Color Burn
            break;
        case 4:
            bop = new UserBlendOps.ColorDodgeBlendOp(); // Color Dodge
            break;
        case 5:
            bop = new UserBlendOps.ReflectBlendOp(); // Reflect
            break;
        case 6:
            bop = new UserBlendOps.GlowBlendOp(); // Glow
            break;
        case 7:
            bop = new UserBlendOps.OverlayBlendOp(); // Overlay
            break;
        case 8:
            bop = new UserBlendOps.DifferenceBlendOp(); // Difference
            break;
        case 9:
            bop = new UserBlendOps.NegationBlendOp(); // Negation
            break;
        case 10:
            bop = new UserBlendOps.LightenBlendOp(); // Lighten
            break;
        case 11:
            bop = new UserBlendOps.DarkenBlendOp(); // Darken
            break;
        case 12:
            bop = new UserBlendOps.ScreenBlendOp(); // Screen
            break;
        case 13:
            bop = new UserBlendOps.XorBlendOp(); // Xor
            break;
        default:
            bop = new UserBlendOps.NormalBlendOp();
            break;
    }
    return bop.Apply(a, ;
}


void Render(Surface dst, Surface src, Rectangle rect)
{
  
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    double CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    double CenterY= ((selection.Bottom - selection.Top) / 2)+selection.Top;
    double offx =0;
    double offy =0;
    double rady = (selection.Bottom - selection.Top) / 2;
    double radx = (selection.Right - selection.Left) / 2;
    double rotateX=Amount2.First * CenterX;
    double rotateY=Amount2.Second * CenterY;
    double sourceX=Amount3.First * CenterX + CenterX;
    double sourceY=Amount3.Second * CenterY + CenterY;
    double gamma = Amount5 * 255;
    double wide=Amount4;
    double hilite = Math.Pow(Amount6,Amount7);
    double tmpy =0;
    double tmpx =0;
    double z=0;
    double tmp=0;
    double zp= Math.Pow((double) Amount1,2) * radx * 8;
    ColorBgra cast = Amount8;//getblend(12,ColorBgra.White,Amount8);
        

    ColorBgra CP;

    
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        tmpy=y-CenterY;
        tmpx=Math.Sqrt(rady*rady-tmpy*tmpy);
        for (int x = rect.Left; x < rect.Right; x++)
        {
            if (IsCancelRequested) return;
            double spread =  Math.Sqrt(Math.Pow(x - CenterX,2) + Math.Pow(y - CenterY,2));
            
            double Light =  Math.Sqrt(Math.Pow(x - sourceX,2) + Math.Pow(y - sourceY,2)) * wide ;
            Light=(Light>CenterY)?1:Light/CenterY;
            
            double hLight =  Math.Sqrt(Math.Pow(x - sourceX,2) + Math.Pow(y - sourceY,2));
            hLight =(hLight >CenterY)?1:hLight /CenterY;  
            
            tmp=(double)x-CenterX;            
            z = zp + Math.Sqrt(tmpx*tmpx-tmp*tmp);
            offx = tmp *  zp / z + CenterX + rotateX;
        
            tmp=(double)y-CenterY;
            
            offy= tmp *  zp / z + CenterY + rotateY;
            
            CP= src.GetBilinearSampleWrapped((float)offx,(float)offy);


            double l,lr,lg,lb;
            
            lr =(1 - Math.Pow(hLight , hilite)) * cast.R;
            lr=(lr>255)?255:(lr<0)?0:lr;
            lg =(1 - Math.Pow(hLight , hilite)) * cast.G;
            lg=(lg>255)?255:(lg<0)?0:lg;
            lb =(1 - Math.Pow(hLight , hilite)) * cast.B;
            lr=(lb>255)?255:(lb<0)?0:lb;
            ColorBgra CH = ColorBgra.FromBgr((byte)lb,(byte)lg,(byte)lr);
            CP=getblend(12,CP,CH);//was 12
            
            l= (1 - Math.Sqrt(Light)) * gamma;
            l=(l>255)?255:(l<0)?0:l;
            ColorBgra CL = ColorBgra.FromBgr((byte)l,(byte)l,(byte)l);
            CP=getblend(1,CP,CL);
            

            
            if (spread>(CenterY-1))CP.A=32;
            if (spread>(CenterY-2))CP.A=128;
            if (spread>CenterY)CP.A=0;
            
            dst[x,y]=CP;  
        }
    }
}
 

Fisheye.zip

Edited by TechnoRobbo
  • Like 2
  • Upvote 5

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

Nice!  It's quick too.  Great job.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

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...