Jump to content


Photo

Outline Selection


  • Please log in to reply
23 replies to this topic

#1 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 13 May 2008 - 05:17 PM

First plugin, word.

Selection > Outline Selection
Size - The thickness of the border/outline
Outside <-> Inside - Right now, does nothing. Next version this will be removed, since I can't edit pixels outside the range, and I can't increase the size of the selection
Colour - Colour of the border/outline

It's quiet simple actually. The point was to allow me to make an outline outside/inside a highlighted selection. Much like Photoshop's Stroke command which I used to use quiet frequently. The effect simple puts a border of specified width and colour on the current layer.

Currently, this 'effect' only outlines on the inside of the selection, and only works for rectangular, singular selection (as in, not multiple boxes). The plan is to eventually be able to outline inside or outside the box, and if it's even possible, to outline on the canvas everything that is selected.

Right now it's not much more useful than the box tool, as it's just as easy to draw the selection as it is to draw the box. However, it does have some advantages:

- It's gaurenteed to be inside the selection.
- When there's nothing selected, it will outline the entire canvas. Since it works always inside the selection, this is great for adding a border to an image.
- Since it's based off of the selection, you can use the marquee tool to select a specific pixel size box, etc.

Let me know your comments. I can post source, if requested. It wasn't actually that complicated once I got realized what the heck was going on.

Edit: Of course I forgot to upload it.

Just a note, one person had the following error:

1 of 1
--------------
File: C:\Program Files\Paint.NET\Effects\OutlineSelection.dll
Effect Name: OutlineSelection.OutlineSelectionPlugin
Full error message: System.TypeLoadException: Method 'OnCreatePropertyCollection' in type 'OutlineSelection.OutlineSelectionPlugin' from assembly 'OutlineSelection, Version=1.0.3055.21360, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I don't think this is because of my plugin, but if more people experience it, let me know, and I'll see if the .dll got corrupt. The actual code is pretty simple so I don't think there's a bug in it.


Copyright notice: This work is copyright me, Anthony Aziz. Feel free to use it or distribute it however you like, as long as you give credit back to me. The exception is that this plugin may not be sold in any way.

Attached Files



#2 R3VENGE

R3VENGE
  • Members
  • 1,162 posts
  • Reputation:0

Posted 13 May 2008 - 05:53 PM

nice plugin thanks :D

Posted Image
psn id: R3V-fiR3


#3 zisworg

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

Posted 13 May 2008 - 05:57 PM

Thank you aziz! :)

#4 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 13 May 2008 - 05:58 PM

Of course! I've got a couple more in mind, too.

#5 BoltBait

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

Posted 13 May 2008 - 06:00 PM

It doesn't work with irregular selections.
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#6 Mike Ryan

Mike Ryan
  • Competition Hosts
  • 4,263 posts
  • Reputation:9

Posted 13 May 2008 - 06:01 PM

Looks good I s'pose. More than anything it seems like a plugin to grasp Paint.NET's Effects API so I hope you have learned something. This is better than anything I am currenty able to make :oops:

Posted Image


#7 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 13 May 2008 - 06:12 PM

It doesn't work with irregular selections.


I hope that falls under "The above post contains sarcasm" :roll: :

Currently, this 'effect' only outlines on the inside of the selection, and only works for rectangular, singular selection (as in, not multiple boxes


Looks good I s'pose. More than anything it seems like a plugin to grasp Paint.NET's Effects API so I hope you have learned something. This is better than anything I am currenty able to make :oops:


It was my first plugin, and did help me grasp the Effects API. Though I only did it because I needed the effect :P I don't know about anyone else, but personally I'll be using this a lot.

#8 BoltBait

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

Posted 13 May 2008 - 06:17 PM

It doesn't work with irregular selections.


I hope that falls under "The above post contains sarcasm" :roll: :

Oops! I missed that.

Here is a version that does work on complex selections.



It is not based on your code... just your idea.

It is limited to single pixel width lines. Here is the source:

// Author: BoltBait
// Submenu: Selection
#region UICode
ColorBgra Amount1 = ColorBgra.FromBgr(0,0,255); // Outline Color
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
    ColorBgra CurrentPixel;
    for(int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            if ( (x>0 && x<src.Width) && (y>0 && y<src.Height) )
            {
                if ((!selectionRegion.IsVisible(x-1, y) ||
                     !selectionRegion.IsVisible(x, y-1) ||
                     !selectionRegion.IsVisible(x+1, y) ||
                     !selectionRegion.IsVisible(x, y+1)
                   ))
                {
                    CurrentPixel=Amount1;
                }
            }
            else
            {
                CurrentPixel=Amount1;
            }
            dst[x,y] = CurrentPixel;
        }
    }
}

I will leave it up to you to add back in the line width... ;)
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#9 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 13 May 2008 - 06:26 PM

Heh, sorry I guess I should've looked to see if someone else had done this. I guess mine does allow thicker borders at the expense of only doing rectagular selections. I read your post about finding the edge of an object based on looking at its neighbours. Though, at least in this situation, wouldn't it be better to look in 8 directions rather than 4? It's nice to know how to get the entire selected region and deal with it now, too. Thanks!

#10 BoltBait

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

Posted 13 May 2008 - 06:31 PM

I find that 4 directions is enough. I did a bunch of research around this issue when I was first woring on my Feather plugin. In fact, that is how my Feather plugin used to work. (It is much less complicated now.)
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#11 BoltBait

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

Posted 13 May 2008 - 09:48 PM

Here is another version of the one I posted above. It includes outline width and works with complex selections:

Attached File  BoltBaitOutlineSelection.zip   3.83K   555 downloads

And, here is the source (ugly, I know):

// Author: BoltBait
// Submenu: Selection
#region UICode
int Amount1 = 2; // [1,10] Outline Width
ColorBgra Amount2 = ColorBgra.FromBgr(0,0,0); // Outline Color
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
    ColorBgra CurrentPixel;
    int Width=Amount1*2;  
    int m,n;      
    for(int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            for (int v=0; v<=Width; v++)
            {
                m = y-(Width/2)+v;
                if (m<=0) 
                {
                    m=0;
                    CurrentPixel = Amount2;
                }
                if (m>=src.Height)
                {
                    m=src.Height;
                    CurrentPixel = Amount2;
                }                                                        
                for (int w=0; w<=Width; w++)
                {
                    n = x-(Width/2)+w;
                    if (n<=0) 
                    {
                        n=0;
                        CurrentPixel = Amount2;
                    }                                                                            
                    if (n>=src.Width)
                    {
                        n=src.Width;
                        CurrentPixel = Amount2;
                    }                                                                    
                    if (!selectionRegion.IsVisible(n,m))
                        CurrentPixel = Amount2;
                }
            }                                                                
            dst[x,y] = CurrentPixel;
        }
    }
}

Anti-aliasing is an exercise left up to the reader. :P
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#12 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 14 May 2008 - 02:33 AM

Wow, taking me to school or what. Is it any problem if I use any of that in my code? I won't re-release it, as you already have, but more so for learning/using it myself.

#13 Bleek II

Bleek II
  • Members
  • 90 posts
  • Reputation:0

Posted 14 May 2008 - 03:46 PM

I believe that's why he showed the code to you but do be sure to give credit. After all, this is a open source community. Nice plugin by the way, I've already found it to be useful.

#14 BoltBait

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

Posted 14 May 2008 - 04:33 PM

Wow, taking me to school or what. Is it any problem if I use any of that in my code? I won't re-release it, as you already have, but more so for learning/using it myself.

I am giving this code to you.

I will not be publishing it on my own site or plugin pack in its current state (and probably never).

Any of the advanced coders can tell you that there are some obvious optimizations that should be made before it is ready for release.

Seriously, I only wrote this in order to teach you how to do it.
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#15 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 14 May 2008 - 04:36 PM

Right on, thanks. I'll look into that 'optimization' myself.

#16 salu

salu
  • Members
  • 1,058 posts
  • Locationan Unknown State of Animals
  • Reputation:0

Posted 14 May 2008 - 09:19 PM

seems handy *downloads*

#17 Aziz

Aziz
  • Members
  • 36 posts
  • LocationWindsor, Ontario
  • Reputation:0

Posted 15 May 2008 - 01:13 PM

Yeah, while it's not complex or unique, it certainly is very handy.

#18 Hellowmate

Hellowmate
  • Members
  • 33 posts
  • Reputation:0

Posted 15 May 2008 - 06:41 PM

Very very handy!
Thanks a lot aziz.
I could do with a plugin like that
*downloads*

#19 Dalton

Dalton
  • Members
  • 572 posts
  • Reputation:1

Posted 15 May 2008 - 08:12 PM

I'll try to use this sometime. :)

EDIT:200th post! Woot woot!
:lol:
MyBB Tutorials, check out my site. :)

#20 salu

salu
  • Members
  • 1,058 posts
  • Locationan Unknown State of Animals
  • Reputation:0

Posted 16 May 2008 - 11:19 PM

Yeah, while it's not complex or unique, it certainly is very handy.


yups :)