Jump to content

Photo alignment & cropping guide


Recommended Posts

I will dig the code out. Red Ochre took a look at this plugin and developed it much further Composition Tool. How does that compare?

  • Upvote 1
Link to comment
Share on other sites

Not sure if this may help xod? :/
quarterizer.zip
I made it a while back to run on a transparent layer to render lines that I could use to 'contain' the magic wand, when I wanted to select a quarter of the canvas. If it helps I can post the code lab code?

(E.E.R. - I'm not 'formally' publishing this one - well I could but it doesn't do much! - found under Render, not Plugin Browser compatible, .dll name 'quarterizer')
 

  • Upvote 1

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Many, many thanks Red ochre, that's exactly what I was looking for!

Thanks a lot.! You can post the code lab code?

I haven't programmed a long time, the time of the Z80µP, but I learn C # and codes helps me to understand how things are done.

 

And thanks also to EER for his kindness.

Link to comment
Share on other sites


// Name: quarterize

// Author: Red ochre (John Robbins)

// Submenu: Render

// URL: http://www.getpaint.net/redirect/plugins.html

// Title: Quarterize Nov 2012 Red ochre

#region UICode

int Amount1 = 1; // [0,100] line width (color from primary)

bool Amount2 = false; // [0,1] diagonals

#endregion

void Render(Surface dst, Surface src, Rectangle rect)

{ Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

ColorBgra PC = (ColorBgra)EnvironmentParameters.PrimaryColor;

// ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;

dst.CopySurface(src,rect.Location,rect);// copy surface quicker than looping through

int lineW = Amount1;

float Stop = selection.Top;

float Sbot = selection.Bottom;

float Sleft = selection.Left;

float Srite = selection.Right;

float H = Sbot - Stop;float midH = (H/2) - 0.5f;

float W = Srite - Sleft;float midW = (W/2) - 0.5f;

// create a GDI+ graphics surface

Graphics g = new RenderArgs(dst).Graphics;

g.Clip = new Region(rect);

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

// create a pen

Pen priPen = new Pen(Color.FromArgb(PC.A,PC.R,PC.G,PC.B));priPen.Width = lineW ;

if(!Amount2)//V & H

{

PointF topmid = new PointF(Sleft + midW,Stop - 1f);

PointF botmid = new PointF(Sleft + midW,Sbot);

PointF leftmid = new PointF(Sleft - 1f ,Stop + midH);

PointF ritemid = new PointF(Srite ,Stop + midH);

g.DrawLine(priPen,topmid,botmid);

g.DrawLine(priPen,leftmid,ritemid);

}

if(Amount2)//diagonals

{

PointF topleft = new PointF(Sleft,Stop );

PointF botrite = new PointF(Srite,Sbot - 0.5f );

PointF toprite = new PointF(Srite ,Stop - 1f);

PointF botleft = new PointF(Sleft ,Sbot - 1f);

g.DrawLine(priPen,topleft,botrite);

g.DrawLine(priPen,botleft,toprite);

}

// dispose of graphics objects

priPen.Dispose();

// g.Dispose();- do not dispose as an alias for something I did not create

}

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

My source as promised.  Red's code uses GDI+ graphics to draw the lines, mine uses the primary/secondary color and changes the pixels directly.  That's why they look quite different.

 

Feel free to ask questions if you don't understand the posted source.

/* ================================================================================= */
/*                                                                                   */
/*   Photo Marker.cs                                                                 */
/*   (c) 2011 Ego Eram Reputo                                                        */
/*                                                                                   */
/*   Description: Renders a number of selectable photo alignment markers             */
/*                                                                                   */
/* ================================================================================= */

// Name: Photo Alignment Tool
// Author: Ego Eram Reputo
// Submenu: Photo
// URL: http://www.getpaint.net/redirect/plugins.html
// Title: Photo Alignment Tool - Ego Eram Reputo

#region UICode
bool Amount1 = false; // [0,1] Show Center Lines
int Amount2 = 0; // [-500,500] Up       Adjust Horisontal      Down
bool Amount3 = true; // [0,1] Draw 'Rule of 1/3rds'
byte Amount4 = 1; // [1] .        Rule of 1/3 Marker Style | Point Markers | Gridlines | Alternating Solid Fill
bool Amount5 = false; // [0,1] Use Secondary Color
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
    ColorBgra UseColor, CurrentPixel;
       
    int ThirdOfWidth = ( selection.Right - selection.Left ) / 3;  // potential for rounding errors here!
    int ThirdOfHeight = ( selection.Bottom - selection.Top ) / 3;  // and here.
    
    int OneThirdX = selection.Left + ThirdOfWidth;
    int OneThirdY = selection.Top + ThirdOfHeight;

    int TwoThirdX = selection.Left + ( ThirdOfWidth * 2 );
    int TwoThirdY = selection.Top + ( ThirdOfHeight * 2 );
        
    int CentreX = (( selection.Right - selection.Left ) / 2 ) + selection.Left ;   // more rounding 
    int CentreY = (( selection.Bottom - selection.Top ) / 2 ) + selection.Top ;
                
    if (!Amount5) 
    {
        UseColor = PrimaryColor;
    }
    else    
    {
        UseColor = SecondaryColor;
    } 
    
    for (int y = selection.Top; y < selection.Bottom; y++)
    {
        for (int x = selection.Left; x < selection.Right; x++)
        {
            CurrentPixel = ColorBgra.FromBgra( 255, 255, 255, 0);    // default = fully transparent
            
            // draw centre lines, vertical and horisontal +/- adjustment
            if ( Amount1  && ( y == ( CentreY + Amount2 ) || ( x==CentreX ) ) ) CurrentPixel =  UseColor;

            // Draw rule of thirds as point markers
            if ( Amount3 )
            {
                switch (Amount4)
                {
                    case 0:  //  Point Markers
                            if ( (( x == OneThirdX ) || ( x == TwoThirdX )) && (( y == OneThirdY ) || ( y == TwoThirdY )) )  CurrentPixel =  UseColor; 
                    break;
                    
                    case 1:  //  Draw rule of thirds as gridlines
                            if ( ( x == OneThirdX ) || ( x == TwoThirdX ) || ( y == OneThirdY ) || ( y == TwoThirdY ) ) CurrentPixel =  UseColor;
                    break;
                    
                    case 2:  //  Draw rule of thirds as alternating solid fills
                            if ( ( ( ( x/ThirdOfWidth)+( y/ThirdOfHeight) ) % 2 ) == 0 ) CurrentPixel =  UseColor;
                    break;
                    
                    default:
                    break;
                    
                }   
            }    
            
            dst[x,y] = CurrentPixel;
        }
    }
}

Link to comment
Share on other sites

Strange things happen with CodeLab v1.8 ( PDN 3.5.11 / NET Framework 3.5 SP1 / WinXP ).

 

Plugins default named Untitled are not displayed in PDN 3.5.11 so I must to rename them keeping the .dll extension.

After that they appear in the PDN Effects but appears twice.

 

GxjfIh9.png

Link to comment
Share on other sites

Hi xod,
I am using codelab 1.8 in Pdn 3.5.11 (I'm on Vista).

Make sure you save each version of your plugin as a '.cs' file, with a unique name (eg. Axes1a, Axes1b, Axes9z ... etc), before you compile. Codelab will not allow you to compile two .dlls with the same name.
I usually create many versions before I am happy with an effect - I then delete all those oddly named .dlls from the Effects folder before compiling the final version with a simple name (eg. Axes).
I would not recommend renaming the .dlls themselves.

That's just the way I work using codelab (I find the version numbering too confusing).
If in doubt delete all your 'Axes' .dlls and 'Untitled' .dlls and recompile in codelab from the saved .cs file.

Z80 spectrum! - I went straight from a Commodore64 to C# on Vista! (which explains a lot) :lol:

Good luck - glad you are giving it try!
 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Make sure you save each version of your plugin as a '.cs' file, with a unique name (eg. Axes1a, Axes1b, Axes9z ... etc), before you compile. Codelab will not allow you to compile two .dlls with the same name.

 

 

Thanks Red, that's the key.
I used your code because is very fast and more simplest. Anyway I have a lot to learn.
I don't made any changes without add an icon to display in effect menu and I changed Amount1 = 2  (line width)
because 0 or 1 give some transparency, I don't know why.
By the way, with value 0 should not draw anything, I suppose?
 
McleKqO.png
Edited by xod
Link to comment
Share on other sites

Perhaps besides the rule-of-thirds guide lines, you could also allow the option of golden mean (aka golden section) guide lines. These are at about 0.381966 and 0.618034 instead of 0.3333 and 0.6667, placing the focal point slightly closer to the center. I often find golden-mean positioning a bit more attractive than the rule-of-thirds.

Edited by MJW
Link to comment
Share on other sites

I'm sure Red Ochre's plugin does golden sections.

Link to comment
Share on other sites

This is my first try to make a plugin.

 

The code is Red ochre's Quarterizer that I made a few changes that were needed me. Thanks again Red.

If the canvas is bigger than 800x600, then we can't move the lines to the edges.

Perhaps it will be useful to somebody else.

Link to comment
Share on other sites

Perhaps it will be useful to somebody else.

 

It is useful to me. When needed, I used to draw my corner to corner diagonal lines manually. The AXES plugin will allow me to do it faster and with more precission. Thanks.

 

Perhaps you should also add an option to use broken lines  - - - - - , dots ....., etc. 

If you could increase the line width to 1000 it would be great for very large selections.

Edited by Eli
Link to comment
Share on other sites

If the canvas is bigger than 800x600, then we can't move the lines to the edges.

We need to sort that out :)

How about posting the code so we can assist?

Link to comment
Share on other sites

Ah! I haven't downloaded it yet (on my tablet). Thanks ReMake!

Link to comment
Share on other sites

I would advise You set the maximum values of Amount6 and Amount7 in 100 (not pixels, but %)

 

int Amount6 = 0; // [0,100] Move Y(%): Left - Right
int Amount7 = 0; // [0,100] Move X(%): Up - Down

 

and change this part of the code:

 

if (Amount5)// Move Lines
{
PointF top = new PointF((W * Amount6)/100 + Sleft ,Stop - 1f);
PointF bot = new PointF((W * Amount6)/100 + Sleft ,Sbot);
PointF left = new PointF(Sleft - 1f ,Stop + (H * Amount7)/100);
PointF rite = new PointF(Srite ,Stop + (H * Amount7)/100);

g.DrawLine(priPen,top,bot);
g.DrawLine(priPen,left,rite);
}

 

This will allow You to move lines from left to right and from top to bottom irrespective of the canvas size.

 

Good Luck!

Edited by ReMake
Link to comment
Share on other sites

Thanks ReMake. I didn't know that but is logic. It works like a charm.

But I want to obtain same value as the rulers for my personal use.

 

If there were a  function to transfer the size of the canvas directly as the value for sliders, would be great.

Link to comment
Share on other sites

Well done xod - you are making good progress! ;)
Thanks Remake for helping out. B)

Perhaps consider using a 'Double Vector' control to replace Amount6 and Amount7, to move the 'origin' of the grid lines? (But it has to be what you find useful!). See the 'uielements' section in Boltbait's codelab tutorials as Remake linked to above.
 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

(W * Amount6)/100 is equivalent  W*(Amount6/100) and equivalent ((float W = Srite - Sleft)*Amount6/100).

 

 

xod, excuse me for the incorrect answer. Perhaps I misunderstood Your thoughts. It is caused by difficulties of a direct and back translation (I studied English 30 years ago).

Edited by ReMake
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...