private void SetColorGradientMinMaxColorsHsv(int h, int s, int v) { Color[] hueColors = new Color[361]; for (int newH = 0; newH <= 360; ++newH) { HsvColor hsv = new HsvColor(newH, 100, 100); hueColors[newH] = hsv.ToColor(); } hueGradientControl.CustomGradient = hueColors; Color[] satColors = new Color[101]; for (int newS = 0; newS <= 100; ++newS) { HsvColor hsv = new HsvColor(h, newS, v); satColors[newS] = hsv.ToColor(); } saturationGradientControl.CustomGradient = satColors; valueGradientControl.MaxColor = new HsvColor(h, s, 100).ToColor(); valueGradientControl.MinColor = new HsvColor(h, s, 0).ToColor(); }
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; } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); // Grab all values SerializedProperty hue = property.FindPropertyRelative("hue"); SerializedProperty saturation = property.FindPropertyRelative("saturation"); SerializedProperty value = property.FindPropertyRelative("value"); SerializedProperty alpha = property.FindPropertyRelative("alpha"); // Convert these values into a color HsvColor color = new HsvColor(hue.floatValue, saturation.floatValue, value.floatValue, alpha.floatValue); Color convertedColor = color.ToColor(); // Draw the color field convertedColor = EditorGUI.ColorField(position, label, convertedColor); // Convert the color back to the values color = HsvColor.FromColor(convertedColor); hue.floatValue = color.Hue; saturation.floatValue = color.Saturation; value.floatValue = color.Value; alpha.floatValue = color.Alpha; // End the property EditorGUI.EndProperty(); }
protected override unsafe void ProcessFilter(UnmanagedImage image) { //IntPtr scan0 = image.Scan0; //int stride = image.Stride; int offset = (image.Stride - image.Width * 3); int factor = 100 / this.Value; byte *ptr = (byte *)image.ImageData.ToPointer(); for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++, ptr += 3) { Color color = Color.FromArgb(ptr[RGB.R], ptr[RGB.G], ptr[RGB.B]); HsvColor hsv = HsvColor.FromColor(color); // Posterize value hsv.Value -= (hsv.Value % factor); // Convert back to RGB color = hsv.ToColor(); ptr[RGB.R] = (byte)color.R; ptr[RGB.G] = (byte)color.G; ptr[RGB.B] = (byte)color.B; } ptr += offset; } }
private void HInput_TextChanged(object sender, TextChangedEventArgs e) { if (isInputHText) { isInputHText = false; return; } float f; if (float.TryParse(HInput.Text, out f)) { float rH = Math.Min(359, Math.Max(0, f * 359.0f)); hsv.H = rH; current = hsv.ToColor(); UpdateSliders(); UpdateTextFields(); UpdatePreview(); RedrawSatVal(); } }
protected override void OnRender(Rectangle[] renderRects, int startIndex, int length) { float factor = 255 / (this._upperThres - this._lowerThres); bool interpolate = this._color != this._color2; Pair <int, int> hues = this.GetHues(this._hueDirection); double fHue = (hues.Second - hues.First) / MathUtil.PIOver2; double fSat = (this._color2.Saturation - this._color.Saturation) / MathUtil.PIOver2; double fVal = (this._color2.Value - this._color.Value) / MathUtil.PIOver2; for (int i = startIndex; i < startIndex + length; i++) { Rectangle rect = renderRects[i]; //Pair<float, float>[,] evs = this._cachedEVs.GetValues(rect); TensorCharacteristics[,] charact = this._cachedCharacteristics.GetValues(rect); for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { float ev; TensorCharacteristics tChar = charact[x - rect.Left, y - rect.Top]; if (this._mode == Modes.Edge) { ev = tChar.MaxEigenvalue; } else { ev = tChar.MinEigenvalue; } ev -= this._lowerThres; ev *= factor; ev = Math.Max(0, Math.Min(255, ev)); HsvColor color = this._color; if (ev > 0 && interpolate) { double ang = Utils.NormalizePeriodic(tChar.DominantDirection - this._angle, Math.PI); if (ang > MathUtil.PIOver2) { ang = Math.PI - ang; } color.Hue = (int)Utils.NormalizePeriodic(ang * fHue + hues.First, 360); color.Saturation = (int)Math.Max(0, Math.Min(100, ang * fSat + color.Saturation)); color.Value = (int)Math.Max(0, Math.Min(100, ang * fVal + color.Value)); } var c = ColorBgra.FromColor(color.ToColor()); this.DstArgs.Surface[x, y] = c.NewAlpha((byte)ev); } } } }
private void SetPropertyValueFromHsv(HsvColor hsv) { UI.SuspendControlPainting(this); try { RgbColor rgb = hsv.ToRgb(); SetPropertyValueFromRgb(rgb.Red, rgb.Green, rgb.Blue); if (this.hsvColorWheel.HsvColor != hsv) { this.hsvColorWheel.HsvColor = hsv; } if (this.valueSlider.Value != (hsv.Value * 255) / 100) { this.valueSlider.Value = (hsv.Value * 255) / 100; } if (this.saturationSlider.Value != (hsv.Saturation * 255) / 100) { this.saturationSlider.Value = (hsv.Saturation * 255) / 100; } HsvColor hsvValMin = hsv; hsvValMin.Value = 0; HsvColor hsvValMax = hsv; hsvValMax.Value = 100; this.valueSlider.MinColor = hsvValMin.ToColor(); this.valueSlider.MaxColor = hsvValMax.ToColor(); HsvColor hsvSatMin = hsv; hsvSatMin.Saturation = 0; HsvColor hsvSatMax = hsv; hsvSatMax.Saturation = 100; this.saturationSlider.MinColor = hsvSatMin.ToColor(); this.saturationSlider.MaxColor = hsvSatMax.ToColor(); } finally { UI.ResumeControlPainting(this); if (UI.IsControlPaintingEnabled(this)) { Refresh(); } } }
void RedrawHue() { for (int y = 0; y < hueBitmap.Height; y++) { float f = y / (float)hueBitmap.Height; float h = f * 359; HsvColor v = new HsvColor(h, 1, 1); D.Color c = v.ToColor(); for (int x = 0; x < hueBitmap.Width; x++) { hueBitmap.SetPixel(x, y, c.R, c.G, c.B, 255); } } HueSelector.Source = hueBitmap.ToImageSource(); }
void RedrawSatVal() { for (int y = 0; y < svBitmap.Height; y++) { for (int x = 0; x < svBitmap.Width; x++) { float sf = x / (float)svBitmap.Width; float sv = 1.0f - y / (float)svBitmap.Height; HsvColor v = new HsvColor(hsv.H, sf, sv); D.Color c = v.ToColor(); svBitmap.SetPixel(x, y, c.R, c.G, c.B, 255); } } SaturationValueSelector.Source = svBitmap.ToImageSource(); }
private void SetPropertyValueFromRgb(int red, int green, int blue) { UI.SuspendControlPainting(this); try { if (this.redNud.Value != red) { this.redNud.Value = red; } if (this.greenNud.Value != green) { this.greenNud.Value = green; } if (this.blueNud.Value != blue) { this.blueNud.Value = blue; } if (this.inOnPropertyValueChanged == 0) { int newValue = (red << 16) | (green << 8) | blue; if (Property.Value != newValue) { Property.Value = newValue; } } RgbColor rgb = new RgbColor(red, green, blue); HsvColor hsv = rgb.ToHsv(); this.hsvColorWheel.HsvColor = hsv; this.valueSlider.Value = (hsv.Value * 255) / 100; this.saturationSlider.Value = (hsv.Saturation * 255) / 100; HsvColor hsvValMin = hsv; hsvValMin.Value = 0; HsvColor hsvValMax = hsv; hsvValMax.Value = 100; this.valueSlider.MinColor = hsvValMin.ToColor(); this.valueSlider.MaxColor = hsvValMax.ToColor(); HsvColor hsvSatMin = hsv; hsvSatMin.Saturation = 0; HsvColor hsvSatMax = hsv; hsvSatMax.Saturation = 100; this.saturationSlider.MinColor = hsvSatMin.ToColor(); this.saturationSlider.MaxColor = hsvSatMax.ToColor(); } finally { UI.ResumeControlPainting(this); if (UI.IsControlPaintingEnabled(this)) { Refresh(); } } }
public override void Draw() { base.Draw(); _secondaryColor.H += TimeKeeper.Global.Time(360 / 4f); if (_secondaryColor.H >= 360f) { _secondaryColor.H -= 360; } Debug.WriteLine(_secondaryColor.H); // This code shows how to draw shapes using static methods and instanced objects. var startingPosition = new Vector2(100, 100); var position = startingPosition; var spacing = 100; // Circles. GraphicsMgr.CurrentColor = _mainColor; // Setting current color. It's active for all shapes and sprites. CircleShape.Draw(position, 24, false); // Filled circle. GraphicsMgr.CurrentColor = _secondaryColor.ToColor(); CircleShape.Draw(position, 32, true); // Outline. position += Vector2.UnitX * spacing; CircleShape.CircleVerticesCount = 8; // Changing the amount of circle vertices. GraphicsMgr.CurrentColor = _mainColor; CircleShape.Draw(position, 24, false); GraphicsMgr.CurrentColor = _secondaryColor.ToColor(); CircleShape.Draw(position, 32, true); CircleShape.CircleVerticesCount = 32; // Circles. position += Vector2.UnitY * spacing; position.X = startingPosition.X; // Rectangles. // You can draw rectangle using its top left and bottom right point... RectangleShape.Draw(position - Vector2.One * 24, position + Vector2.One * 24, false); GraphicsMgr.CurrentColor = _mainColor; // ...or its center position and size! RectangleShape.DrawBySize(position, Vector2.One * 64, true); position += Vector2.UnitX * spacing; RectangleShape.Draw( // We can also manually set colors for each vertex. position - Vector2.One * 24, position + Vector2.One * 24, false, _mainColor, _mainColor, _mainColor, _secondaryColor.ToColor() ); RectangleShape.DrawBySize( position, Vector2.One * 64, true, _mainColor, _secondaryColor.ToColor(), _mainColor, _mainColor ); // Rectangles. position += Vector2.UnitY * spacing; position.X = startingPosition.X; // Triangles. _triangle.Position = position; _triangle.Draw(); // Drawing an instantiated triangle. GraphicsMgr.CurrentColor = _mainColor; TriangleShape.Draw( position + new Vector2(-24, -24), position + new Vector2(24, -24), position + new Vector2(24, 24), false ); // Be aware of culling. This triangle, for example, will be culled. // You can disable culling, if you don't want to deal with it. TriangleShape.Draw(new Vector2(-24, -24), new Vector2(24, 24), new Vector2(24, -24), false); // Triangles. // Lines. position += Vector2.UnitX * spacing; LineShape.Draw(position - Vector2.One * 24, position + Vector2.One * 24); position += Vector2.UnitX * spacing / 2f; ThickLineShape.Draw(position - Vector2.One * 24, position + Vector2.One * 24, 5); // Lines. }
private void RenderSelectedLineBackground(IntPtr hdc, RendererState rs) { var rect = new RECT { left = rs.TextRectangle.Left - this.TextView.ScrollHost.ScrollPosH, right = int.MaxValue, top = rs.TextRectangle.Top + rs.Y - rs.ViewportY, bottom = rs.TextRectangle.Top + rs.Y + rs.LineHeight - rs.ViewportY }; if (this.TextView.BackgroundImage == null) { SafeNativeMethods.FillRect(hdc, ref rect, this._brushCurrentLine.DangerousGetHandle()); } else { // Paint using GDI+ if a background image is used, for the sake of using transparency. using (var g = Graphics.FromHdc(hdc)) { HsvColor c = HsvColor.FromColor(this.TextView.LineHighlightColor); var alpha = (int)(255 - (255 * ((100 - c.Saturation) / 100d))); c.Saturation = 100; using (var currentLineBrush = new SolidBrush(Color.FromArgb(alpha, c.ToColor()))) { g.FillRectangle(currentLineBrush, rect.left, rect.top, this.TextView.ClientSize.Width, rs.LineHeight); } } } }