Sign in to follow this  
Followers 0
BoltBait

Landscape Plugin - With source code (Nov 2, 2009)

16 posts in this topic

Tomorrow is my birthday, but today you get the present!

Remember when I wrote the Portrait plugin, MadJik wrote:

Another good plugin :plugin: ! I like it ! Thanks...

=>joke : ETA for Landscape plugin ?

Well, ETA is TODAY! :D

LandScapeUI2.jpg

LandScapeUI1.jpg

It automates a bunch of steps that I make when fixing landscape pictures. It is obviously not right for everything, but I find it useful. Hopefully you will too.

Download the Landscape.dll as part of my plugin pack here: http://forums.getpaint.net/index.php?/topic/8318-

If you have trouble installing this plugin, post your troubles here.

Enjoy. B)

For those that are interested in such things, here is the CodeLab source:

// Author: BoltBait
// Submenu: Photo
// Name: Sharpen Landscape
// URL: http://www.BoltBait.com/pdn
#region UICode
Pair<double, double> Amount1 = Pair.Create( 0.0 , -0.25 ); // Position of Horizon
int Amount2 = 50; // [0,100] Sky
int Amount3 = 50; // [0,100] Grass
int Amount4 = 100; // [0,200] Sharpen
int Amount5 = 50; // [0,100] Saturation
int Amount6 = 50; // [0,100] Final Multiply Adjustment
#endregion

// Setup for using the various blend ops
private UserBlendOps.OverlayBlendOp overlayOp = new UserBlendOps.OverlayBlendOp();
private UserBlendOps.ColorDodgeBlendOp dodgeOp = new UserBlendOps.ColorDodgeBlendOp();
private UserBlendOps.MultiplyBlendOp multiplyOp = new UserBlendOps.MultiplyBlendOp();
private UnaryPixelOps.HueSaturationLightness saturationOp;

unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    ColorBgra Sky = ColorBgra.FromBgr(255,128,0);
    ColorBgra Grass = ColorBgra.FromBgr(0,128,0);
    int HorizonRow = (int)Math.Round(((Amount1.Second + 1) / 2) * (selection.Bottom - selection.Top));
    saturationOp = new UnaryPixelOps.HueSaturationLightness(0, 100+Amount5*3, 0);

    // Setup for calling the Blur function
    GaussianBlurEffect blurEffect = new GaussianBlurEffect();
    PropertyCollection bProps = blurEffect.CreatePropertyCollection();
    PropertyBasedEffectConfigToken bParameters = new PropertyBasedEffectConfigToken(bProps);
    bParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, 1);
    blurEffect.SetRenderInfo(bParameters, new RenderArgs(dst), new RenderArgs(src));
    // Call the Blur function
    blurEffect.Render(new Rectangle[1] {rect},0,1);

    // Now in the main render loop, the dst canvas has a blurred version of the src canvas
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y);
        ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
        for (int x = rect.Left; x < rect.Right; x++)
        {
            // Create a blue gradient at the top
            if (y < HorizonRow) {
                Sky.A = (byte)(int)((255.0 - (255.0 * y / HorizonRow ))*(Amount2/100.0));
            } else {
                Sky.A = (byte)0;
            }

            // Create a green gradient at the bottom
            if (y > HorizonRow) {
                Grass.A = (byte)(int)((255.0 * (y-HorizonRow) / (selection.Bottom-HorizonRow))*(Amount3/100.0));
            } else {
                Grass.A = (byte)0;
            }

            ColorBgra AdjustmentPixel = *dstPtr;
            ColorBgra SourcePixel = *srcPtr;

            // Sharpen (unsharp mask)
            double NewR = (double)SourcePixel.R + ((double)SourcePixel.R - (double)AdjustmentPixel.R) * (double)Amount4 / 100.0;
            double NewG = (double)SourcePixel.G + ((double)SourcePixel.G - (double)AdjustmentPixel.G) * (double)Amount4 / 100.0;
            double NewB = (double)SourcePixel.B + ((double)SourcePixel.B - (double)AdjustmentPixel.B) * (double)Amount4 / 100.0;
            AdjustmentPixel.R = Utility.ClampToByte(NewR);
            AdjustmentPixel.G = Utility.ClampToByte(NewG);
            AdjustmentPixel.B = Utility.ClampToByte(NewB);

            // Boost the saturation
            *dstPtr = saturationOp.Apply(AdjustmentPixel);

            // Add in the sky and grass
            *dstPtr = multiplyOp.Apply(*dstPtr, Sky);
            *dstPtr = dodgeOp.Apply(*dstPtr, Grass);

            // Finally, add a little "punch" to the overall picture
            AdjustmentPixel = *dstPtr;
            AdjustmentPixel.A = (byte)(int)(Amount6 * 255.0 / 100.0);
            *dstPtr = multiplyOp.Apply(*dstPtr, AdjustmentPixel);

            srcPtr++;
            dstPtr++;
        }
    }
} 
Thanks to Tanel for the Sharpen (unsharp mask) code.
0

Share this post


Link to post
Share on other sites

Very interesting!

Suggestions:

Add horizon angle.

Add horizon tube distortion, like MadJiks...

Add horizon line overlay option. To line up horizon settings with image while previewing.

0

Share this post


Link to post
Share on other sites

*sigh* no one's ever satisfied. Why do I even bother? :(

"Here I am, brain the size of a planet, and they ask me to take you to the bridge. Call that job satisfaction, 'cause I don't." ~Marvin

0

Share this post


Link to post
Share on other sites

Yeah, I guess that was a little soon for feature requests...

Sorry Boltbait! :(

I do think it is very cool as is!

0

Share this post


Link to post
Share on other sites

:shock:

This will be one sweet plugin for some of my photographs! downloads

Ideas are swimming in my heads.

Cheers, BB!

Edit: Have one on me, mate. Beer.gif

0

Share this post


Link to post
Share on other sites

Happy birthday, Santa Claus (you give gifts on your birthday).

0

Share this post


Link to post
Share on other sites

Thanks for the new plugin BoltBait! - and happy birthday :)

0

Share this post


Link to post
Share on other sites

I really like this plugin.

BoltBait is there any way to have a tilt option for the horizon line? sometimes the horizon just isn't smack dab across the screen in straight line.

the work around I've been using is larger canvas and rotating the image then applying plugin then re righting the picture. not absolutlely ideal. but only way I can think to do this. is there another method I'm not thinking of?

ciao OMA

0

Share this post


Link to post
Share on other sites

Thanks. I'll think about it and see what I can do.

0

Share this post


Link to post
Share on other sites

no rush its not a major need ,just thought it would be a nice option. I've a few things perking away in the back of my noodle that I might experiment with if there was a tilt or rotational feature.

ciao OMa

0

Share this post


Link to post
Share on other sites

Sorry BoltBait, I know this plugin is older, but the link is broken to download this plugin. Could you update this one please. Thanks, and it would be much appreciated!

0

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  
Followers 0