Jump to content

Resize the selection?


Recommended Posts

Seems so, I was trying to do that. But I was able to do it, was more of something with a bug in pdn.

It would draw outside the region but not show it, but if I hit undo in the history window then redo, the drawing appeared.

To reproduce it.

Start with new image, add new layer, draw a rectangle selection on new layer, should be smaller than the canvas size, so that each side of the rectangle selection is more than 25 pixels away from the edge of the canvas.

Go to codelab and paste this code: (make sure to hit build when you paste it).

int Amount1=25; //[1,25]Thickness
int Amount2=0; //[0,1]Line                                    Dashed

void Render(Surface dst, Surface src, Rectangle rect)
{
   // User Interface elements
   int GridSize = Amount1;
bool dashed = (Amount2 == 1);
   // Other variables
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   ColorBgra CurrentPixel;
   ColorBgra PrimaryColor;
   ColorBgra SecondaryColor;

   // Get the current brush width
bool fill = false;

   // Grab the primary and secondary colors (swapping if specified in the UI)
   PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;


if ( dashed )
{
	if ( GridSize == 1 )
	{
		GridSize = 2;
	}
}

// Loop through all the pixels
for(int y = rect.Top-GridSize; y < rect.Bottom+GridSize; y++)
{
	for (int x = rect.Left-GridSize; x < rect.Right+GridSize; x++)
	{
		// Only work with a pixel if it is selected
		// (this handles convex & concave selections)
			// Get the source pixel
			CurrentPixel = src[x,y];
			fill = false;
			if ( ( x < selection.Left ) || ( x >= selection.Right ) )
			{
				if ( ! dashed )
				{
					fill = true;
				}
				else
				{
					int pos = ( selection.Bottom - ( selection.Bottom - y )  ) % (GridSize-1);
					if ( ( pos == 0 ) || ( pos < GridSize/2 ) )
					{
						fill = true;
					}
				}
			}
			else if ( (  y <= selection.Top ) || ( y >= selection.Bottom ) )
			{
				if ( ! dashed )
				{
					fill = true;
				}
				else
				{
					int pos = ( selection.Right - ( selection.Right - x )  ) % (GridSize-1);
					if ( ( pos == 0 ) || ( pos < GridSize/2 ) )
					{
						fill = true;
					}
				}
			}
			if ( fill )
			{
				CurrentPixel.R = (byte)PrimaryColor.R;
				CurrentPixel.G = (byte)PrimaryColor.G;
				CurrentPixel.B = (byte)PrimaryColor.B;
				CurrentPixel.A = (byte)PrimaryColor.A;
			}
			// Save the (modified?) pixel
			dst[x,y] = CurrentPixel;
	}
}
}

hit ok, doesn't look like much happened, on your history window, click on New image again, then click on the code lab in the history you had just undone. Magic! it does exactly what I wanted it to do. That is draw a border outside the selection that is 25 pixels wide.

Effects aren't allowed to draw outside the selection...that's part of the design. The selection specifically defines the clipping region.
mocsig.png
Link to comment
Share on other sites

No, that isn't a bug in Paint.NET, it's a bug in your effect. If you draw outside the selection, Paint.NET isn't going to track those changes. They will not be part of the history, and all sorts of weird things will happen. You will piss off users.

Effects are explicitely required to not draw outside of the rectangles they are given. Future versions of Paint.NET will have ways to strictly enforce this.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Ok relax. I was just explaining the weird thing that happened when I did that. What you said makes sense, an effect should not draw outside its selection. I wouldn't call it a bug, it is perhaps an illegal operation to be performed on an effect.

Any case, thanks for the information on the operations of paint.net effects and history window.

No, that isn't a bug in Paint.NET, it's a bug in your effect. If you draw outside the selection, Paint.NET isn't going to track those changes. They will not be part of the history, and all sorts of weird things will happen. You will piss off users.

Effects are explicitely required to not draw outside of the rectangles they are given. Future versions of Paint.NET will have ways to strictly enforce this.

mocsig.png
Link to comment
Share on other sites

Sorry, I was just trying to stress that while something may appear to work, that doesn't necessarily mean it's actually doing what you want it to.

If you draw outside the selection, then yes it may show up if you play around with the history controls. Once an effect is applied, the selected region is redrawn -- but not necessarily anything outside of that region. However, an optimization in many places in Paint.NET applies what is called a simplification to these regions that describe what parts of the image to redraw. For a complex update region that is described by many rectangles (often hundreds), it attempts to create a region that is composed of a small number of rectangles (like 10 or 50 or so). This simplified update region is quicker to redraw: it draws more pixels, but spends less time in the outer loop processing the actual Rectangle data. This simplified region also covers pixels that may be outside the actual selection region -- the simply axiom being that it is required to redraw pixels that have changed, but still OK to redraw pixels that have not changed.

The old contents of the selected region is also saved to disk for undo/redo purposes. Region simplification is not applied at this stage. When you then undo/redo, at some points the entire image is redrawn -- this is when you'll see what you drew outside the selection. However, since those areas are not being tracked for history, they will cause the history to look like it is malfunctioning. For instance, you may do an undo twice, and then redo twice -- and then your changes outside the selection will be gone. Or, maybe they'll still be there even if you completely rewind the history!

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

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.

 Share

×
×
  • Create New...