SignorOmbra Posted June 14, 2021 Share Posted June 14, 2021 Hi, right now I'm making a plugin that needs to clone and scale an image multiple times by a pixel or so. Doing it without CodeLab, and I have no clue about the math behind that. If anybody could help, that would be great! Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted June 14, 2021 Share Posted June 14, 2021 Are you aware a plugin can not change the size of the canvas? 1 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
SignorOmbra Posted June 14, 2021 Author Share Posted June 14, 2021 1 minute ago, toe_head2001 said: Are you aware a plugin can not change the size of the canvas? Yes, I am. I'm attempting to "zoom out" an image, similar to the rotate/zoom effect. (Minus the rotation, of course). Would that be possible? Quote Link to comment Share on other sites More sharing options...
Reptillian Posted June 14, 2021 Share Posted June 14, 2021 (edited) Here's the codelab code for starters. You can use 1/zoom instead for zoom out. #region UICode DoubleSliderControl zoom = 4; // [1,10] Zoom Level #endregion void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need Rectangle selection = EnvironmentParameters.SelectionBounds; double cx = (src.Width - 1) / 2; double cy = (src.Height - 1) / 2; double ix,iy,nx,ny,tx,ty; int fx,fy; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { ix=(double)(x)-cx; iy=(double)(y)-cy; nx=ix*zoom; ny=iy*zoom; tx=nx-ix; ty=ny-iy; fx=Math.Min(Math.Max(x+(int)(tx),0),src.Width - 1 ); fy=Math.Min(Math.Max(y+(int)(ty),0),src.Height - 1 ); dst[x,y] = src[fx,fy]; } } } Edited June 14, 2021 by Reptillian 1 Quote G'MIC Filter Developer I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me. Link to comment Share on other sites More sharing options...
SignorOmbra Posted June 14, 2021 Author Share Posted June 14, 2021 Alright, tried implementing it in a for loop... Now it's colliding with itself! Help is appreciated. (Don't mind the other variables, I'm also making a "trail" effect with some of pyrochild's code as reference.) protected unsafe override void OnRender(Rectangle[] renderRects, int startIndex, int length) { Surface destination = DstArgs.Surface; Surface source = SrcArgs.Surface; Rectangle bounds = SrcArgs.Bounds; Surface customSurface = new Surface(source.Width, source.Height); customSurface.FitSurface(ResamplingAlgorithm.Fant, source); destination.CopySurface(source, renderRects); double cx = (source.Width - 1) / 2; double cy = (source.Height - 1) / 2; double ix, iy, nx, ny, tx, ty; int fx, fy; foreach (Rectangle rect in renderRects) { for ( double xOffset = 0, yOffset = 0; xOffset <= DistanceX && yOffset <= DistanceY; xOffset += SpacingX, yOffset += SpacingY ) { if (IsCancelRequested) return; float xDirectionOffset = -(float)xOffset * DirectionX; float yDirectionOffset = -(float)yOffset * DirectionY; for (int y = rect.Top; y < rect.Bottom; ++y) { float sourceY = y + yDirectionOffset; if (!(bounds.Top <= sourceY && sourceY < bounds.Bottom)) { continue; } ColorBgra* destinationPoint = destination.GetPointAddressUnchecked(rect.Left, y); ColorBgra* sourcePoint = source.GetPointAddressUnchecked(0, (int)sourceY); for (int x = rect.Left; x < rect.Right; ++x) { double zoom = 1 + ((x + y) * 0.001); ix = (double)(x) - cx; iy = (double)(y) - cy; nx = ix * zoom; ny = iy * zoom; tx = nx - ix; ty = ny - iy; fx = Math.Min(Math.Max(x + (int)(tx), 0), destination.Width - 1); fy = Math.Min(Math.Max(y + (int)(ty), 0), destination.Height - 1); destination[x, y] = destination[fx, fy]; } } } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.