internal override void Execute() { if (beginProcessing == false) { return; } base.Execute(); if (motorTorque > this.channelActivationThreshold) { this.activationDecayInterval = 0; } else { this.activationDecayInterval += Time.deltaTime; } this.activationDecayInterval = Mathf.Clamp(this.activationDecayInterval, 0.0f, 1.0f); float activationLevel = this.activationDecayCurve.Evaluate(this.activationDecayInterval); this.redChannelActivation = activationLevel; this.greenChannelActivation = activationLevel; this.blueChannelActivation = activationLevel; ColorInformation leftEyeInfo = this.leftEye.GetEntireEyeInformation(); ColorInformation rightEyeInfo = this.rightEye.GetEntireEyeInformation(); this.redChannelWeight += (this.redChannelActivation * ((leftEyeInfo.maxRed + rightEyeInfo.maxRed) / 2)) * this.learningRate * Time.deltaTime; this.greenChannelWeight += (this.greenChannelActivation * ((leftEyeInfo.maxGreen + rightEyeInfo.maxGreen) / 2)) * this.learningRate * Time.deltaTime; this.blueChannelWeight += (this.blueChannelActivation * ((leftEyeInfo.maxBlue + rightEyeInfo.maxBlue) / 2)) * this.learningRate * Time.deltaTime; this.redChannelWeight = Mathf.Clamp(this.redChannelWeight, 0.0f, 1.0f); this.greenChannelWeight = Mathf.Clamp(this.greenChannelWeight, 0.0f, 1.0f); this.blueChannelWeight = Mathf.Clamp(this.blueChannelWeight, 0.0f, 1.0f); }
private static void UpdateLights() { int?newBrightness = null; ColorInformation colorInformation = new ColorInformation(); switch (PartyOptions.activePartyOption.brightnessOptionIndex) { case 1: newBrightness = SetRandomBrightness(); break; } switch (PartyOptions.activePartyOption.colorOptionIndex) { case 2: colorInformation = LightProcessingColor.SetRandomColorFromUIInput(); break; } if (BridgeInformation.usedLights.Count > 0) { BasicLightController.SendCommonCommond(); } if (newBrightness != null || colorInformation.rgbColor != null || colorInformation.colorTemperature != null) { PartyUIUpdater.UpdateOutputDisplay(newBrightness, colorInformation.rgbColor, colorInformation.colorTemperature); } }
private void learnButton_Click(object sender, EventArgs e) { // Learn the color information. ColorInformation colorInformation = Algorithms.LearnColor(imageViewer1.Image, imageViewer1.Roi, (ColorSensitivity)colorSensitivityBox.SelectedIndex, (int)saturationThreshold.Value); // Plot the color spectrum on the graph. ColorSpectrumHelpers.PlotColorSpectrum(pictureBox1, (ColorSensitivity)colorSensitivityBox.SelectedIndex, colorInformation.Information); }
public Player(string id, string name, ColorInformation information) { if(id == string.Empty || id == Guid.Empty.ToString()) throw new ArgumentNullException(nameof(id)); Color = information.Color; ColorName = information.ColorName; Id = id; Name = name; }
public static string Parse(Bitmap bmp, ColorInformation info) { int bestErrors = int.MaxValue, tmp; string bestResult = ""; Bitmap bestGlyphMap = null; int[] bestScreenSize = null; BitmapData data = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int bmpStride = data.Stride / 4; int[] bmpData = new int[bmpStride * data.Height]; Marshal.Copy(data.Scan0, bmpData, 0, bmpData.Length); bmp.UnlockBits(data); foreach (string mapFile in Directory.GetFiles("glyphmaps", "*." + bmp.Width + "x" + bmp.Height + ".glyphmap")) { Bitmap glyphMap = new Bitmap(mapFile); int parseErrors; int[] screenSize = new int[2]; string result = Parse(bmp, bmpData, bmpStride, glyphMap, out parseErrors, screenSize, null, null, out tmp, out tmp); if (parseErrors < bestErrors) { bestErrors = parseErrors; bestResult = result; if (bestGlyphMap != null) bestGlyphMap.Dispose(); bestGlyphMap = glyphMap; bestScreenSize = screenSize; if (parseErrors == 0) break; } else { glyphMap.Dispose(); } } string message = ""; if (bestErrors == int.MaxValue) { message = "Grabbing failed. Maybe you need to calibrate the font first?"; } else if (bestErrors != 0) { message = "*** WARNING: " + bestErrors + " characters could not be detected ***\n\n"; } if (info != null && bestGlyphMap != null) { info.MessageLength = message.Length; info.ScreenWidth = bestScreenSize[0]; int height = bestScreenSize[1]; info.ForegroundColors = new Color[info.ScreenWidth * height]; info.BackgroundColors = new Color[info.ScreenWidth * height]; Parse(bmp, bmpData, bmpStride, bestGlyphMap, out bestErrors, bestScreenSize, info.ForegroundColors, info.BackgroundColors, out info.CursorX, out info.CursorY); } if (bestGlyphMap != null) bestGlyphMap.Dispose(); return message + bestResult; }
public Player(string id, string name, ColorInformation information) { if (id == string.Empty || id == Guid.Empty.ToString()) { throw new ArgumentNullException(nameof(id)); } Color = information.Color; ColorName = information.ColorName; Id = id; Name = name; }
internal override float CalculateEyeOutput(Eye eye) { float red, green, blue; ColorInformation info = eye.GetEntireEyeInformation(); red = info.maxRed * this.redChannelWeight; green = info.maxGreen * this.greenChannelWeight; blue = info.maxBlue * this.blueChannelWeight; //now we calculate an average value float average = (red + green + blue) / 3; return(this.vehicle.EvaluateEyeBrightness(average)); }
private void timer_Tick(object sender, EventArgs e) { Bitmap bmp = Grabber.GrabScreen(); if (bmp == null) return; bmp = Parser.RemoveBorder(bmp); if (calibration != null) { if (calibration.Add(bmp) && !calibration.IsFinished) { taskbar.StepCalibration(); } else if (!calibration.WasSame) { WindowState = prevState; } bmp.Dispose(); return; } ColorInformation ci = new ColorInformation(); richTextBox.Text = Parser.Parse(bmp, ci); bmp.Dispose(); if (ci.ForegroundColors != null) { for (int y = 0; y < ci.ForegroundColors.Length / ci.ScreenWidth; y++) { for (int x = 0; x < ci.ScreenWidth; x++) { int idx = y * ci.ScreenWidth + x; richTextBox.Select(ci.MessageLength + y * (ci.ScreenWidth + 1) + x, 1); richTextBox.SelectionColor = ci.ForegroundColors[idx]; richTextBox.SelectionBackColor = ci.BackgroundColors[idx]; } } if (ci.CursorX != -1) { richTextBox.Select(ci.MessageLength + ci.CursorY * (ci.ScreenWidth + 1) + ci.CursorX, 1); richTextBox.SelectionFont = new Font(richTextBox.Font, FontStyle.Underline | FontStyle.Bold); } } richTextBox.Select(richTextBox.Text.Length, 0); WindowState = prevState; }
private static ColorInformation ProcessInputDifferenceColor(double soundLevel) { ColorInformation colorInformation = new ColorInformation(); double inputDifference = soundLevel - savedSoundLevel; if (inputDifference > PartyOptions.activePartyOption.colorDifferencePercent) { colorInformation = LightProcessingColor.SetRandomColorFromUIInput(); } PartyUIUpdater.NewInputDifference(inputDifference); savedSoundLevel = soundLevel; return(colorInformation); }
internal virtual float CalculateEyeOutput(Eye eye) { //calculates the output for a specific eye //by default eye output is calculated for the entire eye ColorInformation eyeInfo = eye.GetEntireEyeInformation(); switch (this.eyeMode) { case EyeMode.Maximum: return(eyeInfo.maxBrightness); case EyeMode.Minimum: return(eyeInfo.minBrightness); default: return(eyeInfo.averageBrightness); } }
public static void NewSoundLevel(double soundLevel) { if (callCount > 8) { int?newBrightness = null; ColorInformation colorInformation = new ColorInformation(); switch (PartyOptions.activePartyOption.brightnessOptionIndex) { case 0: newBrightness = ProcessSoundLevelBrightness(soundLevel); break; } switch (PartyOptions.activePartyOption.colorOptionIndex) { case 0: colorInformation = LightProcessingColor.SetColorGradienStep((float)soundLevel / 100f); break; case 1: colorInformation = ProcessInputDifferenceColor(soundLevel); break; } if (BridgeInformation.usedLights.Count > 0) { BasicLightController.SendCommonCommond(); } if (newBrightness != null || colorInformation.rgbColor != null || colorInformation.colorTemperature != null) { PartyUIUpdater.UpdateOutputDisplay(newBrightness, colorInformation.rgbColor, colorInformation.colorTemperature); } callCount = 0; } callCount++; }
internal override float CalculateEyeOutput(Eye eye) { float red, green, blue; //get color information for the entire retine ColorInformation info = eye.GetEntireEyeInformation(); switch (this.eyeMode) { case EyeMode.Maximum: red = info.maxRed; green = info.maxGreen; blue = info.maxBlue; break; case EyeMode.Minimum: red = info.minRed; green = info.minGreen; blue = info.minBlue; break; default: red = info.averageRed; green = info.averageGreen; blue = info.averageBlue; break; } //now we have the color information for each color channel float diffRed, diffGreen, diffBlue; diffRed = Mathf.Abs(colorSensitivity.r - red); diffGreen = Mathf.Abs(colorSensitivity.g - green); diffBlue = Mathf.Abs(colorSensitivity.b - blue); //now we calculate an average value float average = (diffRed + diffGreen + diffBlue) / 3; //if we have the an exact match to the preferred color, average will equal 0 //and if we have the exact opposite, the average will be 1 return(this.vehicle.EvaluateEyeBrightness(1 - average)); }
private bool LoadImages(string path) { DisposeImages(); if (path.EndsWith(".tga")) { _source = TGA.FromFile(path); } else { _source = (Bitmap)Bitmap.FromFile(path); } //if (_source.PixelFormat != PixelFormat.Format32bppArgb) // using (Bitmap bmp = _source) // _source = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format32bppArgb); //_source.SetResolution(96.0f, 96.0f); _preview = new Bitmap(_source.Width, _source.Height, PixelFormat.Format32bppArgb); txtPath.Text = path; lblSize.Text = String.Format("{0} x {1}", _source.Width, _source.Height); _colorInfo = _source.GetColorInformation(); lblColors.Text = _colorInfo.ColorCount.ToString(); lblTransparencies.Text = _colorInfo.AlphaColors.ToString(); //Get max LOD int maxLOD = 1; for (int w = _source.Width, h = _source.Height; (w != 1) && (h != 1); w >>= 1, h >>= 1, maxLOD++) { ; } numLOD.Maximum = maxLOD; return(true); }
public BusLineRoute(ColorInformation color, BusRoute route) { Color = color; Route = route; }
//returns color information from the specified retinal patch private ColorInformation GetColorInformationFromPatch(Texture2D tex, int x, int y, int width, int height, int patchColumn, int patchRow) { ColorInformation info = new ColorInformation(patchRow, patchColumn); Color[] pix = tex.GetPixels(x, y, width, height); float graySum = 0, redSum = 0, blueSum = 0, greenSum = 0; float grayMax = 0, redMax = 0, blueMax = 0, greenMax = 0; float grayMin = 0, redMin = 0, blueMin = 0, greenMin = 0; for (int i = 0; i < pix.Length; i++) { //get maximum color information if (pix[i].grayscale > grayMax) { grayMax = pix[i].grayscale; } if (pix[i].r > redMax) { redMax = pix[i].r; } if (pix[i].g > greenMax) { greenMax = pix[i].g; } if (pix[i].b > blueMax) { blueMax = pix[i].b; } //get minimum color information if (pix[i].grayscale < grayMin) { grayMin = pix[i].grayscale; } if (pix[i].r < redMin) { redMin = pix[i].r; } if (pix[i].g < greenMin) { greenMin = pix[i].g; } if (pix[i].b < blueMin) { blueMin = pix[i].b; } //get total color information graySum += pix[i].grayscale; redSum += pix[i].r; greenSum += pix[i].g; blueSum += pix[i].b; } //set maximum color information info.maxBrightness = grayMax; info.maxRed = redMax; info.maxGreen = greenMax; info.maxBlue = blueMax; //set minimum color information info.minBrightness = grayMin; info.minRed = redMin; info.minGreen = greenMin; info.minBlue = blueMin; //set average color information info.averageBrightness = graySum / pix.Length; info.averageRed = redSum / pix.Length; info.averageGreen = greenSum / pix.Length; info.averageBlue = blueSum / pix.Length; return(info); }
//// Called whenever Monaco needs to translate a color value to the textual representation (e.g. from the onhover color picker selector) public IAsyncOperation <IEnumerable <ColorPresentation> > ProvideColorPresentationsAsync(IModel document, ColorInformation colorInfo) { return(AsyncInfo.Run(async delegate(CancellationToken cancelationToken) { return new ColorPresentation[] { new ColorPresentation(colorInfo.Color.ToString()), }.AsEnumerable(); })); }
internal ColorInformation GetEntireEyeInformation() { //returns color information for the entire eye - used when we are dealing with a simple eye float graySum = 0, redSum = 0, blueSum = 0, greenSum = 0; float grayMax = 0, redMax = 0, blueMax = 0, greenMax = 0; float grayMin = 0, redMin = 0, blueMin = 0, greenMin = 0; ColorInformation info = new ColorInformation(0, 0); for (int i = 0; i < this.retinalColumns; i++) { for (int j = 0; j < this.retinalRows; j++) { ColorInformation patchInfo = this.retinalPatchesVisualInfo [i, j]; //get maximum color information if (patchInfo.maxBrightness > grayMax) { grayMax = patchInfo.maxBrightness; } if (patchInfo.maxRed > redMax) { redMax = patchInfo.maxRed; } if (patchInfo.maxGreen > greenMax) { greenMax = patchInfo.maxGreen; } if (patchInfo.maxBlue > blueMax) { blueMax = patchInfo.maxBlue; } //get minimum color information if (patchInfo.minBrightness < grayMin) { grayMin = patchInfo.minBrightness; } if (patchInfo.minRed < redMin) { redMin = patchInfo.minRed; } if (patchInfo.minGreen < greenMin) { greenMin = patchInfo.minGreen; } if (patchInfo.minBlue < blueMin) { blueMin = patchInfo.minBlue; } //get total color information graySum += patchInfo.averageBrightness; redSum += patchInfo.averageRed; greenSum += patchInfo.averageGreen; blueSum += patchInfo.averageBlue; } } //set maximum color information info.maxBrightness = grayMax; info.maxRed = redMax; info.maxGreen = greenMax; info.maxBlue = blueMax; //set minimum color information info.minBrightness = grayMin; info.minRed = redMin; info.minGreen = greenMin; info.minBlue = blueMin; //set average color information info.averageBrightness = graySum / (this.retinalColumns * this.retinalRows); info.averageRed = redSum / (this.retinalColumns * this.retinalRows); info.averageGreen = greenSum / (this.retinalColumns * this.retinalRows); info.averageBlue = blueSum / (this.retinalColumns * this.retinalRows); return(info); }