Jump to content


Photo

Tube Effect (ymd: 100718)


  • Please log in to reply
45 replies to this topic

#1 MadJik

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

Posted 04 April 2007 - 01:07 PM

Tube Effect
(or oblique cylinder?)

What's this?

Photo sample from:
http://www.photo-libre.fr

Posted Image
This is a distort effect plugin. It allows you to distort the image as if you put in on a cylinder...
While moving, if the image leaves the area on a side it will reappear on the other.

In fact it was originally 99% made with CodeLab...(1% for external text editor, and for the icon).

Download the DLL
Plugin TubeOblique.dll
Posted ImageHere is the DLLPosted Image

The source is available with the plugins package!
http://forums.getpaint.net/index.php?showtopic=7186

How to install?
Close Paint.net
Unzip and place the DLL in your Effect folder usually: C:/Program Files/Paint.NET/Effects

The User interface
Posted Image
X,Y Offset (direction):
...you could choose the direction of the distortion.

Steps factor:
...you could increase the effect of distortion.

Quality:
...increasing the quality is slowering the rendering a bit, and should reduce the pixelisation.

Options:
_ Centered: if checked the borders are moving and the middle of the image is stable.
_ Horizontal flip: if checked the upper part moves in opposite way than the lower part, like a S or Z.
_ Vertical flip: if checked the right part moves in opposite way than the left part, like ~.

Examples:

Posted Image

Posted Image

Posted Image

Attention, need surounding but not everywhere!
Let's test with this simple image. Let's say the blue rectangle is the subject.
In this example the subject is in the middle of the area. The effect takes the full width of the selection and so the subject is moved down:
Posted Image

For a better result (depending on what you are looking for!) you shoud cut/paste in a new image for the time to apply the effect.
Take away left/right margin and leave up/low transparent (for a vertical effect).
Then the effect is fully applied on the subject, most left and most right pixels don't move (or just 1-2 px).
Posted Image


Advanced Example
To make the 'glass' on the first picture:
I've set the background color to transparent.
I've resized the canvas only verticaly.
I mean the picture was (for example) 160x120 I enlarge the canvas to 160x300.
Be sure :
- there is no transparent border on left/right to have a nice tube effect.
- upper/lower borders are transparent...

Then I've duplicated the image.
And Applied Tube V:+0.60 steps 100 not centered, on the top layer
And Applied Tube V:-0.60 steps 100 not centered, on the second layer

And some other effects (shadow, glow, ..), I forgot to use the feather...

Please test it and give your comments...

#2 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 04 April 2007 - 02:37 PM

This looks really cool. Would you be able to add anti-aliasing?
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#3 Zulu2

Zulu2
  • Newbies
  • 8 posts
  • Reputation:0

Posted 04 April 2007 - 04:45 PM

man.....this is crazy thanks for the plugin

#4 BuzzKill

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

Posted 04 April 2007 - 04:51 PM

Positioning of the object(you wish to tubulize) in the canvas is vital and can be very tricky.

Cool plugin but it needs some work. Anti-aliasing would be nice. Also, the panelling* of the object can be quite bothersome.


Posted Image*panelling


Posted ImageCoffee anyone?

Posted Image
- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

#5 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 12,567 posts
  • LocationKirkland, WA
  • Reputation:120

Posted 04 April 2007 - 05:11 PM

I'm still not sure why you're sampling the selectionRegion.IsVisible() at every pixel. The list of rectangles you get is limited to the selected region anyway, so this will always return true. I tried to tell BoltBait this about 5 times but it has still persisted in the template.

Also, instead of doing:
CurrentPixel = src[srcX,srcY];
try this:
CurrentPixel = src.GetBilinearSample(srcXd, srcYd);
And get rid of the IEEERemainder stuff. It will look much more better.
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#6 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 04 April 2007 - 05:13 PM

"much more better"

So, you're saying it will look very good?
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#7 BoltBait

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

Posted 04 April 2007 - 05:19 PM

I'm still not sure why you're sampling the selectionRegion.IsVisible() at every pixel. The list of rectangles you get is limited to the selected region anyway, so this will always return true. I tried to tell BoltBait this about 5 times but it has still persisted in the template.

That is true... except for irregular selections.

If you don't check, you'll get issues like this:

Posted Image

Which I ran across when developing the Gradient plugin that I wrote.

Besides, you're the one that gave me the code in the first place. :D
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#8 MadJik

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

Posted 04 April 2007 - 08:31 PM

@Rick:
BoltBait is in some way my 'guide' so it's not surprising to find some similar stuff...
@BuzzKill and All:
Ok for Antialias but how with Codelab?

#9 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 12,567 posts
  • LocationKirkland, WA
  • Reputation:120

Posted 04 April 2007 - 09:00 PM

That is true... except for irregular selections.

No, it's completely true especially for irregular selections. The current selection is passed straight to the effect rendering harness. The whole point of the effect system in Paint.NET is that you don't have to worry about things like clipping to the selection, multicore scaling, etc.

If you don't check, you'll get issues like this:

Posted Image

Which I ran across when developing the Gradient plugin that I wrote.

I don't understand what you're showing me here. The layer thumbnail does not update while the effect is running. It sounds like an implementation problem, or you were using a beta version where things were operating differently.

Besides, you're the one that gave me the code in the first place. :D

No, I didn't give you that part of the code. I tried telling you several times that you don't need to call selectionRegion.IsVisible().

Edit: Woops, I did give you that code. But then I tried to correct myself in the very next post.
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#10 BoltBait

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

Posted 04 April 2007 - 09:03 PM

@BuzzKill and All:
Ok for Antialias but how with Codelab?

Rick already told you... Use src.GetBilinearSample(srcXd, srcYd);

int Amount1=0;  //[-200,200]Horizontal cylinder factor 
int Amount2=0;  //[-200,200]Vertical cylinder factor 

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

    float RadiusY =(float)Amount1 / 100.0f; 
    float RadiusX =(float)Amount2 / 100.0f; 
    
    long SizeX = (long)(selection.Right - selection.Left); 
    long SizeY = (long)(selection.Bottom - selection.Top); 
    long CenterX = (long)((SizeX / 2.0f)+selection.Left); 
    long CenterY = (long)((SizeY / 2.0f)+selection.Top); 

    for(int y = rect.Top; y < rect.Bottom; y++) 
    { 
        for (int x = rect.Left; x < rect.Right; x++) 
        { 
            if (selectionRegion.IsVisible(x, y)) 
            { 
              float AngleY = (float)Math.Asin(2.0f*(float)(y - CenterY)/(float)SizeY); 
              float srcXd = (float)(Math.Cos(AngleY) * RadiusY * CenterY)+x; 
              if (srcXd < 0) srcXd+=(float)SizeX;
              if (srcXd > SizeX) srcXd-=SizeX; 

              float AngleX = (float)Math.Acos(2.0f*(float)(x - CenterX)/(float)SizeX); 
              float srcYd = (float)(Math.Sin(AngleX) * RadiusX * CenterX)+y; 
              if (srcYd < 0) srcYd+=SizeY; 
              if (srcYd > SizeY) srcYd-=SizeY;

              dst[x,y] = src.GetBilinearSample(srcXd, srcYd); 
           } 
        } 
    } 
}

Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#11 MadJik

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

Posted 04 April 2007 - 09:26 PM

Oops, never thought it was for antialiasing... Thanks!
Edited the first post to change this in the code and added more explanations....
Changed the dll also (please download it again!)

#12 BuzzKill

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

Posted 04 April 2007 - 09:37 PM

Much better! Thanks.
Posted Image
- DO NOT contact me asking for the .pdn of my avatar or the PDN logo. Thank you. Have a nice day.

#13 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 12,567 posts
  • LocationKirkland, WA
  • Reputation:120

Posted 04 April 2007 - 09:39 PM

Well, don't confuse antialiasing and sampling methods.

This may not make the edges smooth.
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#14 BoltBait

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

Posted 04 April 2007 - 09:43 PM

Well, don't confuse antialiasing and sampling methods.

This may not make the edges smooth.


True, but I think barkbark00 was really asking for a better sampling method.

Now, if you leave some space around the image before you run the effect, the sampling method should create a sort of antialiasing. The only problem in this case is when the image repeats.
Click to play:
Posted ImagePosted ImagePosted ImagePosted ImagePosted Image
Download: BoltBait's Plugin Pack | CodeLab | More... and how about a Computer Dominos Game

#15 Rick Brewster

Rick Brewster

    Paint.NET Author and Developer

  • Administrators
  • 12,567 posts
  • LocationKirkland, WA
  • Reputation:120

Posted 04 April 2007 - 09:44 PM

Yeah I think you should be fine.

Rotate/Zoom does some weird faux-antialiasing so that the edges of the rectangle are smooth. I forget exactly how it does it; I wouldn't use it as an example :)
The Paint.NET Blog: http://blog.getpaint.net/
Donations are always appreciated! http://www.getpaint.net/donate.html

Posted Image

#16 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 05 April 2007 - 07:54 PM

Would it be possible to revamp the Rectangular to Polar Conversion plug-in Source to include Bilinear Sampling?
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#17 MadJik

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

Posted 05 April 2007 - 08:12 PM

Would it be possible to revamp the Rectangular to Polar Conversion plug-in Source to include Bilinear Sampling?


Few code to change.
I would give a chance to Programmerman (plugin author) to update...
Post your request on his topic... Or update the plugin yourself as the source is provided (I will do it in few days if nobody answers).

#18 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 05 April 2007 - 08:22 PM

Thanks Madjik, I posted the request in his thread.

I would do it but I am lost when it comes to C#.
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster

#19 MadJik

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

Posted 03 May 2007 - 02:38 PM

Tube Effect new version 2007/05/03

What's new:

The two sliders ranges are now : -500% to +500% and default 0%
Horizontal slider is inverted (more 'natural').

Better behave for none square image while moving, if the image leaves the area on a side it will reappear on the other.

The Effect DLL

You can download the effect DLL here: Tube Oblique.dll

Put this file in your c:/program files/Paint.NET/Effects directory. You need to restart Paint.Net.
The Effect is in the Effects menu under Distorts...

Source Code
int Amount1=0;  //[-500,500]Horizontal cylinder factor
int Amount2=0;  //[-500,500]Vertical cylinder factor

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

  float RadiusY =-(float)Amount1 / 100.0f;
  float RadiusX =(float)Amount2 / 100.0f;
  float Distort = 2.0f;

  long SizeX = (long)(selection.Right - selection.Left);
  long SizeY = (long)(selection.Bottom - selection.Top);
  long CenterX = (long)((SizeX / 2.0f)+selection.Left);
  long CenterY = (long)((SizeY / 2.0f)+selection.Top);
  ColorBgra CurrentPixel; 

  for(int y = rect.Top; y < rect.Bottom; y++)
  {
    float AngleY = (float)Math.Asin(Distort *(float)(y - CenterY)/(float)SizeY);
    float srcXd = (float)(Math.Cos(AngleY) * RadiusY * CenterY);
    for (int x = rect.Left; x < rect.Right; x++)
    {
      //CurrentPixel = src.GetBilinearSample(x, y); // Get the current pixel 
      int srcX = (int)Math.IEEERemainder((int)srcXd + x,SizeX);
      if (srcX < selection.Left) srcX+=(int)SizeX;
      if (srcX >= selection.Right) srcX-=(int)SizeX;

      float AngleX = (float)Math.Acos(Distort *(float)(x - CenterX)/(float)SizeX);
      float srcYd = (float)(Math.Sin(AngleX)* RadiusX * CenterX);
      int srcY = (int)Math.IEEERemainder((int)srcYd + y,SizeY);
      if (srcY < selection.Top) srcY+=(int)SizeY;
      if (srcY >= selection.Bottom) srcY-=(int)SizeY;

      CurrentPixel = src.GetBilinearSample(srcX, srcY);
      dst[x,y] = CurrentPixel;
    }
  }
}


#20 barkbark00

barkbark00
  • Members
  • 3,336 posts
  • Reputation:2

Posted 03 May 2007 - 03:04 PM

I've always liked this plugin...

Would it be possible to center the effect? That way you wouldn't need to piece the image back together if part of it went of the canvas...
Posted Image
Take responsibility for your own intelligence. ;) -Rick Brewster