/// <summary> /// Prepare the sampler instance. /// </summary> /// <param name="gui">Sampler type from GUI (combo-box)?</param> private void checkSampler(bool gui) { string name = comboSampling.Text; if (!gui && sset != null) { name = sset.samplingSource; } if (DefaultSampling.Samplings.ContainsKey(name)) { sampler = DefaultSampling.Samplings[name]; } else { sampler = new RandomSampling(); } string dname = comboDensity.Text; switch (dname) { case DefaultPdf.PDF_IMAGE: if (densityFile == null || !File.Exists(densityFile)) { Util.Log("Invalid density file: " + densityFile ?? "null"); density = new DensityFunction(-1); break; } density = new RasterPdf(densityFile, checkNegative.Checked); break; case DefaultPdf.PDF_UNIFORM: density = new DensityFunction(-1); break; case DefaultPdf.PDF_RAMP: density = new DensityFunction(0); break; case DefaultPdf.PDF_COSRR: density = new DensityFunction(1); break; case DefaultPdf.PDF_SINCR: density = new DensityFunction(2); break; case DefaultPdf.PDF_SINCOS: density = new DensityFunction(3); break; } sampler.Density = density; sampler.Break = false; }
public SmartObjectLayer(SubPattern pattern, string name, System.Drawing.Bitmap bitmap, int x, int y, int width, int height) : base(pattern, name) { Crop = Crops[0]; Resampler = Resamplers[0]; Bitmap = bitmap; _ObjectX = x; _ObjectY = y; _ObjectWidth = width; _ObjectHeight = height; }
private void WritePoints(ISampling sample, TimePoint[] data, AlignModes mode, String prefix = null) { if (prefix.IsNullOrEmpty()) { prefix = "avg"; } var f = $"Algorithms/{prefix}_{mode}_sampled.csv".GetFullPath(); //if (sample.BucketSize > 0) f = $"Algorithms/avgfill_{mode}_sampled.csv".GetFullPath(); if (File.Exists(f)) { File.Delete(f); } using var csv = new CsvFile(f, true); for (var i = 0; i < data.Length; i++) { csv.WriteLine(data[i].Time, data[i].Value); } csv.Dispose(); //XTrace.WriteLine(f); }
public static void Register(ISampling s) { Samplings[s.Name] = s; }
public void ChangeResampling(int num) { Resampler = Resamplers[num]; }
public void ParsePattern(ICrop crop, ISampling sampling, IColorQuantizer quantizer, IColorCache colorCache) { if (!this.IsParsing) { IsParsing = true; Thread thread = new Thread(() => { var bmp = new Bitmap((System.Drawing.Image)Image.Clone()); int desiredWidth = 32; int desiredHeight = 32; if (crop != null) { crop.SetImage(bmp); desiredWidth = crop.GetWidth(); desiredHeight = crop.GetHeight(); } if (quantizer is BaseColorCacheQuantizer colorCacheQuantizer) { colorCacheQuantizer.ChangeCacheProvider(colorCache); } var sampledBmp = sampling.Resample(bmp, desiredWidth, desiredHeight); bmp.Dispose(); bmp = sampledBmp; Bitmap croppedBmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(croppedBmp)) { graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.DrawImage(bmp, (32 - bmp.Width) / 2, (32 - bmp.Height) / 2, bmp.Width, bmp.Height); } bmp.Dispose(); bmp = croppedBmp; var transparentPixels = new bool[bmp.Width * bmp.Height]; for (var y = 0; y < bmp.Height; y++) { for (var x = 0; x < bmp.Width; x++) { transparentPixels[x + y * bmp.Width] = bmp.GetPixel(x, y).A != 255; } } var targetImage = ImageBuffer.QuantizeImage(bmp, quantizer, null, 15, 1); bmp.Dispose(); bmp = new Bitmap(targetImage); for (var y = 0; y < bmp.Height; y++) { for (var x = 0; x < bmp.Width; x++) { if (transparentPixels[x + y * bmp.Width]) { bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 0, 0, 0)); } } } Result = bmp; IsReady = true; IsParsing = false; }); thread.Start(); } }