Jump to content


Photo

Portrait Effect Plugin (Updated 2007-05-27)


  • Please log in to reply
21 replies to this topic

#1 BoltBait

BoltBait
  • Administrators
  • 8,909 posts
  • LocationCalifornia, USA
  • Reputation:103

Posted 04 April 2007 - 12:32 AM

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.

Posted Image
More Info

As always, more information can be found here: http://boltbait.goog...es.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 © 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!
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#2 BuzzKill

BuzzKill
  • Members
  • 1,020 posts
  • LocationCorpus Christi
  • Reputation:1

Posted 04 April 2007 - 01:24 AM

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:
Posted Image
- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

#3 Riot

Riot
  • Members
  • 15 posts
  • Reputation:0

Posted 04 April 2007 - 01:26 AM

I like it. Good job.
Posted Image
^^
First Creation with Paint.NET

#4 BoltBait

BoltBait
  • Administrators
  • 8,909 posts
  • LocationCalifornia, USA
  • Reputation:103

Posted 04 April 2007 - 01:27 AM

BuzzKill!!!!

I'm in ur Paint Dot Net... eatin' ur cookie. :D
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#5 Leif

Leif
  • Members
  • 672 posts
  • LocationDenmark
  • Reputation:0

Posted 04 April 2007 - 01:50 AM

Thanks. Those two plugin looks really interesting.
I just bought a scanner, so they might come in very handy.
Posted Image
My DA: http://leif-j.deviantart.com/
--------------
Some people seek justice so persistent, that they will do great injustice themselves.

#6 Helio

Helio
  • Members
  • 1,954 posts
  • LocationMichigan, USA
  • Reputation:1

Posted 04 April 2007 - 02:14 AM

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

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

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

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


#7 davidtayhs

davidtayhs
  • Members
  • 195 posts
  • Reputation:0

Posted 04 April 2007 - 05:27 AM

Thanks for a wonderful portrait plugin!

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

#8 MadJik

MadJik
  • Members
  • 2,428 posts
  • LocationLille;France
  • Reputation:20

Posted 04 April 2007 - 08:18 AM

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!

#9 BoltBait

BoltBait
  • Administrators
  • 8,909 posts
  • LocationCalifornia, USA
  • Reputation:103

Posted 05 April 2007 - 01:26 AM

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. ;)
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#10 Mr Frojo

Mr Frojo
  • Members
  • 2,118 posts
  • LocationColorado
  • Reputation:2

Posted 05 April 2007 - 09:21 PM

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

I'm still alive!


#11 jpope

jpope
  • Members
  • 164 posts
  • LocationJefferson City, MO
  • Reputation:0

Posted 06 April 2007 - 04:33 AM

Great plugin. Works great for other stuff too.
Before:
Posted Image
After:
Posted Image
Thanks BoltBait. :)
Posted Image

#12 Picc84

Picc84
  • Members
  • 1,122 posts
  • LocationNorth Eastern, PA
  • Reputation:0

Posted 06 April 2007 - 10:21 PM

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

#13 belman92

belman92
  • Members
  • 10 posts
  • Reputation:0

Posted 08 April 2007 - 03:05 PM

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

#14 zisworg

zisworg
  • Members
  • 77 posts
  • LocationLyon, France
  • Reputation:0

Posted 14 April 2007 - 08:56 PM

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

Thanks so much.

#15 olav.k.m

olav.k.m
  • Members
  • 294 posts
  • LocationBergen, Norway
  • Reputation:0

Posted 20 April 2007 - 06:41 PM

wow. I love this plugin! :D

#16 Nesk

Nesk
  • Members
  • 184 posts
  • Reputation:0

Posted 28 April 2007 - 10:44 PM

Wow, thats a great plugin! Thanks for sharing it.

#17 Zeras737

Zeras737
  • Newbies
  • 4 posts
  • Reputation:0

Posted 03 May 2007 - 12:49 PM

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

#18 BoltBait

BoltBait
  • Administrators
  • 8,909 posts
  • LocationCalifornia, USA
  • Reputation:103

Posted 28 May 2007 - 05:19 AM

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.
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#19 Ash

Ash

    Former Moderator

  • Members
  • 6,381 posts
  • Locationhttp://tinyurl.com/6kqz9v
  • Reputation:5

Posted 28 May 2007 - 05:58 AM

Very nice! Thank you :)

#20 jpope

jpope
  • Members
  • 164 posts
  • LocationJefferson City, MO
  • Reputation:0

Posted 28 May 2007 - 07:39 AM

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