public void ApplyChromaKey(KalikoImage image) { var pixels = image.IntArray; var keyHsb = ColorSpaceHelper.RGBtoHSB(KeyColor); for (int i = 0; i < pixels.Length; i++) { int rgb = pixels[i]; int red = (rgb >> 16) & 0xff; int green = (rgb >> 8) & 0xff; int blue = rgb & 0xff; HSB hsb = ColorSpaceHelper.RGBtoHSB(red, green, blue); if (Math.Abs(hsb.Hue - keyHsb.Hue) < ToleranceHue && Math.Abs(hsb.Saturation - keyHsb.Saturation) < ToleranceSaturnation && Math.Abs(hsb.Brightness - keyHsb.Brightness) < ToleranceBrightness) { pixels[i] = rgb & 0xffffff; } else { pixels[i] = rgb; } } image.IntArray = pixels; }
public void ApplyChromaKey(KalikoImage image) { unsafe { var bitmapData = image.LockBits(); var bytesPerPixel = Image.GetPixelFormatSize(bitmapData.PixelFormat) / 8; var height = bitmapData.Height; var widthInBytes = bitmapData.Width * bytesPerPixel; var startOffset = (byte *)bitmapData.Scan0; var keyHsb = ColorSpaceHelper.RGBtoHSB(KeyColor); Parallel.For(0, height, y => { var currentLine = startOffset + (y * bitmapData.Stride); for (var x = 0; x < widthInBytes; x = x + bytesPerPixel) { var red = currentLine[x]; var green = currentLine[x + 1]; var blue = currentLine[x + 2]; var hsb = ColorSpaceHelper.RGBtoHSB(red, green, blue); if (Abs(hsb.Hue, keyHsb.Hue) < ToleranceHue && Abs(hsb.Saturation, keyHsb.Saturation) < ToleranceSaturnation && Abs(hsb.Brightness, keyHsb.Brightness) < ToleranceBrightness) { currentLine[x + 3] = 0; } } }); image.UnlockBits(bitmapData); } }
public override Color BlendColor(Color l, Color r) { Color c = r; HSB hsv = ColorSpaceHelper.RGBtoHSB(c); hsv.Brightness += (((IsPreview ? _noise : _noise2).NextDouble() - 0.5f) * 2) * GlobalSettings.NoiseSaturation; if (hsv.Brightness < 0) { hsv.Brightness = 0; } if (hsv.Brightness > 1) { hsv.Brightness = 1; } return(Color.FromArgb(r.A, ColorSpaceHelper.HSBtoColor(hsv))); }