ReMake Posted October 15, 2023 Posted October 15, 2023 (edited) Now that we have paint.net 5.0.11, CodeLab v6.10 and @BoltBait's tutorials, it's time to update the outdated plugins. My first attempt is to convert the classic Center Lines effect into a GPU effect. The Line Width control has been added to the new effect. Below is the CodeLab script of the new plugin. Spoiler // Name:CenterLines // Submenu:Tools // Author:ReMake // Title:Center Lines // Version:2.0 // Desc:Drawing auxiliary center lines // Keywords:paint.net|effect|center|lines // URL: // Help: #region UICode IntSliderControl lineWidth = 1; // [1,100] Line Width ListBoxControl color = 0; // Color|Primary|Secondary|Custom ColorWheelControl custom = ColorBgra.FromBgra(0, 0, 255, 255); // [Red?] {color} PanSliderControl position = new Vector2Double(0.000, 0.000); // Position #endregion protected override unsafe void OnDraw(IDeviceContext deviceContext) { deviceContext.DrawImage(Environment.SourceImage); // preserve background RectInt32 selection = Environment.Selection.RenderBounds; ColorBgra32 primaryColor = Environment.PrimaryColor; ColorBgra32 secondaryColor = Environment.SecondaryColor; ColorBgra32 lineColor = ColorBgra.Red; // converts the PanSlider values to between 0 and 1 double posX = (position.X + 1) / 2; double posY = (position.Y + 1) / 2; // shift of lines by 1 pixel to the right/down if posX/posY = 0 int shiftX = posX == 0 ? 1 : 0; int shiftY = posY == 0 ? 1 : 0; // converting posX/posY to actual pixel coordinates int centerX = (int)Math.Round(selection.Width * posX) + selection.Left + shiftX; int centerY = (int)Math.Round(selection.Height * posY) + selection.Top + shiftY; switch (color) { case 0: lineColor = primaryColor; break; case 1: lineColor = secondaryColor; break; case 2: lineColor = custom; break; } ISolidColorBrush brush = deviceContext.CreateSolidColorBrush(lineColor); deviceContext.DrawLine( centerX, selection.Top, centerX, selection.Bottom, brush, lineWidth); deviceContext.DrawLine( selection.Left, centerY, selection.Right, centerY, brush, lineWidth); } I am interested in what range the Line Width control should have and is there a need to use a transparency change to control Custom Color? I would also like to get suggestions and comments on code optimization. Edited October 16, 2023 by ReMake Edited the script after clarifications by Rick Brewster 2 Quote
Solution Rick Brewster Posted October 16, 2023 Solution Posted October 16, 2023 Performance looks fine. You don't need to create that stroke style -- you can just pass null. That's the same as creating/using the default stroke style. 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
ReMake Posted October 16, 2023 Author Posted October 16, 2023 @Rick Brewster, thanks for the clarification. I edited the code above. Quote
Rick Brewster Posted October 16, 2023 Posted October 16, 2023 Actually I don't think you even need to pass null -- the default value for that parameter should already be null. DrawLine(x0, y0, x1, y1, brush, strokeWidth); // no need to pass strokeStyle at all 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
AndrewDavid Posted October 16, 2023 Posted October 16, 2023 @ReMake I plan on following you as much as I can understanding the new GPU benefits. When I paste your code into my Codelab - I receive this error What am I not doing? Quote
BoltBait Posted October 16, 2023 Posted October 16, 2023 20 minutes ago, AndrewDavid said: @ReMake I plan on following you as much as I can understanding the new GPU benefits. When I paste your code into my Codelab - I receive this error What am I not doing? @ReMake created a new GPU Drawing effect. You're trying to put that code into a new GPU Image effect. Had you saved that code into a .cs file and did a File > Open in CodeLab, it would have know the type and loaded it into the proper window type for you. Or, had you done a File > New > GPU Drawing Effect before pasting in your code, it would have worked properly. 1 1 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
AndrewDavid Posted October 16, 2023 Posted October 16, 2023 Request @ReMake Now that I see it working - I would like to include it in my next Plugin Template release. The one I just posted is only the UI. No working script. If approved I can go on to a Chapter 2 of my plugin template. Request @Rick Brewster Can you approve the use of your source code that resides in my Repository to create templates of 2 specific type of plugins to identify the different types of effects. Yours is the only code I have seen that does not generate that WindowsBase error in VS2022. I think 4 templates would be a great asset for anyone coding in VS2022. I think I can do Classic on my own. I did publish one, and I just remembered how I did it. Quick while everything is in sync. I know how fast things change. Quote
ReMake Posted October 16, 2023 Author Posted October 16, 2023 1 hour ago, Rick Brewster said: DrawLine(x0, y0, x1, y1, brush, strokeWidth); // no need to pass strokeStyle at all Yes, it works. I edited the script again. Thanks again, @Rick Brewster. Quote
ReMake Posted October 16, 2023 Author Posted October 16, 2023 19 minutes ago, AndrewDavid said: Request @ReMake The above script is open source. You can use it as you see fit. I created this effect following the tutorial by @BoltBait. @Rick Brewster's explanations relate to optimizing the code for the Center Lines effect. @BoltBait's script assumes the possible use of the Line Style and is more suitable for the template. Quote
AndrewDavid Posted October 16, 2023 Posted October 16, 2023 @ReMake the script @BoltBait provides does not allow color change, size width or position. (Baby Steps) That is why I want to use yours. I tried on my own to figure it how to add the controls myself - now I have the answer but feel guilty using your script without your approval. Think of the code your script contains that his does not. That would be the next step in a tutorial - but I don't think he wants to go that far. That's the code I am referring to. Quote
BoltBait Posted October 16, 2023 Posted October 16, 2023 6 minutes ago, AndrewDavid said: the script @BoltBait provides does not allow color change, size width Have you read ALL the new tutorials? Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
AndrewDavid Posted October 16, 2023 Posted October 16, 2023 @BoltBait and your unfinished ones. Drawing Text in a GPU Drawing Plugin. Followed your directions but it generates an error. I am trying to use the API references to figure it out without asking you. Spoiler There is no argument given that corresponds to the required parameter 'serviceType' of 'IServiceProvider.GetService(Type)' I know the API's do not provide examples, but I should be able to find the reference needed to correct this. AM I close? https://paintdotnet.github.io/apidocs/api/PaintDotNet.DirectWrite.DirectWriteFactory.CreateRef.html Quote
BoltBait Posted October 16, 2023 Posted October 16, 2023 13 minutes ago, AndrewDavid said: @BoltBait and your unfinished ones. Well, I'm constantly revising them. You may want to go back and review all of them. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
ReMake Posted October 17, 2023 Author Posted October 17, 2023 @AndrewDavid, you can freely use the above script. 1 Quote
Rick Brewster Posted October 17, 2023 Posted October 17, 2023 19 hours ago, AndrewDavid said: Can you approve the use of your source code that resides in my Repository If it's from here then the license is MIT. 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
ReMake Posted November 18, 2023 Author Posted November 18, 2023 My second attempt is to convert the classic Color Sketch effect into a GPU effect. Applied Bokeh blur effect instead of Gaussian blur. In my opinion, this gave more expressiveness to the final image. Below is the CodeLab script of the new plugin. Spoiler // Name:Color Sketch // Submenu:Artistic // Author:ReMake // Title:Color Sketch // Version:1.2 // Desc:Paint.net effect that simulates a sketch with colored pencils // Keywords:paint.net|effect|color|sketch // URL:http://www.getpaint.net/redirect/plugins.html // Help: #region UICode IntSliderControl size = 3; // [1,20] Pencil tip size IntSliderControl range = 0; // [-20,20] Range #endregion protected override IDeviceImage OnCreateOutput(IDeviceContext deviceContext) { BokehBlurEffect blurEffect = new (deviceContext); blurEffect.Properties.Input.Set(Environment.SourceImage); blurEffect.Properties.EdgeMode.SetValue(BokehBlurEdgeMode.Clamp); blurEffect.Properties.Radius.SetValue(size + 1f); float amount = range / 100f; PdnBrightnessContrastEffect bacEffect = new (deviceContext); bacEffect.Properties.Input.Set(blurEffect); bacEffect.Properties.Brightness.SetValue(amount); bacEffect.Properties.Contrast.SetValue(-amount); InvertEffect invertEffect = new (deviceContext); invertEffect.Properties.Input.Set(bacEffect); BlendEffect blendEffect = new (deviceContext); blendEffect.Properties.Destination.Set(Environment.SourceImage); blendEffect.Properties.Source.Set(invertEffect); blendEffect.Properties.Mode.SetValue(BlendMode.ColorDodge); return blendEffect; } Any criticism, suggestions and comments on code optimization. 1 Quote
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.