private static bool SimilarColors(Color colorOne, Color colorTwo) { if (Math.Abs(colorOne.GetHue()-colorTwo.GetHue()) <= 36) { //Console.WriteLine("Hue"); return true; } if (Math.Abs(colorOne.GetBrightness()-colorTwo.GetBrightness()) <= .1) { //Console.WriteLine("Hue"); return true; } if (Math.Abs(colorOne.GetSaturation()-colorTwo.GetSaturation()) <= .1) { //Console.WriteLine("Hue"); return true; } return false; }
public static Color Interpolate(Color c1, Color c2, float pct) { if (pct < 0) { pct = 0; } else if (pct > 1) { pct = 1; } var qct = 1 - pct; var h = c1.GetHue() * qct + c2.GetHue() * pct; var s = c1.GetSaturation() * qct + c2.GetSaturation() * pct; var l = c1.GetBrightness() * qct + c2.GetBrightness() * pct; var a = c1.A * qct + c2.A * pct; return(hslToColor(h / 360f, s, l, a)); }
protected override Color calculateNewPixelColor(Bitmap sourceImage, int x, int y) { if (maxBrightness == -1) { calculateBrightness(sourceImage); } Color sourceColor = sourceImage.GetPixel(x, y); int brightnessChange = (int)((sourceColor.GetBrightness() - minBrightness) * (255 / (maxBrightness - minBrightness))); Color resultColor = Color.FromArgb( Clamp(sourceColor.R + brightnessChange, 0, 255), Clamp(sourceColor.G + brightnessChange, 0, 255), Clamp(sourceColor.B + brightnessChange, 0, 255)); return(resultColor); }
private void SetColor(Color color) { this.BackColor = color; this.DataNote.BackColor = color; this.Title.BackColor = color; this.ColorPickerBtn.BackColor = color; if (color.GetBrightness() > 0.5f) { this.Title.ForeColor = Color.Black; this.DataNote.ForeColor = Color.Black; } else { this.Title.ForeColor = Color.White; this.DataNote.ForeColor = Color.White; } UpdateNote(); }
/// <summary> /// Draws the reversible frame with the given background color for the specified control rectangle. /// </summary> /// <param name="g">The graphics object.</param> /// <param name="backgroundColor">Color of the background.</param> /// <param name="rectangle">The rectangle.</param> public static void Draw(Graphics g, Color backgroundColor, Rectangle rectangle) { RasterOperation mode; Color alternateColor; if (backgroundColor.GetBrightness() < 0.5) { mode = RasterOperation.NOTXORPEN; alternateColor = Color.White; } else { mode = RasterOperation.XORPEN; alternateColor = Color.Black; } var hdc = g.GetHdc(); try { IntPtr pen = CreatePen((int)PenStyle.Dot, 1, ColorTranslator.ToWin32(backgroundColor)); int previousMode = SetROP2(new HandleRef(null, hdc), (int)mode); IntPtr previousBrush = SelectObject(new HandleRef(null, hdc), new HandleRef(null, GetStockObject((int)StockObject.NullBrush))); IntPtr previousPen = SelectObject(new HandleRef(null, hdc), new HandleRef(null, pen)); SetBkColor(new HandleRef(null, hdc), ColorTranslator.ToWin32(alternateColor)); Rectangle(new HandleRef(null, hdc), rectangle.X, rectangle.Y, rectangle.Right, rectangle.Bottom); SetROP2(new HandleRef(null, hdc), previousMode); SelectObject(new HandleRef(null, hdc), new HandleRef(null, previousBrush)); SelectObject(new HandleRef(null, hdc), new HandleRef(null, previousPen)); if (pen != IntPtr.Zero) { DeleteObject(new HandleRef(null, pen)); } } finally { g.ReleaseHdc(); } }
public static Color Darken(this Color color, float percent) { float lighting = color.GetBrightness(); lighting -= lighting * percent; if (lighting > 1.0) { lighting = 1; } else if (lighting <= 0) { lighting = 0; } Color tintedColor = FromHsl(color.A, color.GetHue(), color.GetSaturation(), lighting); return(tintedColor); }
private void frmColorInfo_Load(object sender, EventArgs e) { string Info = ""; Info = Info + "R " + ColorInfo.R + "\r\n" + Info + "G " + ColorInfo.G + "\r\n" + Info + "B " + ColorInfo.B + "\r\n" + Info + "A " + ColorInfo.A + "\r\n" + Info + "Hue " + ColorInfo.GetHue().ToString() + "\r\n" + Info + "Saturation " + ColorInfo.GetSaturation().ToString() + "\r\n" + Info + "Brightness " + ColorInfo.GetBrightness().ToString() + "\r\n" + Info + "IsKnownColor " + ColorInfo.IsKnownColor.ToString() + "\r\n" + Info + "IsNamedColor " + ColorInfo.IsNamedColor.ToString() + "\r\n" + Info + "IsSystemColor " + ColorInfo.IsSystemColor.ToString() + "\r\n" + Info + "Name " + ColorInfo.Name; txtColor.Text = Info; lblColor.BackColor = ColorInfo; }
// Aqui quitamos el color ... lo dejamos en blanco y negro (El captcha) public static void qutarColor(Bitmap bm) { for (int x = 0; x < bm.Width; x++) { for (int y = 0; y < bm.Height; y++) { Color pix = bm.GetPixel(x, y); //Aqui puedes jugar con los valores del brillo yo he probado poco pero tu puedes cambiarlo if (pix.GetBrightness() > 0.870f) { bm.SetPixel(x, y, Color.White); } else { bm.SetPixel(x, y, Color.Black); } } } }
public override Boolean IsCloseEnough(Color color) { var brightness = color.GetBrightness(); if (base.IsCloseEnough(color)) { if (brightness > 0.42 && brightness < 0.5) { return(true); } else { Console.WriteLine(brightness); return(false); } } return(false); }
private Features getAvarages() { if (_featuresIsNotSet) { return(_features); } _featuresIsNotSet = true; if (_boundingRectIsNotSet) { _boundingRect = getBoundingBox(); } float resultR = 0, resultG = 0, resultB = 0, resultH = 0, resultS = 0, resultL = 0; int pointSize = 0; for (int i = BoundingRect.Left; i < BoundingRect.Right; i++) { for (int j = BoundingRect.Top; j < BoundingRect.Bottom; j++) { Color px = Image.GetPixel(i, j); if (px.R + px.G + px.B < MinRGB) { continue; } resultR += px.R; resultG += px.G; resultB += px.B; resultH += px.GetHue(); resultS += px.GetSaturation(); resultL += px.GetBrightness(); pointSize++; } } _features = new Features(); _features.AvarageR = resultR / pointSize; _features.AvarageG = resultG / pointSize; _features.AvarageB = resultB / pointSize; _features.AvarageH = resultH / pointSize; _features.AvarageS = resultS / pointSize; _features.AvarageL = resultL / pointSize; _features.Size = pointSize; return(_features); }
static unsafe void Main(string[] args) { // Get parameters Palette palIn = new Palette(args[0]); string strFileOut = args[1]; double dAlpha = Double.Parse(args[2]); // Create mapping byte[] ab = new byte[palIn.Length]; Palette palInHSB = new Palette(palIn.Length); for (int iclr = 0; iclr < palIn.Length; iclr++) { Color clr = palIn[iclr]; double h = clr.GetHue(); double s = clr.GetSaturation(); double l = clr.GetBrightness(); double r; double g; double b; MyHSLtoRGB(h, s, l * dAlpha, &r, &g, &b); Color clrShadow = Color.FromArgb((int)(r * 255.0), (int)(g * 255.0), (int)(b * 255.0)); ab[iclr] = (byte)palIn.FindClosestEntry(clrShadow); } // Write palette mapping Stream stm = new FileStream(strFileOut, FileMode.Create, FileAccess.Write, FileShare.None); BinaryWriter bwtr = new BinaryWriter(stm); bwtr.Write(ab); bwtr.Close(); #if false // Check it Palette palCheck = new Palette(palIn.Length); for (int iclr = 0; iclr < palIn.Length; iclr++) { palCheck[iclr] = palIn[ab[iclr]]; } palCheck.SaveJasc("shadow.pal"); #endif }
private void DrawReversibleFrame(IntPtr handle, Rectangle rectangle, Color backColor) { //Bug # 71547 <subhag> to make drag rect visible if any the dimensions of the control are 0 if (rectangle.Width == 0) { rectangle.Width = 5; } if (rectangle.Height == 0) { rectangle.Height = 5; } // Copy of ControlPaint.DrawReversibleFrame, see VSWhidbey 581670 // If ControlPaint ever gets overrloaded, we should replace the code below by calling it: // ControlPaint.DrawReversibleFrame(handle, rectangle, backColor, FrameStyle.Thick); // ------ Duplicate code---------------------------------------------------------- Gdi32.R2 rop2; Color graphicsColor; if (backColor.GetBrightness() < .5) { rop2 = Gdi32.R2.NOTXORPEN; graphicsColor = Color.White; } else { rop2 = Gdi32.R2.XORPEN; graphicsColor = Color.Black; } using var dc = new User32.GetDcScope(handle); using var pen = new Gdi32.ObjectScope(Gdi32.CreatePen(Gdi32.PS.SOLID, 2, ColorTranslator.ToWin32(backColor))); using var rop2Scope = new Gdi32.SetRop2Scope(dc, rop2); using var brushSelection = new Gdi32.SelectObjectScope(dc, Gdi32.GetStockObject(Gdi32.StockObject.NULL_BRUSH)); using var penSelection = new Gdi32.SelectObjectScope(dc, pen); Gdi32.SetBkColor(dc, ColorTranslator.ToWin32(graphicsColor)); Gdi32.Rectangle(dc, rectangle.X, rectangle.Y, rectangle.Right, rectangle.Bottom); // ------ Duplicate code---------------------------------------------------------- }
protected override void Callback() { memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(0, 0, 0, 0, s); memoryGraphics.Dispose(); double red = 0; double green = 0; double blue = 0; float brightness = 0.0F; int cntr = 0; varMutex.WaitOne(); for (int x = 0; x < activeScreen.Bounds.Width; x += xSkipper_) { for (int y = 0; y < activeScreen.Bounds.Height; y += ySkipper_) { Color pixel = memoryImage.GetPixel(x, y); brightness += pixel.GetBrightness(); red += pixel.R; green += pixel.G; blue += pixel.B; cntr++; } } varMutex.ReleaseMutex(); red /= cntr; green /= cntr; blue /= cntr; brightness /= cntr; red *= brightness * emphaser_; green *= brightness * emphaser_; blue *= brightness * emphaser_; lastRGB_.Set(red, green, blue); _rgbOutput.ShowRGB(lastRGB_); // Thread.Sleep(20); }
public static IDictionary <Zond, int> GetCrossCount(Bitmap bitmap, IEnumerable <Zond> zonds) { PointF ConvertToAbsolute(PointF point) => new PointF(point.X * (bitmap.Width - 1), point.Y * (bitmap.Height - 1)); var result = new Dictionary <Zond, int>(); foreach (Zond zond in zonds) { PointF absoluteStartPoint = ConvertToAbsolute(zond.StartPoint); PointF absoluteEndPoint = ConvertToAbsolute(zond.EndPoint); float diffX = absoluteEndPoint.X - absoluteStartPoint.X; float diffY = absoluteEndPoint.Y - absoluteStartPoint.Y; float length = (float)Math.Sqrt(diffX * diffX + diffY * diffY); int stepCount = (int)Math.Ceiling(length); float stepX = diffX / stepCount; float stepY = diffY / stepCount; int counter = 0; bool isIn = false; for (int i = 0; i < stepCount; i++) { int x = (int)(absoluteStartPoint.X + stepX * i); int y = (int)(absoluteStartPoint.Y + stepY * i); Color color = bitmap.GetPixel(x, y); float brightness = color.GetBrightness(); if (isIn && brightness > 0.5f) { isIn = false; } else if (!isIn && brightness <= 0.5f) { isIn = true; counter++; } } result.Add(zond, counter); } return(result); }
/// <summary> /// Draws a reversible frame on the screen within the specified bounds, /// with the specified background color, and in the specified state. /// </summary> /// <param name="graphics">The Graphics object to draw on.</param> /// <param name="rectangle">The Rectangle that represents the dimensions of the rectangle to draw, in screen coordinates.</param> /// <param name="backColor">The Color of the background behind the frame.</param> /// <param name="style">The FrameStyle of the line.</param> public static void DrawReversibleFrame(Graphics graphics, Rectangle rectangle, Color backColor, FrameStyle style) { Win32.DrawMode drawMode; Color color; if (((double)backColor.GetBrightness()) < 0.5f) { drawMode = Win32.DrawMode.R2_NOTXORPEN; color = Color.White; } else { drawMode = Win32.DrawMode.R2_XORPEN; color = Color.Black; } IntPtr ptrPen = IntPtr.Zero; switch (style) { case FrameStyle.Dashed: ptrPen = Win32.CreatePen((int)Win32.PenStyle.PS_DOT, 1, ColorTranslator.ToWin32(backColor)); break; case FrameStyle.Thick: ptrPen = Win32.CreatePen((int)Win32.PenStyle.PS_SOLID, 1, ColorTranslator.ToWin32(backColor)); break; } IntPtr ptrGraphics = graphics.GetHdc(); int oldDrawMode = Win32.SetROP2(ptrGraphics, (int)drawMode); IntPtr ptrOldBrush = Win32.SelectObject(ptrGraphics, Win32.GetStockObject((int)Win32.StockObject.NULL_BRUSH)); IntPtr ptrOldPen = Win32.SelectObject(ptrGraphics, ptrPen); Win32.SetBkColor(ptrGraphics, ColorTranslator.ToWin32(color)); Win32.Rectangle(ptrGraphics, rectangle.X, rectangle.Y, rectangle.Right, rectangle.Bottom); Win32.SetROP2(ptrGraphics, oldDrawMode); Win32.SelectObject(ptrGraphics, ptrOldBrush); Win32.SelectObject(ptrGraphics, ptrOldPen); Win32.DeleteObject(ptrPen); graphics.ReleaseHdc(ptrGraphics); }
static void PrepareSpritesImpl(Bitmap bmp, int x0, int tilescount, StreamWriter writer) { for (int tile = 0; tile < tilescount; tile++) { var words = new int[16]; var masks = new int[16]; int x = x0 + (tile / 16) * 20; int y = 8 + (tile % 16) * 20; for (int i = 0; i < 16; i++) { int val = 0; int valm = 0; for (int b = 0; b < 16; b++) { Color c = bmp.GetPixel(x + b, y + i); int v = (c.GetBrightness() > 0.2f) ? 0 : 1; val |= (v << b); int vm = (c.R == 120 && c.G == 120 && c.B == 120) ? 1 : 0; valm |= (vm << b); } words[i] = val; masks[i] = valm ^ 0xFFFF; } writer.Write("\t.WORD\t"); for (int i = 0; i < 16; i++) { writer.Write($"{EncodeOctalString2(masks[i])},{EncodeOctalString2(words[i])}"); if (i == 3 || i == 7 || i == 11) { writer.WriteLine(); writer.Write("\t.WORD\t"); } else if (i < 15) { writer.Write(","); } } writer.WriteLine(); } }
private void SetCurrentColorInfo() { //RGB currentRedText.Text = SelectedColor.R.ToString(); currentGreenText.Text = SelectedColor.G.ToString(); currentBlueText.Text = SelectedColor.B.ToString(); //HSL //currentHueText.Text = SelectedColor.CalculateHue().ToString(); currentSaturationText.Text = SelectedColor.GetSaturation().ToString("P0"); currentLightText.Text = SelectedColor.GetBrightness().ToString("P0"); //Hue hueRedText.Text = SelectedHue.R.ToString(); hueGreenText.Text = SelectedHue.G.ToString(); hueBlueText.Text = SelectedHue.B.ToString(); currentHexText.Text = SelectedColor.ToHtml(); rgbCodeText.Text = $"({SelectedColor.R},{SelectedColor.G},{SelectedColor.B})"; }
public void SetColor(Color color) { Color = color; IsSettingValues = true; RSlider.Slider.Value = Color.R; GSlider.Slider.Value = Color.G; BSlider.Slider.Value = Color.B; ASlider.Slider.Value = Color.A; SSlider.Slider.Value = Color.GetSaturation(); LSlider.Slider.Value = Color.GetBrightness(); HSlider.Slider.Value = Color.GetHue(); ColorDisplayBorder.Background = new SolidColorBrush(Color); IsSettingValues = false; OnPickColor?.Invoke(color); }
private void minMaxBright(Bitmap sourceImage) { min = Color.FromArgb(255, 255, 255); max = Color.FromArgb(0, 0, 0); for (int i = 0; i != sourceImage.Width; ++i) { for (int j = 0; j != sourceImage.Height; ++j) { Color tmpColor = sourceImage.GetPixel(i, j); if (tmpColor.GetBrightness() < min.GetBrightness()) { min = tmpColor; } else if (tmpColor.GetBrightness() > max.GetBrightness()) { max = tmpColor; } } } }
public static Color RampedColourByBoxNumber(Color aBaseline, int aBoxCount, uint aCellBaseAddress, uint aAddress) { float cellAddressOffset = (float)((aAddress - aCellBaseAddress) / 4); Color dark = ColourUtils.Darken(aBaseline, 0.30f); Color light = ColourUtils.Lighten(aBaseline, 0.30f); // This is the baseline brightness for the colour float brightnessBaseline = light.GetBrightness() - dark.GetBrightness(); // This is how much brightness we can apply to each box. float brightnessPerBox = (brightnessBaseline / aBoxCount); // This is the brightness of the target box float brightnessPercentage = brightnessPerBox * cellAddressOffset; Color ret = ColourUtils.Lighten(aBaseline, brightnessPercentage); return(ret); }
public static Matrix[] ImageToMatrix(Bitmap img) { int h = img.Height; int w = img.Width; double[,] r = new double[h, w]; double[,] g = new double[h, w]; double[,] b = new double[h, w]; double[,] a = new double[h, w]; double[,] bw = new double[h, w]; Matrix.MatrixLoop((i, j) => { c = img.GetPixel(i, j); r[i, j] = c.R; g[i, j] = c.G; b[i, j] = c.B; a[i, j] = c.A; bw[i, j] = c.GetBrightness() * 255; }, h, w); return(new Matrix[] { bw, r, g, b }); }
public static float BitmapBrightness(this Bitmap bmp) { double brightnessSum = 0.0d; int nonTranspPxelCount = 0; for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color pix = bmp.GetPixel(x, y); if (pix.A <= 127) { continue; } brightnessSum += pix.GetBrightness(); nonTranspPxelCount++; } } return((float)(brightnessSum / nonTranspPxelCount)); }
private void MousePositionTimer_Tick(object sender, EventArgs e) { Color color = GetPixelColor(MousePosition.X, MousePosition.Y); //Sample Color sampleColorPictureBox.BackColor = color; //RGB Color textBoxRgbR.Text = color.R.ToString(); textBoxRgbG.Text = color.G.ToString(); textBoxRgbB.Text = color.B.ToString(); //HSL Color textBoxHslH.Text = color.GetHue().ToString("F0"); textBoxHslS.Text = (color.GetSaturation() * 100).ToString("F0"); textBoxHslL.Text = (color.GetBrightness() * 100).ToString("F0"); //Hex Color textBoxHEX.Text = "#" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"); }
protected override Color calculateNewPixelColor(Bitmap sourceImage, int x, int y) { Color max = Color.FromArgb(0, 0, 0); for (int l = -radiusY; l <= radiusY; ++l) { for (int k = -radiusX; k <= radiusX; ++k) { int idX = Clamp(x + k, 0, sourceImage.Width - 1); int idY = Clamp(y + l, 0, sourceImage.Height - 1); Color neighborColor = sourceImage.GetPixel(idX, idY); if (Convert.ToBoolean(kernel[k + radiusX, l + radiusY]) && (neighborColor.GetBrightness() > max.GetBrightness())) { max = neighborColor; } } } return(max); }
/// <summary> /// Update the Oled display /// </summary> /// <param name="pGraphics">the graphics from GetGraphics() </param> public void Update(Graphics pGraphics) { pGraphics.Flush(); byte[] _tempbuffer = new byte[DISPLAY_SIZE]; for (int y = 0; y < DISPLAY_HEIGHT; y++) { for (int x = 0; x < DISPLAY_WIDTH; x++) { Color pixel = _DisplayImage.GetPixel(x, y); if (pixel.GetBrightness() < 0.5) { _tempbuffer[(y / 8) * DISPLAY_WIDTH + x] |= (byte)(1 << (y % 8)); } } } SendBuffer(_tempbuffer); }
public Bitmap ChangeColor(Bitmap scrBitmap, float limit) { //https://stackoverflow.com/questions/33096826/c-sharp-how-to-remove-all-color-except-black-from-an-image // const float limit = 0.3f; //0.3f for (int i = 0; i < scrBitmap.Width; i++) { for (int j = 0; j < scrBitmap.Height; j++) { Color c = scrBitmap.GetPixel(i, j); if (c.GetBrightness() > limit) { scrBitmap.SetPixel(i, j, Color.White); } } } return(scrBitmap); }
private void SetColorToolTip(object sender, EventArgs e) { TrackBar tb = (TrackBar)sender; cBLightbar.Checked = true; if (tb != null) { int value = tb.Value; int sat = bgc - (value < bgc ? value : bgc); int som = bgc + 11 * (int)(value * 0.0039215); tb.BackColor = Color.FromArgb(tb.Name.ToLower().Contains("red") ? som : sat, tb.Name.ToLower().Contains("green") ? som : sat, tb.Name.ToLower().Contains("blue") ? som : sat); } alphacolor = Math.Max(tBRedBar.Value, Math.Max(tBGreenBar.Value, tBBlueBar.Value)); reg = Color.FromArgb(tBRedBar.Value, tBGreenBar.Value, tBBlueBar.Value); full = HuetoRGB(reg.GetHue(), reg.GetBrightness(), reg); bnColor.BackColor = Color.FromArgb((alphacolor > 205 ? 255 : (alphacolor + 50)), full); ((Label)gBExtras.Controls.Find("lb" + tb.Name.Substring(2, tb.Name.Length - 5) + "V", true)[0]).Text = tb.Value.ToString(); extraChanged = true; }
// a good selectionHighlight color: 215, 238, 252 private Brush HighlightBrush(Rectangle box) { float med = _selectionHighlight.GetBrightness(); float bright = med + 0.05f; if (bright > 1f) { bright = 1f; } float dark = med - 0.05f; if (dark < 0f) { dark = 0f; } Color brtCol = SymbologyGlobal.ColorFromHsl(_selectionHighlight.GetHue(), _selectionHighlight.GetSaturation(), bright); Color drkCol = SymbologyGlobal.ColorFromHsl(_selectionHighlight.GetHue(), _selectionHighlight.GetSaturation(), dark); return(new LinearGradientBrush(box, brtCol, drkCol, LinearGradientMode.Vertical)); }
/// <summary> /// Increase of decrease the brightess of a colour /// </summary> public static Color MultiplyBrightness(this Color c, float amount = 1.0f) // if too dark, multiple white. { if (float.IsNaN(amount)) { return(c); } float val = Math.Abs(amount); float brightness = c.GetBrightness(); if (brightness < 0.1) { c = Color.White; } return(Color.FromArgb(c.A, (byte)Math.Max(Math.Min(Math.Round((float)c.R * val), 255), 0), (byte)Math.Max(Math.Min(Math.Round((float)c.G * val), 255), 0), (byte)Math.Max(Math.Min(Math.Round((float)c.B * val), 255), 0))); }
/// <summary> /// Gets a cool Highlight brush for highlighting things. /// </summary> /// <param name="box">The rectangle in the box</param> /// <param name="selectionHighlight">The color to use for the higlight</param> /// <returns>The highlight brush.</returns> public static Brush HighlightBrush(Rectangle box, Color selectionHighlight) { float med = selectionHighlight.GetBrightness(); float bright = med + 0.05f; if (bright > 1f) { bright = 1f; } float dark = med - 0.05f; if (dark < 0f) { dark = 0f; } Color brtCol = ColorFromHsl(selectionHighlight.GetHue(), selectionHighlight.GetSaturation(), bright); Color drkCol = ColorFromHsl(selectionHighlight.GetHue(), selectionHighlight.GetSaturation(), dark); return(new LinearGradientBrush(box, brtCol, drkCol, LinearGradientMode.Vertical)); }
public void AssertImageEquals(Bitmap expected, Bitmap actual) { var diffCount = 0.0; for (var x = 0; x < expected.Width; x++) { for (var y = 0; y < expected.Height; y++) { Color expectedPixel = expected.GetPixel(x, y); Color actualPixel = actual.GetPixel(x, y); if (Math.Abs(expectedPixel.GetBrightness() - actualPixel.GetBrightness()) > 0.1) { diffCount++; } } } // Изображение, которое рисует метод Draw, должно в точности совпадать с изображением expected-image Assert.Less(diffCount, 100); }
public HSLColor(Color color) { Hue = color.GetHue(); Saturation = color.GetSaturation(); Lightness = color.GetBrightness(); }
public static unsafe void ToSurface(this Texture2D image, TextSurface surface, Color[] cachedColorArray, bool blockMode = false) { int imageWidth = image.Width; int imageHeight = image.Height; image.GetData<Color>(cachedColorArray); SurfaceEditor editor = new SurfaceEditor(surface); editor.Clear(); global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) => //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++) { int startY = (h * surface.Font.Size.Y); //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) => for (int w = 0; w < imageWidth / surface.Font.Size.X; w++) { int startX = (w * surface.Font.Size.X); float allR = 0; float allG = 0; float allB = 0; for (int y = 0; y < surface.Font.Size.Y; y++) { for (int x = 0; x < surface.Font.Size.X; x++) { int cY = y + startY; int cX = x + startX; Color color = cachedColorArray[cY * imageWidth + cX]; allR += color.R; allG += color.G; allB += color.B; } } byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y)); byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y)); byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y)); var newColor = new Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; if (blockMode) { if (sbri > 204) editor.SetGlyph(w, h, 219, newColor); //█ else if (sbri > 152) editor.SetGlyph(w, h, 178, newColor); //▓ else if (sbri > 100) editor.SetGlyph(w, h, 177, newColor); //▒ else if (sbri > 48) editor.SetGlyph(w, h, 176, newColor); //░ } else { if (sbri > 230) editor.SetGlyph(w, h, (int)'#', newColor); else if (sbri > 207) editor.SetGlyph(w, h, (int)'&', newColor); else if (sbri > 184) editor.SetGlyph(w, h, (int)'$', newColor); else if (sbri > 161) editor.SetGlyph(w, h, (int)'X', newColor); else if (sbri > 138) editor.SetGlyph(w, h, (int)'x', newColor); else if (sbri > 115) editor.SetGlyph(w, h, (int)'=', newColor); else if (sbri > 92) editor.SetGlyph(w, h, (int)'+', newColor); else if (sbri > 69) editor.SetGlyph(w, h, (int)';', newColor); else if (sbri > 46) editor.SetGlyph(w, h, (int)':', newColor); else if (sbri > 23) editor.SetGlyph(w, h, (int)'.', newColor); } } } ); }
private void UpdateHsb(Color value) { Hue = (int)value.GetHue(); var brightness = value.GetBrightness(); Brightness = (int)(brightness * 100); var saturation = value.GetSaturation(); Saturation = (int)(saturation * 100); UpdateThumbPosition(); }