public void ColorCutQuantizerGetQuantizedColors() { tlog.Debug(tag, $"ColorCutQuantizerGetQuantizedColors START"); using (PixelBuffer pixelBuffer = new PixelBuffer(100, 200, PixelFormat.A8)) { using (Rectangle region = new Rectangle()) { var testingTarget = ColorCutQuantizer.FromBitmap(pixelBuffer, region, 255); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <ColorCutQuantizer>(testingTarget, "Should be an Instance of ColorCutQuantizer!"); try { testingTarget.GetQuantizedColors(); tlog.Debug(tag, "quantizedColors : " + testingTarget.GetQuantizedColors()); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception: Failed!"); } } } tlog.Debug(tag, $"ColorCutQuantizerGetQuantizedColors END (OK)"); }
/** * Generate and return the {@link Palette} synchronously. */ public Palette Generate() { //TimingLogger logger = LOG_TIMINGS // ? new TimingLogger(LOG_TAG, "Generation") // : null; List <Swatch> swatches; if (_bitmap != null) { // We have a Bitmap so we need to use quantization to reduce the number of colors // First we'll scale down the bitmap if needed Bitmap bitmap = ScaleBitmapDown(_bitmap); //if (logger != null) //{ // logger.addSplit("Processed Bitmap"); //} Rectangle?nullableRegion = _region; if (bitmap != _bitmap && nullableRegion.HasValue) { Rectangle region = nullableRegion.Value; // If we have a scaled bitmap and a selected region, we need to scale down the // region to match the new scale double scale = bitmap.Width / (double)_bitmap.Width; region = Rectangle.FromLTRB((int)Math.Floor(region.Left * scale), region.Top, region.Right, region.Bottom); region = Rectangle.FromLTRB(region.Left, (int)Math.Floor(region.Top * scale), region.Right, region.Bottom); region = Rectangle.FromLTRB(region.Left, region.Top, Math.Min((int)Math.Ceiling(region.Right * scale), bitmap.Width), region.Bottom); region = Rectangle.FromLTRB(region.Left, region.Top, region.Right, Math.Min((int)Math.Ceiling(region.Bottom * scale), bitmap.Width)); } // Now generate a quantizer from the Bitmap ColorCutQuantizer quantizer = new ColorCutQuantizer(GetPixelsFromBitmap(bitmap), _maxColors, _filters.Any() ? null : _filters.ToArray()); // If created a new bitmap, recycle it //if (bitmap != _bitmap) //{ // bitmap.recycle(); //} swatches = quantizer.GetQuantizedColors(); //if (logger != null) //{ // logger.addSplit("Color quantization completed"); //} } else { // Else we're using the provided swatches swatches = _swatches; } // Now create a Palette instance Palette p = new Palette(swatches, _targets); // And make it generate itself p.Generate(); //if (logger != null) //{ // logger.addSplit("Created Palette"); // logger.dumpToLog(); //} return(p); }
public void ColorCutQuantizerFromBitmapWithNullRegion() { tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithNullRegion START"); using (PixelBuffer pixelBuffer = new PixelBuffer(1, 2, PixelFormat.A8)) { using (Rectangle region = null) { var testingTarget = ColorCutQuantizer.FromBitmap(pixelBuffer, region, 255); Assert.IsNotNull(testingTarget, "Should be not null!"); Assert.IsInstanceOf <ColorCutQuantizer>(testingTarget, "Should be an Instance of ColorCutQuantizer!"); } } tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithNullRegion END (OK)"); }
public void ColorCutQuantizerFromBitmapWithMaxColorLessThan1() { tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithMaxColorLessThan1 START"); using (PixelBuffer pixelBuffer = new PixelBuffer(100, 200, PixelFormat.RGBA8888)) { using (Rectangle region = new Rectangle()) { try { ColorCutQuantizer.FromBitmap(pixelBuffer, region, 0); } catch (ArgumentNullException e) { tlog.Debug(tag, e.Message.ToString()); tlog.Debug(tag, $"ColorCutQuantizerFromBitmapWithMaxColorLessThan1 END (OK)"); Assert.Pass("Caught ArgumentNullException : Passed!"); } } } }