Sign in to follow this  
Followers 0
BoltBait

Portrait Effect Plugin (Updated 2007-05-27)

22 posts in this topic

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 "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!

0

Share this post


Link to post
Share on other sites

I really love this plugin.

It has a dimming and glowing effect all at the same time: an example

Ah! I got BoltBaits in my history window! :lol:

0

Share this post


Link to post
Share on other sites

BuzzKill!!!!

I'm in ur Paint Dot Net... eatin' ur cookie. :D

0

Share this post


Link to post
Share on other sites

Thanks. Those two plugin looks really interesting.

I just bought a scanner, so they might come in very handy.

0

Share this post


Link to post
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

0

Share this post


Link to post
Share on other sites

Thanks for a wonderful portrait plugin!

Simplifies process of making older men and women look better!!

0

Share this post


Link to post
Share on other sites

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

=>joke : ETA for Landscape plugin ?

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!

0

Share this post


Link to post
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. ;)

0

Share this post


Link to post
Share on other sites

Looks pretty nice. I have a picture that this can be done to, but its on my crashed hard drive.

0

Share this post


Link to post
Share on other sites

Great plugin. Works great for other stuff too.

Before:

Sunset05.png

After:

Sunset05p.png

Thanks BoltBait. :)

0

Share this post


Link to post
Share on other sites

Cool pluginn! and i'm waiting for Madjik's versian ;)

0

Share this post


Link to post
Share on other sites

wow i'm glad my idea based on hpebley3's orton effect was made into a plugin! great job BoltBait!

0

Share this post


Link to post
Share on other sites

Awesome !! :D

Another BIG (*very good*) BoltBait's plugin !

Thanks so much.

0

Share this post


Link to post
Share on other sites

Once again Bolt you've done it again! Mkaing me and my PC art powers happy :-)

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Very nice! Thank you :)

0

Share this post


Link to post
Share on other sites

Rock on BoltBait. You've made one of my favorite plugins even better. Thanks. :D

0

Share this post


Link to post
Share on other sites

i like this effect!

its really cool

it makes a picture cherubic in a way!

0

Share this post


Link to post
Share on other sites

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?

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