private void ChangeContrast(KalikoImage image)
        {
            var lookupTable = BuildLookupTable();

            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;

                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];

                        currentLine[x]     = lookupTable[red];
                        currentLine[x + 1] = lookupTable[green];
                        currentLine[x + 2] = lookupTable[blue];
                    }
                });

                image.UnlockBits(bitmapData);
            }
        }
        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);
            }
        }
Beispiel #3
0
        public override void Run(KalikoImage image)
        {
            if (Radius == 0)
            {
                return;
            }

            var bitmapData = image.LockBits();
            var tempBitmap = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.PixelFormat);

            var tempBitmapData = tempBitmap.LockBits(new Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), ImageLockMode.ReadWrite, tempBitmap.PixelFormat);

            ConvolveAndTranspose(Kernel, bitmapData, tempBitmapData, bitmapData.Width, bitmapData.Height, UseAlpha, UseAlpha && PremultiplyAlpha, false, EdgeMode.Clamp);
            ConvolveAndTranspose(Kernel, tempBitmapData, bitmapData, bitmapData.Height, bitmapData.Width, UseAlpha, false, UseAlpha && PremultiplyAlpha, EdgeMode.Clamp);

            tempBitmap.UnlockBits(tempBitmapData);
            image.UnlockBits(bitmapData);

            tempBitmap.Dispose();
        }
Beispiel #4
0
        private void Sharpen(KalikoImage image, float amount, float radius, int threshold)
        {
            var bitmapData = image.LockBits();

            var tempBitmap     = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.PixelFormat);
            var tempBitmapData = tempBitmap.LockBits(new Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), ImageLockMode.ReadWrite, tempBitmap.PixelFormat);

            var outBitmap     = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.PixelFormat);
            var outBitmapData = outBitmap.LockBits(new Rectangle(0, 0, outBitmap.Width, outBitmap.Height), ImageLockMode.ReadWrite, outBitmap.PixelFormat);

            ApplyGaussianBlur(radius, bitmapData, tempBitmapData, outBitmapData);

            ApplyMask(amount, threshold, bitmapData, outBitmapData);

            outBitmap.UnlockBits(outBitmapData);
            tempBitmap.UnlockBits(tempBitmapData);
            image.UnlockBits(bitmapData);

            outBitmap.Dispose();
            tempBitmap.Dispose();
        }
Beispiel #5
0
        private static void DesaturateImage(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;

                Parallel.For(0, height, y => {
                    var currentLine = startOffset + (y * bitmapData.Stride);
                    for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
                    {
                        var gray       = (byte)(.299 * currentLine[x + 2] + .587 * currentLine[x + 1] + .114 * currentLine[x]);
                        currentLine[x] = currentLine[x + 1] = currentLine[x + 2] = gray;
                    }
                });

                image.UnlockBits(bitmapData);
            }
        }
Beispiel #6
0
        private static void InvertImage(KalikoImage image)
        {
            unsafe {
                var bitmapData = image.LockBits();

                var bytesPerPixel = Image.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
                var height        = bitmapData.Height;
                var widthInBytes  = bitmapData.Width * bytesPerPixel;
                var byteStart     = (byte *)bitmapData.Scan0;

                Parallel.For(0, height, y => {
                    var currentLine = byteStart + (y * bitmapData.Stride);
                    for (var x = 0; x < widthInBytes; x = x + bytesPerPixel)
                    {
                        currentLine[x]     = (byte)(currentLine[x] ^ 255);
                        currentLine[x + 1] = (byte)(currentLine[x + 1] ^ 255);
                        currentLine[x + 2] = (byte)(currentLine[x + 2] ^ 255);
                    }
                });

                image.UnlockBits(bitmapData);
            }
        }