Jump to content

newbie effect question...


drakaan

Recommended Posts

Hi all, I'm trying (unsuccessfully, so far) to use codelab to create a plugin that splits an image in two. Just one horizontal split.

The code I have so far is:

void Render(Surface dst, Surface src, Rectangle rect)
{
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);

   // Delete any of these lines you don't need
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   int offsetx = 0;
   int V1 = 10;
   int H1 = 10;
   int spacing = 10;

               for (int y = rect.Bottom; y > rect.Top; --y)
               {
                   for (int x = rect.Right; x > rect.Left; --x)
                   {
                       if (x > rect.Left + V1)
                       {
                           offsetx = spacing * 2;
                       } else {
               	    offsetx = 0;
                       }

                       if (x < rect.Right - offsetx)
                       {
                           dst[x + offsetx, y] = src[x, y];
                       }
                   }
               }
}

I had some errors with x being beyond the bounds of the selection which seem handled, but there's no obvious movement of the ol' pixels.

Can somebody hit me with a clue-by-four?

drakaan sig jan 2020.png

Link to comment
Share on other sites

Show me an example of a "before" and "after" image.

The first issue I see is in the following line of code:

dst[x + offsetx, y] = src[x, y];

it should look more like this:

dst[x, y] = src[ ... ];

Remember, in your loops, you should be looping through the destination canvas NOT the source canvas.

Link to comment
Share on other sites

Sure...it's a simple idea...

Before:

before.png

After:

after.png

Iterating over the destination canvas sounded counterintuitive to me when I read it, but after thinking about it, I believe I grok it in fullness.

I should be using the current X and Y for the destination surface and for that point, set the pixel's values according to my desired value based on calculations of the source surface's geometry (instead of bass-ackwards, like I just attempted to do).

Does that mean that effects can never alter pixels outside of the selection?

It seems like an obvious question, but I can think of some situations where having the selection not be a mask for the effect would be handy.

drakaan sig jan 2020.png

Link to comment
Share on other sites

Does that mean that effects can never alter pixels outside of the selection?

Effects are not allowed to modify pixels outside of the ROI* that has been passed to it.

You can always read pixels outside of your selection, you just can't modify them.

There is some discussion of this here: http://paintdotnet.12.forumer.com/viewtopic.php?t=5281

*ROI=Rectangle of Interest

Link to comment
Share on other sites

Okay...modified it a bit. Now I see copied pixels, but I guess I have to clear the source pixels for the locations where I moved them?

EDIT: Now it's clipping correctly, I just don't know how to make the right pixels transparent...

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 

   // Delete any of these lines you don't need 
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
   int offsetx = 0; 
   int V1 = 10; 
   int H1 = 10; 
   int spacing = 10; 

               for (int y = rect.Top; y < rect.Bottom; ++y) 
               { 
                   for (int x = rect.Left; x < rect.Right; ++x) 
                   { 
                       if (x > rect.Left + V1) 
                       { 
                           offsetx = spacing; 
                       } else { 
                      offsetx = 0; 
                       } 

                       if (x > rect.Left + offsetx) 
                       { 
               	    if (x > rect.Left + (offsetx * 2)) {
                   		dst[x, y] = src[x - offsetx, y];
                           } else {

               ColorBgra CurrentPixel = src[x,y];
               // TODO: Add pixel processing code here
               // Access RGBA values this way, for example:
                CurrentPixel.R = 0;
                CurrentPixel.G = 0;
                CurrentPixel.B = 0;
                CurrentPixel.A = 0;
                           }
                       } 
                   } 
               } 
}

drakaan sig jan 2020.png

Link to comment
Share on other sites

Woohoo! Figured it out!

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 

   // Delete any of these lines you don't need 
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); 
   int offsetx = 0; 
   int V1 = 10; 
   int H1 = 10; 
   int spacing = 10; 

               for (int y = rect.Top; y < rect.Bottom; ++y) 
               { 
                   for (int x = rect.Left; x < rect.Right; ++x) 
                   { 
                       if (x > rect.Left + V1) 
                       { 
                           offsetx = spacing; 
                       } else { 
                      offsetx = 0; 
                       } 

                       if (x > rect.Left + offsetx) 
                       { 
               	    if (x > rect.Left + (offsetx * 2)) {
                   		dst[x, y] = src[x - offsetx, y];
                           } else {
                           	ColorBgra dpix = src[x - offsetx, y];
                   		dpix.A = 0;
               		dst[x,y] = dpix;
                           }
                       } 
                   } 
               } 
} 

Learned a few things, too...

drakaan sig jan 2020.png

Link to comment
Share on other sites

Cool.

Now, you need to read part 2 of my plugin tutorials so you can put some sliders on the UI:

http://paintdotnet.12.forumer.com/viewtopic.php?t=5308

I plan on more than that, eventually (draggable dividers on a thumbnail image)...I definitely need to read that article, though.

Final goal is a basic image splitter for cutting images up to use in web forms. You'll have a choice of one or two horizontal or vertical dividers and their placement on the image...maybe a "make symmetrical" button, too.

drakaan sig jan 2020.png

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