Jump to content

BoltBait

Administrator
  • Posts

    15,730
  • Joined

  • Last visited

  • Days Won

    405

Everything posted by BoltBait

  1. Like this: int MyInt = (int)MyDouble; You can see examples of this in the code I posted above. Look at the PreRender function where I'm calling some Math functions.
  2. Yes, the compiler is smart enough to precompute the results of the constant expression. Writing it out that way is just easier for us humans to understand what I'm doing. It is easy to verify by using ILSpy to decompile the resulting DLL:
  3. I agree... which is why I just rewrote the Posterize part. Now the colors are correct: // Name: Gradual Stripes // Submenu: Render // Author: BoltBait & Pratyush // Title: Gradual Stripes // Version: 2.0 // Desc: Draws stripes with gradual change in shades // Keywords: Stripes|Grayscale|Lines #region UICode PanSliderControl Amount1 = Pair.Create(-1.0,0.0); // Starting Point ColorWheelControl Amount2 = ColorBgra.FromBgr(0,0,0); // [Black] PanSliderControl Amount3 = Pair.Create(1.0,0.0); // Ending Point ColorWheelControl Amount4 = ColorBgra.FromBgr(255,255,255); // [White] IntSliderControl Amount5=16; // [2,64] Bands #endregion Surface wrk = null; Color[] palette = new Color[64]; protected override void OnDispose(bool disposing) { if (wrk != null) wrk.Dispose(); wrk = null; base.OnDispose(disposing); } Color FindNearestColor(Color color, Color[] palette, int palSize) { int minDistanceSquared = 255 * 255 + 255 * 255 + 255 * 255 + 1; byte bestIndex = 0; for (byte i = 0; i < palSize; i++) { int Rdiff = color.R - palette[i].R; int Gdiff = color.G - palette[i].G; int Bdiff = color.B - palette[i].B; int distanceSquared = Rdiff * Rdiff + Gdiff * Gdiff + Bdiff * Bdiff; if (distanceSquared < minDistanceSquared) { minDistanceSquared = distanceSquared; bestIndex = i; if (minDistanceSquared < 1) break; } } if (bestIndex == 0) return Amount2; if (bestIndex == palSize-1) return Amount4; return palette[bestIndex]; } void PreRender(Surface dst, Surface src) { if (wrk == null) wrk = new Surface(src.Size); int sw = (Amount5 + 1) * 2; Bitmap swatch = new Bitmap(sw,1); using (LinearGradientBrush Brush1 = new LinearGradientBrush(new Point(0,0),new Point(sw-2,0), Amount2, Amount4)) { using (Graphics g = Graphics.FromImage(swatch)) { g.FillRectangle(Brush1,0,0,sw,1); } } for (int i = 0; i < Amount5; i++) { palette[i] = swatch.GetPixel(i*2+1,0); } Rectangle selection = EnvironmentParameters.GetSelection(wrk.Bounds).GetBoundsInt(); int width = selection.Right - selection.Left; int height = selection.Bottom - selection.Top; int x1 = (int)Math.Round(((Amount1.First + 1) / 2) * width) + selection.Left; int y1 = (int)Math.Round(((Amount1.Second + 1) / 2) * height) + selection.Top; int x2 = (int)Math.Round(((Amount3.First + 1) / 2) * width) + selection.Left; int y2 = (int)Math.Round(((Amount3.Second + 1) / 2) * height) + selection.Top; Point p1 = new Point(x1,y1); Point p2 = new Point(x2,y2); if (!p1.Equals(p2)) { using (LinearGradientBrush Brush1 = new LinearGradientBrush(p1,p2, Amount2, Amount4)) { using (Graphics g = new RenderArgs(wrk).Graphics) { g.FillRectangle(Brush1,selection.Left,selection.Top,width,height); } } } } void Render(Surface dst, Surface src, Rectangle rect) { for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { if (IsCancelRequested) return; ColorBgra CurrentPixel = wrk[x,y]; CurrentPixel = FindNearestColor(CurrentPixel, palette, Amount5); dst[x,y] = CurrentPixel; } } } EDIT: I just rewrote it again. Now the stripes are the correct number and size.
  4. I agree, so I rewrote the posterize portion: <snip> I think you're going to like this version.
  5. It works perfectly. If I choose (16, 0.1, good quality) I get just the image I expect.
  6. Well, if that's how Posterize "works", I hate it. Has anyone written a better one? Or, should I start thinking of a better algorithm?
  7. With the same gradient, if I move the linked sliders to 2, I get 3 colors.
  8. In some instances, Adjustments > Posterize is rendering too many colors. In this example, I'm asking it to render 16 different colors, it is actually rendering 32. Maybe I just don't know how posterize is supposed to work. I just assumed with linked sliders and choosing 16, I'd get 16 colors. Is that wrong? If I render a gradient from black to white, posterize gives me exactly the number of colors I choose, 16.
  9. @Pratyush you've written your plugin in a very strange way. I'm not sure about your looping structure... and basing your calculations on the size of the rectangle sent into the Render function... Anyway, I've written a well behaved version of your plugin. Use it if you like. <snip> It will render your gradient to any angle and it respects the current selection. Plus, it is super fast (that is, the UI is very responsive). It will also repeat the pattern if you pull the nubs [+] in from the edges. Enjoy.
  10. For the way this plugin is written, it would be really, really hard. If you want to simulate the same thing, just draw a gradient the angle you want (be sure to disable anti-aliasing) then run Adjustments > Posterize.
  11. Yes, changing the style updates the defaults to help new users pick the right values when choosing certain color combinations (like Hue). I recommend always starting entering data by starting at the top and working your way down the screen. That way you start with the style. Yup, that's annoying and I need to fix it. Basically, there is code in there that keeps the 3 values (min, default, max) in sync so that the combination is always valid. I need to make it a little less aggressive. Yeah, I know. Like I said, I do need to fix that. In order to type a negative number, change the 0 to 2 first. Then put the minus sign in. EDIT: I have fixed #2 and #3 for the next release. Instead of triggering the normalization on "text change", I'm now doing it on "before leave". So, it normalizes the fields when you exit one of them, not while you're typing.
  12. If you make the main window so narrow that the Finalize button is in the overflow, it doesn't work. Other buttons seemed to work when in the overflow list, just not the Finalize button. I tried finalizing text and a gradient and neither one worked--clicking the button does nothing. (I'm getting a jump on next year's Most Obscure Bug competition.)
  13. I'm wondering of your virus scanner is blocking access to that directory.
  14. I coded a fix for this. It will be in the next release of CodeLab. Basically, it will ignore any commented out lines. If you use the UIBuilder, when you click OK, those lines will be deleted.
  15. Once you finalize text, it becomes part of the image and can't be edited again as text.
  16. Try updating again. The most current version is 4.0.21
  17. Just a thought... are you trying to save to a regular directory on your computer (like My Documents or Desktop) or are you trying to save some place special like One Drive?
  18. Buy the mouse that feels most comfortable in your hand. After all, you will be holding it often. My hands are fairly small, so those gaming mice are way too big for me. I like the standard Logitech M100 which is just the right size for me and costs about 8 bucks.
  19. Sorry, I run Windows 10 and my mouse settings screen looks like this: Maybe it's time to upgrade?
  20. One more thing to check... Click your start menu button and type "Settings" press enter. On the settings screen, search for "Mouse" settings. On the mouse settings screen, look to see if the following option is set: "Scroll inactive windows when I hover over them". It should be "On". When I change that setting to "Off", I get the same behavior you're experiencing.
×
×
  • Create New...