//Adjust black bars to horizontal bottom static unsafe void AdjustBlackbarBottom(byte *bitmapData, ref int targetMargin) { try { for (int captureStep = vMarginMinimumOffset; captureStep < vBlackBarStepVertical; captureStep += vMarginBlackAccuracy) { int CaptureZoneVer = captureStep; for (int captureRange = vMarginMinimumOffset; captureRange < vBlackBarRangeVertical; captureRange += vMarginBlackAccuracy) { int CaptureZoneHor = captureRange; ColorRGBA ColorPixel = ColorProcessing.GetPixelColor(bitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor, CaptureZoneVer); if (ColorPixel != null) { if (setDebugMode && setDebugBlackBar) { ColorProcessing.SetPixelColor(bitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor, CaptureZoneVer, ColorRGBA.Orange); } if (ColorPixel.R > setAdjustBlackBarBrightness || ColorPixel.G > setAdjustBlackBarBrightness || ColorPixel.B > setAdjustBlackBarBrightness) { targetMargin = captureStep; //Debug.WriteLine("Adjusting black bar margin to: " + captureStep); return; } } } } targetMargin = vBlackBarStepVertical; } catch { } }
public ColorForm(Form1 form1) { this.parent = form1; InitializeComponent(); this.pictureBox1.Image = ColorProcessing.GetPreviev(parent.Pic, this.pictureBox1.Width, this.pictureBox1.Height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); }
/// <summary> /// Call this method to refresh the color properties /// </summary> /// <param name="player">player instance</param> /// <param name="density">density for adaptive color</param> public void LoadColor(Color primaryColor, Color secondaryColor) { this._primaryColor = primaryColor.ToChromaColor(); this._secondaryColor = secondaryColor.ToChromaColor(); var gradients = ColorProcessing.GenerateGradients(new[] { primaryColor, secondaryColor }, true); this._albumColors?.Dispose(); this._albumColors = new AutoshiftCirculaQueue <ChromaColor>(gradients.Select(ColorExtensions.ToChromaColor), 500); }
public void StartProcessColorEdit(float brightness, float gamma, float red, float green, float blue, float alpha) { DateTime start = DateTime.Now; Pic = ColorProcessing.AdjustImage( Pic, brightness, gamma, red, green, blue, alpha); this.pictureBox1.Image = Pic; MessageBox.Show(string.Format("Время обработки: {0}", (DateTime.Now - start)), "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }
private void trackBar_Scroll(object sender, EventArgs e) { this.pictureBox1.Image = ColorProcessing.GetPreviev( parent.Pic, this.pictureBox1.Width, this.pictureBox1.Height, this.brightnessTrackBar.Value * 0.1f, this.gammaTrackBar.Value * 0.1f, this.redTrackBar.Value * 0.1f, this.greenTrackBar.Value * 0.1f, this.blueTrackBar.Value * 0.1f, this.alphaTrackBar.Value * 0.1f); }
private ColorProcessing getColorProcessing() { ColorProcessing colorProcessing = ColorProcessing.COLOR_KEEP; if (radioButtonColorConvert.Checked) { colorProcessing = ColorProcessing.COLOR_CONVERT; } else if (radioButtonColorRemove.Checked) { colorProcessing = ColorProcessing.COLOR_REMOVE; } return(colorProcessing); }
public override string Convert(string inputString, ColorProcessing colorProcessing) { string outputString; switch (colorProcessing) { case ColorProcessing.COLOR_REMOVE: case ColorProcessing.COLOR_CONVERT: outputString = colorCodeRegex.Replace(inputString, ""); break; case ColorProcessing.COLOR_KEEP: default: outputString = inputString; break; } return(outputString); }
public override string Convert(string inputString, ColorProcessing colorProcessing) { inputString = inputString.Replace("&", "&").Replace(">", ">").Replace(">", "<"); string outputString; switch (colorProcessing) { case ColorProcessing.COLOR_REMOVE: outputString = colorCodeRegex.Replace(inputString, ""); break; case ColorProcessing.COLOR_CONVERT: outputString = colorCodeAndTextRegex.Replace(inputString, new MatchEvaluator(HtmlColorCodesMatchEvaluator)); break; case ColorProcessing.COLOR_KEEP: default: outputString = inputString; break; } return(outputString + "<br />"); }
private void buttonConvert_Click(object sender, EventArgs e) { if (conversionBackgroundWorker.IsBusy) { // Cancel conversion conversionBackgroundWorker.CancelAsync(); } else { // Check input and begin converting if (textBoxInputFile.Text.Trim().Length == 0) { MessageBox.Show(this, "You must specify an input file to convert.", "Invalid input file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!File.Exists(textBoxInputFile.Text)) { MessageBox.Show(this, "The input file does not exist.", "Invalid input file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (textBoxOutputFile.Text.Trim().Length == 0) { MessageBox.Show(this, "You must specify an output file.", "Invalid output file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { LogConverter converter = LogConverterFactory.create(getConverterType()); ColorProcessing colorProcessing = getColorProcessing(); object[] args = new object[4]; args[0] = converter; args[1] = textBoxInputFile.Text; args[2] = textBoxOutputFile.Text; args[3] = colorProcessing; progressBarConvert.Value = 0; conversionBackgroundWorker.RunWorkerAsync(args); } } }
public abstract string Convert(string inputString, ColorProcessing colorProcessing);
private void conversionBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { SetBusyState(true); BackgroundWorker worker = (BackgroundWorker)sender; object[] args = (object[])e.Argument; LogConverter converter = (LogConverter)args[0]; string inputFileName = (string)args[1]; string outputFileName = (string)args[2]; ColorProcessing colorProcessing = (ColorProcessing)args[3]; FileStream inputFileStream = null; FileStream outputFileStream = null; StreamReader inputFileReader = null; StreamWriter outputFileWriter = null; try { inputFileStream = File.OpenRead(inputFileName); outputFileStream = File.OpenWrite(outputFileName); inputFileReader = new StreamReader(inputFileStream); outputFileWriter = new StreamWriter(outputFileStream); // Count the number of lines in input int totalLines = 0; while (inputFileReader.ReadLine() != null) { ++totalLines; } // Rewind to the beginning of the input file inputFileStream.Seek(0, SeekOrigin.Begin); // Write header outputFileWriter.WriteLine(converter.Header); // Convert input to output int currentLines = 0; string inputLine; while ((inputLine = inputFileReader.ReadLine()) != null) { ++currentLines; string outputLine = converter.Convert(inputLine, colorProcessing); outputFileWriter.WriteLine(outputLine); worker.ReportProgress((int)(currentLines * 100.0 / totalLines)); if (worker.CancellationPending) { e.Cancel = true; break; } } // Write footer outputFileWriter.WriteLine(converter.Footer); } finally { if (outputFileWriter != null) { outputFileWriter.Close(); } if (inputFileReader != null) { inputFileReader.Close(); } if (outputFileStream != null) { outputFileStream.Close(); } if (inputFileStream != null) { inputFileStream.Close(); } } }
//Capture the color pixels private static unsafe void CaptureColorAlgorithm(byte *BitmapData, ref int CapturedColors, ref int AverageRed, ref int AverageGreen, ref int AverageBlue, int CaptureZoneHor, int CaptureZoneVer, int CaptureZoneSize, LedSideTypes SideType) { try { int CaptureEvenStep = 1; int CaptureZoneHorRange = 0; int CaptureZoneVerRange = 0; for (int captureStep = 0; captureStep < CaptureZoneSize; captureStep++) { if (CaptureEvenStep == 1) { CaptureEvenStep = 0; } else { CaptureEvenStep = 1; } for (int captureRange = 0; captureRange < vCaptureRange; captureRange += 2) { if (SideType == LedSideTypes.TopLeftToRight) { CaptureZoneHorRange = captureStep; CaptureZoneVerRange = -captureRange - CaptureEvenStep; } else if (SideType == LedSideTypes.TopRightToLeft) { CaptureZoneHorRange = -captureStep; CaptureZoneVerRange = -captureRange - CaptureEvenStep; } else if (SideType == LedSideTypes.BottomLeftToRight) { CaptureZoneHorRange = captureStep; CaptureZoneVerRange = captureRange + CaptureEvenStep; } else if (SideType == LedSideTypes.BottomRightToLeft) { CaptureZoneHorRange = -captureStep; CaptureZoneVerRange = captureRange + CaptureEvenStep; } else if (SideType == LedSideTypes.LeftBottomToTop) { CaptureZoneHorRange = captureRange + CaptureEvenStep; CaptureZoneVerRange = captureStep; } else if (SideType == LedSideTypes.LeftTopToBottom) { CaptureZoneHorRange = captureRange + CaptureEvenStep; CaptureZoneVerRange = -captureStep; } else if (SideType == LedSideTypes.RightBottomToTop) { CaptureZoneHorRange = -captureRange - CaptureEvenStep; CaptureZoneVerRange = captureStep; } else if (SideType == LedSideTypes.RightTopToBottom) { CaptureZoneHorRange = -captureRange - CaptureEvenStep; CaptureZoneVerRange = -captureStep; } ColorRGBA ColorPixel = ColorProcessing.GetPixelColor(BitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor + CaptureZoneHorRange, CaptureZoneVer + CaptureZoneVerRange); if (ColorPixel != null) { if (setDebugMode && setDebugColor) { ColorProcessing.SetPixelColor(BitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor + CaptureZoneHorRange, CaptureZoneVer + CaptureZoneVerRange, ColorRGBA.Purple); } AverageRed += ColorPixel.R; AverageGreen += ColorPixel.G; AverageBlue += ColorPixel.B; CapturedColors++; } } } } catch { } }