Jump to content
How to Install Plugins ×

Soften Portrait Effect Plugin (Updated 2007-05-27)


Recommended Posts

Soften Portrait Effect

 

I'm still learning how to create complex effect filters for Paint.NET. This is the first one that I wrote that combines preexisting effects. After I wrote this one, I did the Ink Sketch effect.

 

The Idea

 

The idea for this plugin came from belman92's post here.

 

I thought that it would be easy to automate the steps that are sometimes used to make portraits look softer and more professional. You can use this on other pictures, but it really is meant for portraits. It adds a little brown to smooth out skin but not too much detail is lost.

 

Here is an example pic of my lovely wife:

<snip demonstration photo>

 

The Effect DLL

 

NOTE: This effect is now included in Paint.NET. If you have upgraded to Paint.NET 3.10 or greater, you do not need to download this effect... you already have it!

 

Instructions for Use

 

The best way to use this is to follow these steps:

 

1. Open your graphic.

2. Click the Effects > Portrait menu.

3. Adjust the sliders for the desired effect.

 

PortraitUI.jpg

 

More Info

 

As always, more information can be found here: http://boltbait.googlepages.com/portrait

 

Source Code

 

To understand this code, first read the Ink Sketch thread. Go ahead, I'll wait.

Back? OK, here ya go:

/* PortraitEffect.cs
Copyright (c) 2007 David Issel
Contact Info: BoltBait@hotmail.com http://www.BoltBait.com

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions: 

The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software. 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
THE SOFTWARE. 
*/ 
using System;
using System.Collections;
using System.Drawing;
using PaintDotNet;
using PaintDotNet.Effects;

namespace PortraitEffect
{
   public class EffectPlugin
       : PaintDotNet.Effects.Effect
   {
       public static string StaticName
       {
           get
           {
               return "Soften Portrait";
           }
       }

       public static Bitmap StaticIcon
       {
           get
           {
               return new Bitmap(typeof(EffectPlugin), "EffectPluginIcon.png");
           }
       }
       private BlurEffect blurEffect = new BlurEffect(); 
       private UnaryPixelOps.Desaturate desaturateOp = new UnaryPixelOps.Desaturate(); 
       private SepiaEffect sepiaEffect = new SepiaEffect(); 
       private BrightnessAndContrastAdjustment bacAdjustment = new BrightnessAndContrastAdjustment();
       private UserBlendOps.OverlayBlendOp OverlayOp = new UserBlendOps.OverlayBlendOp();
       private UnaryPixelOp levels;

       public override unsafe void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) 
       { 
           ThreeAmountsConfigToken tacd = (ThreeAmountsConfigToken)parameters;
           float RedAdjust = 1.0f + ((float)tacd.Amount3 / 100.0f);
           float BlueAdjust = 1.0f - ((float)tacd.Amount3 / 100.0f);

           AmountEffectConfigToken blurToken = new AmountEffectConfigToken(tacd.Amount1 * 3); 
           BrightnessAndContrastAdjustmentConfigToken bacToken = new BrightnessAndContrastAdjustmentConfigToken(tacd.Amount2, -tacd.Amount2/2); 

           this.blurEffect.Render(blurToken, dstArgs, srcArgs, rois, startIndex, length); 
           this.bacAdjustment.Render(bacToken, dstArgs, dstArgs, rois, startIndex, length); 

           for (int i = startIndex; i < startIndex + length; ++i) 
           { 
               Rectangle roi = rois[i]; 

               for (int y = roi.Top; y < roi.Bottom; ++y) 
               { 
                   ColorBgra* srcPtr = srcArgs.Surface.GetPointAddress(roi.Left, y); 
                   ColorBgra* dstPtr = dstArgs.Surface.GetPointAddress(roi.Left, y); 

                   for (int x = roi.Left; x < roi.Right; ++x) 
                   {
                       ColorBgra srcGrey = this.desaturateOp.Apply(*srcPtr);
                       srcGrey.R = Utility.ClampToByte((int)((float)srcGrey.R * RedAdjust));
                       srcGrey.B = Utility.ClampToByte((int)((float)srcGrey.B * BlueAdjust));
                       ColorBgra mypixel = this.OverlayOp.Apply(srcGrey, *dstPtr); 
                       *dstPtr = mypixel; 

                       ++srcPtr; 
                       ++dstPtr; 
                   } 
               } 
           } 
       } 

       public override EffectConfigDialog CreateConfigDialog() 
       { 
           ThreeAmountsConfigDialog tacd = new ThreeAmountsConfigDialog(); 
           tacd.Text = StaticName; 

           tacd.Amount1Label = "Soften"; 
           tacd.Amount1Minimum = 0; 
           tacd.Amount1Maximum = 10; 
           tacd.Amount1Default = 5; 

           tacd.Amount2Label = "Lighting"; 
           tacd.Amount2Minimum = -20; 
           tacd.Amount2Maximum = 20; 
           tacd.Amount2Default = 0;

           tacd.Amount3Label = "Warmth";
           tacd.Amount3Minimum = 0;
           tacd.Amount3Maximum = 20;
           tacd.Amount3Default = 10;

           return tacd; 
       }

       public EffectPlugin() 
           : base(StaticName, StaticIcon, true) 
       { 

       } 

   }
}
 

Note: This is NOT a codelab script!

Link to comment
Share on other sites

When BoltBait jumped in my effects menu, he fixed it! Now I have arrows! BoltBait to the rescue.

cute_cat-portrait.jpg

NO, I don't have a cat. :P

v An excellent open–source strategy game—highly recommended.

 

"I wish I had never been born," she said. "What are we born for?"

"For infinite happiness," said the Spirit. "You can step out into it at any moment..."

Link to comment
Share on other sites

As you can see from Helio's example, not every picture is a good candidate for this plugin. :P

I'm still learning how to create complex effect...

I'm learning too, so I would much appreciate to see the source, for my self learning!

I don't know... every time I post my souce code, you take it, learn from it, and totally show me up by writing a better plugin than me!!! :cry:

Maybe I'll post the source after I write that Landscape plugin. ;)

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Updated the DLL.

I added a third slider. I also adjusted what the sliders do.

I was never happy with the "feel" of control you had over the results with the old version. Hopefully, you will feel more in control of the effect with this version.

See the links in the first post for the download.

Enjoy.

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Hey just wanted to say how much I love this plugin and it's integration into the core program.

Two of my favorite pictures as examples:

http://flickr.com/photos/undaunted/1364872177/

http://flickr.com/photos/undaunted/1265285401/

I actually like the effect more on non-portrait things like skyscrapers and shadowy areas, although it does do good work on portraits too as you can see in the first example.

I love Paint.net but I was curious how to make a similar effect in other programs (moving to Mac soon), I see the blur but where does the glow come from?

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