public static FilterImage FilterImageFromBitmap(Bitmap bitmap)
        {
            FilterImage outputImage = new FilterImage(bitmap.Width, bitmap.Height);

            var bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, outputImage.Width, outputImage.Height),
                ImageLockMode.ReadOnly,
                PixelFormat.Format32bppArgb
                );
            var stride = bitmapData.Stride - bitmapData.Width * 4;

            int x, y;

            unsafe
            {
                var offset = (byte *)bitmapData.Scan0.ToPointer();
                for (y = 0; y < outputImage.Height; y++)
                {
                    for (x = 0; x < outputImage.Width; x++)
                    {
                        outputImage.SetPixel(x, y,
                                             *(offset + 2),
                                             *(offset + 1),
                                             *(offset + 0),
                                             *(offset + 3)
                                             );

                        offset += 4;
                    }
                    offset += stride;
                }
            }
            bitmap.UnlockBits(bitmapData);
            return(outputImage);
        }
Exemplo n.º 2
0
        public FilterImage RotateAndDownscale(FilterImage input, double angleRad)
        {
            int         newWidth  = (int)((double)input.Width / 8);
            int         newHeight = (int)((double)input.Height / 8);
            FilterImage newImage  = new FilterImage(newWidth, newHeight);

            int centerX = newWidth / 2;
            int centerY = newHeight / 2;

            for (int x = 0; x < newWidth; x++)
            {
                for (int y = 0; y < newHeight; y++)
                {
                    double dir       = Math.Atan2(y - centerY, x - centerX);
                    double magnitude = Math.Sqrt((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY)) * 8;

                    dir = dir - angleRad;

                    int origX = (int)Math.Round((centerX * 8) + magnitude * Math.Cos(dir));
                    int origY = (int)Math.Round((centerY * 8) + magnitude * Math.Sin(dir));

                    if (origX >= 0 && origX < input.Width &&
                        origY >= 0 && origY < input.Height)
                    {
                        newImage.SetPixelArgb(x, y, input.PixelArgb(origX, origY));
                    }
                }
            }

            return(newImage);
        }
        public static Bitmap BitmapFromFilterImage(FilterImage image)
        {
            Bitmap outputBitmap = new Bitmap(image.Width, image.Height);

            var bitmapData = outputBitmap.LockBits(
                new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.WriteOnly,
                PixelFormat.Format32bppArgb
                );

            var fillBytes = bitmapData.Stride - bitmapData.Width * 4;

            unsafe
            {
                int x, y;
                var offset = (byte *)bitmapData.Scan0.ToPointer();
                for (y = 0; y < image.Height; y++)
                {
                    for (x = 0; x < image.Width; x++)
                    {
                        *(offset + 3) = image.Alpha(x, y);
                        *(offset + 2) = image.Red(x, y);
                        *(offset + 1) = image.Green(x, y);
                        *(offset + 0) = image.Blue(x, y);
                        offset       += 4;
                    }
                    offset += fillBytes;
                }
            }
            outputBitmap.UnlockBits(bitmapData);
            return(outputBitmap);
        }
Exemplo n.º 4
0
        public FilterImage Execute(FilterImage input)
        {
            cImage cimage = input.tocImage();

            cimage = cimage.ApplyHQ(scale.Value, complex.GetSelected());
            return(new FilterImage(cimage));
        }
Exemplo n.º 5
0
        public void FilterElement()
        {
            IPipe pipeNull = new PipeNull();

            //Creamos una tag de Image
            Dictionary <string, Attribute> attributeList = new Dictionary <string, Attribute>();
            Attribute attribute  = new Attribute("Name", "image1");
            Attribute attribute2 = new Attribute("PositionY", "100");
            Attribute attribute3 = new Attribute("PositionX", "100");
            Attribute attribute4 = new Attribute("Length", "100");
            Attribute attribute5 = new Attribute("Width", "100");
            Attribute attribute6 = new Attribute("ImagePath", "Oceano.jpg");

            attributeList.Add(attribute.Key, attribute);
            attributeList.Add(attribute2.Key, attribute2);
            attributeList.Add(attribute3.Key, attribute3);
            attributeList.Add(attribute4.Key, attribute4);
            attributeList.Add(attribute5.Key, attribute5);
            attributeList.Add(attribute6.Key, attribute6);
            Tag tag = new Tag("Image", attributeList);

            //Creamos un filterImage
            IFilterConditional filterImage = new FilterImage();
            IPipe pipe0 = new PipeConditional(filterImage, pipeNull, pipeNull);

            //Testeamos que el resultado de la pipe sea el correcto.
            Assert.True(pipe0.Send(tag) is VisitorImage);
        }
        //put the bitmap as input image and set it for next steps
        private void SetInputImage(Bitmap inputBitmap)
        {
            var hBitmap = inputBitmap.GetHbitmap();
            var imgIn   = ((System.Windows.Controls.Image) this.FindName("InputImage"));

            if (imgIn.Source != null)
            {
                imgIn.Source = null;
            }

            try
            {
                var imageSource = Imaging.CreateBitmapSourceFromHBitmap(
                    hBitmap,
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(inputBitmap.Width, inputBitmap.Height));

                imageSource.Freeze();
                imgIn.Source = imageSource;
            }
            finally
            {
                DeleteObject(hBitmap);

                imgIn.Width  = inputBitmap.Width;
                imgIn.Height = inputBitmap.Height;

                var inputInfoLabel = ((System.Windows.Controls.Label) this.FindName("InputInfoLabel"));
                inputInfoLabel.Content = $"x:{inputBitmap.Width} y:{inputBitmap.Height}";
                inputImage             = FilterImageConvert.FilterImageFromBitmap(inputBitmap);
            }
        }
Exemplo n.º 7
0
        public FilterImage Execute(FilterImage input)
        {
            cImage cimage = input.tocImage();

            cimage = cimage.ApplyXbr(scale.Value, alphaBlending.Value);
            return(new FilterImage(cimage));
        }
        private async Task ExecuteCurrentFilterTiled()
        {
            int tileSizeY;
            int tileSizeX;

            if (!int.TryParse(((TextBox)this.FindName("tileYbox")).Text, out tileSizeY) || !int.TryParse(((TextBox)this.FindName("tileXbox")).Text, out tileSizeX))
            {
                MessageBox.Show("invalid tile dimensions");
                return;
            }
            if (tileSizeX == 0 || tileSizeX > this.inputImage.Width || tileSizeY == 0 || tileSizeY > this.inputImage.Height)
            {
                MessageBox.Show("Tiles should be at least 1 pixel (x & y) and not bigger than the input image");
                return;
            }

            converting = true;
            //maybe display its settings again to see the up to date settings
            DisplayCurrentFilterSettings();

            PushProgress("Creating target Image", 1);
            //just run the converter with the first tile, to see how big the output tiles are
            Task <FilterImage> testConvertTask       = Task.Run(() => this.currentFilter.Execute(this.inputImage.GrabSubImage(0, 0, tileSizeX, tileSizeY)));
            FilterImage        testOutputFilterImage = await testConvertTask;

            int         scaleX      = testOutputFilterImage.Width / tileSizeX;
            int         scaleY      = testOutputFilterImage.Height / tileSizeY;
            FilterImage outputImage = new FilterImage(this.inputImage.Width * scaleX, this.inputImage.Height * scaleY);

            int offsetX;
            int offsetY        = 0;
            int tilesProcessed = 1;
            int tilesToProcess = (inputImage.Height / tileSizeY) * (inputImage.Width / tileSizeX);

            while (offsetY <= inputImage.Height - tileSizeY)
            {
                offsetX = 0;
                while (offsetX <= inputImage.Width - tileSizeX)
                {
                    PushProgress($"converting tile: {tilesProcessed} / {tilesToProcess}", 2);
                    Task <FilterImage> convertTileTask = Task.Run(() => this.currentFilter.Execute(this.inputImage.GrabSubImage(offsetX, offsetY, tileSizeX, tileSizeY)));
                    FilterImage        iOutputTile     = await convertTileTask;
                    outputImage.PutImage(offsetX * scaleX, offsetY * scaleY, iOutputTile);
                    offsetX += tileSizeX;
                    tilesProcessed++;
                }
                offsetY += tileSizeY;
            }

            //convert the result back to bitmap
            PushProgress("Fetching result", 3);
            var outputTask   = Task.Run(() => FilterImageConvert.BitmapFromFilterImage(outputImage));
            var outputBitmap = await outputTask;

            //apply the output bitmap guiwise
            PushProgress("Rendering result", 3);
            SetOutputImage(outputBitmap);

            converting = false;
        }
Exemplo n.º 9
0
        public FilterImage Execute(FilterImage input)
        {
            FilterImage newImage = new FilterImage(input.Width, input.Height);

            for (int x = 0; x < input.Width; x++)
            {
                for (int y = 0; y < input.Height; y++)
                {
                    int argb = GBCColor(input.PixelArgb(x, y));
                    newImage.SetPixelArgb(x, y, argb);
                }
            }
            return(newImage);
        }
Exemplo n.º 10
0
        public FilterImage Execute(FilterImage input)
        {
            cImage cimage = input.tocImage();

            cimage = cimage.ApplyXbr(4, false);
            cimage = cimage.ApplyXbr(2, false);

            int normalizedDegs = rotateDegrees.Value < 0 ? rotateDegrees.Value + 360 : rotateDegrees.Value;

            double rotateRads = normalizedDegs * Math.PI / 180.0;


            FilterImage rot = RotateAndDownscale(new FilterImage(cimage), rotateRads);

            return(rot);
        }
 public string ExecuteFilter(FilterImage inputImage, ref FilterImage outputImage, string[] args)
 {
     for (int i = 0; i < args.Length; i++)
     {
         var argSplit = args[i].Split(':');
         foreach (Setting setting in filter.Settings)
         {
             if (setting.Name.Equals(argSplit[0], StringComparison.InvariantCultureIgnoreCase))
             {
                 setting.Set(argSplit[1]);
             }
         }
     }
     outputImage = filter.Execute(inputImage);
     return("Ok");
 }
Exemplo n.º 12
0
        public FilterImage Execute(FilterImage input)
        {
            int         newWidth  = (int)((double)input.Width * (1.0 / scale.Value));
            int         newHeight = (int)((double)input.Height * (1.0 / scale.Value));
            FilterImage newImage  = new FilterImage(newWidth, newHeight);

            for (int x = 0; x < newImage.Width; x++)
            {
                for (int y = 0; y < newImage.Height; y++)
                {
                    Dictionary <int, int> argbCount = new Dictionary <int, int>();
                    // test imp 1, most common wins.
                    FilterImage chunk = input.GrabSubImage(x * scale.Value, y * scale.Value, scale.Value, scale.Value);
                    for (int cx = 0; cx < chunk.Width; cx++)
                    {
                        for (int cy = 0; cy < chunk.Height; cy++)
                        {
                            int pixel = chunk.PixelArgb(cx, cy);
                            if (!argbCount.ContainsKey(pixel))
                            {
                                argbCount.Add(pixel, 1);
                            }
                            else
                            {
                                argbCount[pixel] = argbCount[pixel] + 1;
                            }
                        }
                    }

                    int finalPixel;
                    if (argbCount.Count >= scale.Value * 2 - 1 && colorBlending.Value == true)
                    {
                        finalPixel = PixelMix(argbCount);
                    }
                    else
                    {
                        finalPixel = MostCommonValue(argbCount);
                    }
                    newImage.SetPixelArgb(x, y, finalPixel);
                }
            }
            return(newImage);
        }
Exemplo n.º 13
0
        public FilterImage Execute(FilterImage input)
        {
            FilterImage newImage = new FilterImage(input.Width * scale.Value, input.Height * scale.Value);

            for (int x = 0; x < input.Width; x++)
            {
                for (int y = 0; y < input.Height; y++)
                {
                    int argb = input.PixelArgb(x, y);
                    for (int ix = 0; ix < scale.Value; ix++)
                    {
                        for (int iy = 0; iy < scale.Value; iy++)
                        {
                            newImage.SetPixelArgb(ix + x * scale.Value, iy + y * scale.Value, argb);
                        }
                    }
                }
            }
            return(newImage);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (commandManager.IsFilter(args[0]) && args.Length >= 3)
                {
                    Bitmap bmpSrc;
                    try
                    {
                        bmpSrc = new Bitmap(args[1], true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("err: " + e);
                        return;
                    }

                    FilterImage input = FilterImageConvert.FilterImageFromBitmap(bmpSrc);
                    bmpSrc.Dispose();

                    FilterImage output = new FilterImage(0, 0);

                    Console.Write(commandManager.ExecuteCommand(args[0], args.Skip(1).ToArray(), ref output, input));
                    Bitmap outputBitmap = FilterImageConvert.BitmapFromFilterImage(output);
                    outputBitmap.Save(args[2]);
                    outputBitmap.Dispose();
                }
                else
                {
                    Console.Write(commandManager.ExecuteCommand(args[0], args.Skip(1).ToArray()));
                }
            }
            else
            {
                Console.Write(commandManager.ExecuteCommand("List", new string[] { }));
            }
        }
Exemplo n.º 15
0
 public FilterImage Execute(FilterImage input)
 {
     return(input);
 }