public override unsafe ColorBgra Apply(ColorBgra color, int area, int *hb, int *hg, int *hr, int *ha) { ColorBgra normalized = GetPercentileOfColor(color, area, hb, hg, hr, ha); double lerp = Strength * (1 - 0.75 * color.GetIntensity()); return(ColorBgra.Lerp(color, normalized, lerp)); }
IntSliderControl m_V = 100; // [0,100] {!m_UseRgbPicker} Value #endregion void Render(Surface dst, Surface src, Rectangle rect) { HsvColor hsv = new HsvColor(m_H, m_S, m_V); var bgra = m_UseRgbPicker ? m_RgbColor : ColorBgra.FromColor(hsv.ToColor()); var white = ColorBgra.FromColor(Color.White); var colorToUse = ColorBgra.Lerp(white, bgra, m_TintStrength); ColorBgra currentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) { return; } for (int x = rect.Left; x < rect.Right; x++) { currentPixel = src[x, y]; byte r = currentPixel.R; byte g = currentPixel.G; byte b = currentPixel.B; currentPixel.R = (byte)((int)r * (int)colorToUse.R / 255); currentPixel.G = (byte)((int)g * (int)colorToUse.G / 255); currentPixel.B = (byte)((int)b * (int)colorToUse.B / 255); dst[x, y] = currentPixel; } } }
private unsafe void RenderClouds(Surface surface, Rectangle rect) { ColorBgra colorFrom = EnvironmentParameters.PrimaryColor; ColorBgra colorTo = EnvironmentParameters.SecondaryColor; int w = surface.Width; int h = surface.Height; for (int y = rect.Top; y < rect.Bottom; ++y) { ColorBgra *ptr = surface.GetPointAddressUnchecked(rect.Left, y); int dy = 2 * y - h; for (int x = rect.Left; x < rect.Right; ++x) { int dx = 2 * x - w; double val = 0; double mult = 1; int div = this.scale; for (int i = 0; i < 12 && mult > 0.03 && div > 0; ++i) { double dxr = 65536 + (double)dx / (double)div; double dyr = 65536 + (double)dy / (double)div; int dxd = (int)dxr; int dyd = (int)dyr; dxr -= dxd; dyr -= dyd; double noise = Noise( unchecked ((byte)dxd), unchecked ((byte)dyd), dxr, //(double)dxr / div, dyr, //(double)dyr / div, (byte)(seed ^ i)); val += noise * mult; div /= 2; mult *= this.power; } *ptr = ColorBgra.Lerp(colorFrom, colorTo, (val + 1) / 2); ++ptr; } } }
private unsafe static void RenderClouds(ISurface surface, Rectangle rect, int scale, byte seed, double power, ColorBgra colorFrom, ColorBgra colorTo) { int w = surface.Width; int h = surface.Height; for (int y = rect.Top; y <= rect.Bottom; ++y) { ColorBgra *ptr = surface.GetPointAddress(rect.Left, y); int dy = 2 * y - h; for (int x = rect.Left; x <= rect.Right; ++x) { int dx = 2 * x - w; double val = 0; double mult = 1; int div = scale; for (int i = 0; i < 12 && mult > 0.03 && div > 0; ++i) { double dxr = 65536 + (double)dx / (double)div; double dyr = 65536 + (double)dy / (double)div; int dxd = (int)dxr; int dyd = (int)dyr; dxr -= dxd; dyr -= dyd; double noise = Noise( unchecked ((byte)dxd), unchecked ((byte)dyd), dxr, //(double)dxr / div, dyr, //(double)dyr / div, (byte)(seed ^ i)); val += noise * mult; div /= 2; mult *= power; } *ptr = ColorBgra.Lerp(colorFrom, colorTo, (val + 1) / 2); ++ptr; } } }
public unsafe override ColorBgra Apply(ColorBgra src, int area, int *hb, int *hg, int *hr, int *ha) { ColorBgra median = GetPercentile(50, area, hb, hg, hr, ha); return(ColorBgra.Lerp(src, median, -0.5f)); }
private void DrawGradient(Graphics g) { Rectangle gradientRect; // draw gradient gradientRect = ClientRectangle; gradientRect.Inflate(-triangleHalfLength, -triangleSize + 3); if (this.gradient != null && gradientRect.Width > 1 && gradientRect.Height > 1) { Surface gradientSurface = new Surface(gradientRect.Size); using (RenderArgs ra = new RenderArgs(gradientSurface)) { for (int y = 0; y < gradientSurface.Height; ++y) { for (int x = 0; x < gradientSurface.Width; ++x) { float f = x * (gradient.Length - 1) / (float)gradientRect.Width; int i = (int)f; byte v = (byte)((((x ^ y) & 4) * 16) + 191); ColorBgra checker = ColorBgra.FromUInt32((uint)v | (uint)(v << 8) | (uint)(v << 16) | 0xff000000); ColorBgra c = ColorBgra.Lerp(gradient[i], gradient[i + 1], f - i); gradientSurface[x, y] = UserBlendOps.NormalBlendOp.ApplyStatic(checker, c); } } g.DrawImage(ra.Bitmap, gradientRect, ra.Bounds, GraphicsUnit.Pixel); } gradientSurface.Dispose(); } // draw value triangles Brush brush; Pen pen; if (highlight) { brush = Brushes.Blue; pen = Pens.White; } else { brush = this.Enabled ? Brushes.Black : Brushes.Gray; pen = Pens.Gray; } g.SmoothingMode = SmoothingMode.AntiAlias; Point a1; Point b1; Point c1; Point a2; Point b2; Point c2; int pos = gradientRect.Left + (int)(gradientRect.Width * value + 0.5); a1 = new Point(pos - triangleHalfLength, 0); b1 = new Point(pos, triangleSize - 1); c1 = new Point(pos + triangleHalfLength, 0); a2 = new Point(a1.X, Height - 1 - a1.Y); b2 = new Point(b1.X, Height - 1 - b1.Y); c2 = new Point(c1.X, Height - 1 - c1.Y); if (this.drawNearNub) { g.FillPolygon(brush, new Point[] { a1, b1, c1, a1 }); } if (this.drawFarNub) { g.FillPolygon(brush, new Point[] { a2, b2, c2, a2 }); } if (this.drawNearNub) { g.DrawPolygon(pen, new Point[] { a1, b1, c1, a1 }); } if (this.drawFarNub) { g.DrawPolygon(pen, new Point[] { a2, b2, c2, a2 }); } }