private void ConvertImageAction()
        {
            ImageProcessingModel imageProcessingModel = new ImageProcessingModel();
            string fileNameForCovertedImage           = imageProcessingModel.ProcessImage(this.fileName, this.isAsync);

            this.ConvertedImage = new BitmapImage(new Uri(fileNameForCovertedImage));
            this.DurationTime   = string.Format("{0:hh}:{0:mm}:{0:ss}.{0:ffff}", imageProcessingModel.durationTimeSpan);
        }
 public void Setup()
 {
     imageProcessing = new ImageProcessingModel();
     fileNames       = new Dictionary <string, string>()
     {
         { "test.jpg", "test_converted.jpg" },
         { "test.png", "test_converted.png" },
         { "test.bmp", "test_converted.bmp" }
     };
 }
 public ImageViewModel(MainWindow _mainWindow)
 {
     ImageModel                     = new ImageProcessingModel();
     m_MainWindow                   = _mainWindow;
     this.LoadImageCommand          = new CommandBase(BrowseAndLoadAction, TrueFunc);
     this.SaveCommand               = new CommandBase(SaveAction, TrueFunc);
     this.ExitCommand               = new CommandBase(ExitAction, TrueFunc);
     this.WarningCommand            = new CommandBase(WarningAction, TrueFunc);
     ImageModel.IsSaveButtonEnabled = false;
 }
        public static InnerImageProcessingRenderer Create(string textureFilename = @"Textures\edgeDetection.bmp")
        {
            var model = new ImageProcessingModel();
            ShaderCode[] simpleShader = new ShaderCode[2];
            simpleShader[0] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.vert"), ShaderType.VertexShader);
            simpleShader[1] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.frag"), ShaderType.FragmentShader);
            var propertyNameMap = new AttributeMap();
            propertyNameMap.Add("vert", "position");
            propertyNameMap.Add("uv", "uv");
            var renderer = new InnerImageProcessingRenderer(
                model, simpleShader, propertyNameMap, ImageProcessingModel.strposition);
            renderer.textureFilename = textureFilename;

            return renderer;
        }
Esempio n. 5
0
        public ImageProcessingViewModel()
        {
            string path = @"E:\Downloads\eye.jpg";

            if (File.Exists(path))
            {
                imageModel = new ImageProcessingModel(path);
                RedrawImage();
            }

            updateBrightnessTimer = new Timer()
            {
                AutoReset = false,
                Interval  = 500,
            };
            updateBrightnessTimer.Elapsed += delegate(object o, ElapsedEventArgs e)
            {
                imageModel.SetBrightness(Brightness);
                RedrawImage();
            };

            updateConstrastTimer = new Timer()
            {
                AutoReset = false,
                Interval  = 500,
            };
            updateConstrastTimer.Elapsed += delegate(object o, ElapsedEventArgs e)
            {
                imageModel.SetConstrast(Contrast);
                RedrawImage();
            };

            updateBlurFilterTimer = new Timer()
            {
                AutoReset = false,
                Interval  = 500,
            };
            updateBlurFilterTimer.Elapsed += delegate(object o, ElapsedEventArgs e)
            {
                if (isBlur)
                {
                    imageModel.SetBlurFilter(isBlur, BlurFilterValue, IsGauss);
                    RedrawImage();
                }
            };
        }
        public static InnerImageProcessingRenderer Create(string textureFilename = @"Textures\edgeDetection.bmp")
        {
            var model = new ImageProcessingModel();

            ShaderCode[] simpleShader = new ShaderCode[2];
            simpleShader[0] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.vert"), ShaderType.VertexShader);
            simpleShader[1] = new ShaderCode(File.ReadAllText(@"shaders\ImageProcessingRenderer\ImageProcessing.frag"), ShaderType.FragmentShader);
            var propertyNameMap = new AttributeMap();

            propertyNameMap.Add("vert", "position");
            propertyNameMap.Add("uv", "uv");
            var renderer = new InnerImageProcessingRenderer(
                model, simpleShader, propertyNameMap, ImageProcessingModel.strposition);

            renderer.textureFilename = textureFilename;

            return(renderer);
        }
Esempio n. 7
0
 protected override void DoInitialize()
 {
     {
         var computeProgram = new ShaderProgram();
         var shaderCode     = new ShaderCode(File.ReadAllText(
                                                 @"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader);
         var shader = shaderCode.CreateShader();
         computeProgram.Create(shader);
         shader.Delete();
         this.computeProgram = computeProgram;
     }
     {
         Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename);
         if (bitmap.Width != 512 || bitmap.Height != 512)
         {
             bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero);
         }
         OpenGL.GenTextures(1, this.input_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]);
         //  Lock the image bits (so that we can pass them to OGL).
         BitmapData bitmapData = bitmap.LockBits(
             new Rectangle(0, 0, bitmap.Width, bitmap.Height),
             ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F,
                           bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                           bitmapData.Scan0);
         //  Unlock the image.
         bitmap.UnlockBits(bitmapData);
         /* We require 1 byte alignment when uploading texture data */
         //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
         /* Clamping to edges is important to prevent artifacts when scaling */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
         /* Linear filtering usually looks best for text */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
         bitmap.Dispose();
     }
     {
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.intermediate_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         // This is the texture that the compute program will write into
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.output_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         var          bufferable   = new ImageProcessingModel();
         ShaderCode[] simpleShader = new ShaderCode[2];
         simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader);
         simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("vert", "position");
         propertyNameMap.Add("uv", "uv");
         var pickableRenderer = new PickableRenderer(
             bufferable, simpleShader, propertyNameMap, "position");
         pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]");
         pickableRenderer.Initialize();
         pickableRenderer.SetUniform("output_image",
                                     new samplerValue(
                                         BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0));
         this.renderer = pickableRenderer;
     }
 }
 protected override void DoInitialize()
 {
     {
         var computeProgram = new ShaderProgram();
         var shaderCode = new ShaderCode(File.ReadAllText(
             @"06ImageProcessing\ImageProcessing.comp"), ShaderType.ComputeShader);
         var shader = shaderCode.CreateShader();
         computeProgram.Create(shader);
         shader.Delete();
         this.computeProgram = computeProgram;
     }
     {
         Bitmap bitmap = new System.Drawing.Bitmap(this.textureFilename);
         if (bitmap.Width != 512 || bitmap.Height != 512)
         {
             bitmap = (Bitmap)bitmap.GetThumbnailImage(512, 512, null, IntPtr.Zero);
         }
         OpenGL.GenTextures(1, this.input_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.input_image[0]);
         //  Lock the image bits (so that we can pass them to OGL).
         BitmapData bitmapData = bitmap.LockBits(
             new Rectangle(0, 0, bitmap.Width, bitmap.Height),
             ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA32F,
             bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
             bitmapData.Scan0);
         //  Unlock the image.
         bitmap.UnlockBits(bitmapData);
         /* We require 1 byte alignment when uploading texture data */
         //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
         /* Clamping to edges is important to prevent artifacts when scaling */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
         /* Linear filtering usually looks best for text */
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
         OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
         bitmap.Dispose();
     }
     {
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.intermediate_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.intermediate_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         // This is the texture that the compute program will write into
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GenTextures(1, this.output_image);
         OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, this.output_image[0]);
         OpenGL.TexStorage2D(TexStorage2DTarget.Texture2D, 8, OpenGL.GL_RGBA32F, 512, 512);
     }
     {
         var bufferable = new ImageProcessingModel();
         ShaderCode[] simpleShader = new ShaderCode[2];
         simpleShader[0] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.vert"), ShaderType.VertexShader);
         simpleShader[1] = new ShaderCode(File.ReadAllText(@"06ImageProcessing\ImageProcessing.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("vert", "position");
         propertyNameMap.Add("uv", "uv");
         var pickableRenderer = new PickableRenderer(
             bufferable, simpleShader, propertyNameMap, "position");
         pickableRenderer.Name = string.Format("Pickable: [ImageProcessingRenderer]");
         pickableRenderer.Initialize();
         pickableRenderer.SetUniform("output_image",
             new samplerValue(
                 BindTextureTarget.Texture2D, this.output_image[0], OpenGL.GL_TEXTURE0));
         this.renderer = pickableRenderer;
     }
 }