コード例 #1
0
ファイル: Effects.cs プロジェクト: tbayart/gpu-image
        /// <summary>load image from disc, set texture and isize as side effect</summary>
        internal ImageTex LoadImage(String fileName)
        {
            //Console.WriteLine("LoadImage using graphicsDevice " + graphicsDevice.GetHashCode());
            ImageTex fileImage = new ImageTex(fileName, this);

            return(fileImage);
        }
コード例 #2
0
ファイル: Effects.cs プロジェクト: tbayart/gpu-image
        /// <summary>image processing render pass on entire image; given multiple input images, technique name, and parms</summary>
        public ImageTex Xrender(ImageTex[] inimages, String name, float[] parms)
        {
            FullTechnique technique = GetTechnique(name, parms);
            ImageTex      nimage    = Xrender(inimages, technique);

            return(nimage);
        }
コード例 #3
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
        /// <summary>Perform n sequential direct copies of image, mainly used for timing tests</summary>
        public ImageTex dd(int n)
        {
            ImageTex r = this;

            for (int i = 0; i < n; i++)
            {
                r = r.Xrender("dir");
            }
            return(r);
        }
コード例 #4
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
        /// <summary>Apply unsharp mask to image, with given radius, strength and threshold</summary>
        public ImageTex Unsharp(double r, double strength, double threshold)
        {
            int K = (int)Math.Ceiling(r);

            float[] gauss = Gauss(r);
            float[] p     = new float[3].Concat(gauss).ToArray();
            p[0] = p.Length;
            p[1] = (float)strength;
            p[2] = (float)threshold;
            ImageTex a = effects.Xrender(this, "Unsharp_" + K, p);

            return(a);
        }
コード例 #5
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
        /// <summary>Apply gaussian blur of image:  r is radius, allow drop to 0.05 at r</summary>
        public ImageTex Blur(double r)
        {
            if (r < 0)
            {
                r = 0;
            }
            int K = (int)Math.Ceiling(r);

            float[] gauss = Gauss(r);
            float[] p     = new float[4].Concat(gauss).ToArray();
            p[0] = p.Length;
            p[1] = K; p[2] = 0;
            p[3] = (float)gauss.Sum();
            ImageTex a = effects.Xrender(this, "conv", p);

            p[1] = 0; p[2] = K;
            return(effects.Xrender(a, "conv", p));
        }
コード例 #6
0
ファイル: Effects.cs プロジェクト: tbayart/gpu-image
        /// <summary>image processing render pass on entire image;
        /// given multiple input images, technique and transformation matrix and required output size
        /// </summary>
        internal ImageTex Xrender(ImageTex[] inimage, FullTechnique ftechnique, Matrix tran, int ssizeX, int ssizeY)
        {
            //*//if (dotime) timer.Start();
            EffectTechnique ltechnique = ftechnique.technique;
            Effect          effect     = ftechnique.effect;

            RenderTarget2D xxtarget;
            NextOp         op     = inimage[0].nextOpNew; // STD, ALT, SHARE, NEW
            int            isizeX = inimage[0].Width;
            int            isizeY = inimage[0].Height;

            if (ssizeX == 0)
            {
                ssizeX = isizeX;
            }
            if (ssizeY == 0)
            {
                ssizeY = isizeY;
            }

            switch (op)
            {
            case NextOp.STD: xxtarget = xtarget; break;

            case NextOp.ALT: xxtarget = xtarget1; break;

            case NextOp.SHARE: rtn++; xxtarget = rts[rtn % SIZE]; break;

            case NextOp.NEW: xxtarget = null; break;

            default: throw new Exception("Unexpected NewOp " + op);
            }
            SurfaceFormat sf = useVector4 ? SurfaceFormat.Vector4 : graphicsDevice.DisplayMode.Format;

            if (xxtarget == null || xxtarget.Width != ssizeX || xxtarget.Height != ssizeY || xxtarget.Format != sf)
            {
                // programming note:  TODO:
                // If the xxtarget is not the right size, I can't get things to work.
                // Even if it is too big and I cut it down with viewports.
                // This reallocation does not seem to matter too much with graphicsDevice.DisplayMode.Format,
                // but is a performance problem with SurfaceFormat.Vector4.
                // We probably don't need Vector4 too much anyway, but if we do we should cache a few RenderTargets for the case of size changing often
                // (this multisize case arises a lot in the scanline test code).
                // Console.WriteLine("xxsize " + ssizeX + " " + ssizeY);
                xxtarget = new RenderTarget2D(graphicsDevice, ssizeX, ssizeY, 1, sf);
                switch (op)
                {
                case NextOp.STD: xtarget = xxtarget; break;

                case NextOp.ALT: xtarget1 = xxtarget; break;

                case NextOp.SHARE: rts[rtn % SIZE] = xxtarget; break;

                case NextOp.NEW: break;

                default: throw new Exception("Unexpected NewOp " + op);
                }
            }

            Viewport savevp = graphicsDevice.Viewport;                         // this should match the screen size

            graphicsDevice.SetRenderTarget(0, xxtarget);                       // << note that this changes graphicsDevice.Viewport to xxtarget = image size

            graphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.Gray); // this processing should often cover entire image, so no need to clear


            float h = 0.5f;
            //Matrix mat = new Matrix(h, 0, 0, 0, 0, -h, 0, 0, 0, 0, 1, 0, h + h / isizeX, h + h / isizeY, 0, 1);
            //Matrix ss0 = new Matrix(1, 0, 0, 0, 0, isizeY * 1.0f / isizeX, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
            //Matrix ss1 = new Matrix(1, 0, 0, 0, 0, isizeX * 1.0f / isizeY, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
            //mat = mat * ss0 * tran * ss1; // *mat;
            Matrix mat = new Matrix(h, 0, 0, 0, 0, -h, 0, 0, 0, 0, 1, 0, h + h / isizeX, h + h / isizeY, 0, 1);

            mat = mat * tran; // *mat;
            effect.Parameters["TexProj"].SetValue(mat);
            effect.Parameters["isize"].SetValue(new Vector2(isizeX, isizeY));
            effect.Parameters["stepImageXy"].SetValue(inimage[0].stepImageXy);
            ftechnique.SetParameters();
            if (inimage.Length >= 1)
            {
                effect.Parameters["image"].SetValue(inimage[0].texture);
            }
            if (inimage.Length >= 2)
            {
                effect.Parameters["image2"].SetValue(inimage[1].texture);
            }
            if (inimage.Length >= 3)
            {
                effect.Parameters["image3"].SetValue(inimage[2].texture);
            }
            if (inimage.Length >= 4)
            {
                effect.Parameters["image4"].SetValue(inimage[3].texture);
            }

            RunEffect(effect);
            graphicsDevice.SetRenderTarget(0, null);  // << note that this changes graphicsDevice.Viewport to (large) backBuffer size
            Texture2D result = xxtarget.GetTexture();

            graphicsDevice.Viewport = savevp;         // restore the back buffer

            // ? timer not reliable, work not complete behind the scenes
            //*//if (dotime) timer.time(ltechnique.Name);
            // TODO: improve fid text
            ImageTex r = new ImageTex(inimage[0].fid + ";" + ltechnique, result, this, inimage[0].fileInfo + " " + ftechnique.Name);

            // r.Show();
            return(r);
        }
コード例 #7
0
ファイル: Effects.cs プロジェクト: tbayart/gpu-image
 /// <summary>image processing render pass on entire image; given input image and technique</summary>
 public ImageTex Xrender(ImageTex inimage, FullTechnique ltechnique)
 {
     return(Xrender(new ImageTex[] { inimage }, ltechnique));
 }
コード例 #8
0
ファイル: Effects.cs プロジェクト: tbayart/gpu-image
 /// <summary>image processing render pass on entire image; given input image, technique name</summary>
 public ImageTex Xrender(ImageTex inimage, String name)
 {
     return(Xrender(new ImageTex[] { inimage }, name, null));
 }
コード例 #9
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 public ImageTex(ImageTex i) : this(i.fid, i.texture, i.effects, i.fileInfo)
 {
 }
コード例 #10
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 /// <summary>multiply and add four images</summary>
 public ImageTex Mad(ImageTex b, ImageTex c, ImageTex d, float fa, float fb, float fc, float fd)
 {
     return(effects.Xrender(new ImageTex[] { this, b, c, d }, "mad", new float[] { 4, fa, fb, fc, fd }));
 }
コード例 #11
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 /// <summary>multiply and add three images</summary>
 public ImageTex Mad(ImageTex b, ImageTex c, float fa, float fb, float fc)
 {
     return(effects.Xrender(new ImageTex[] { this, b, c }, "mad", new float[] { 3, fa, fb, fc, 0 }));
 }
コード例 #12
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 /// <summary>multiply and add two images</summary>
 public ImageTex Mad(ImageTex b, float fa, float fb)
 {
     return(effects.Xrender(new ImageTex[] { this, b }, "mad", new float[] { 2, fa, fb, 0, 0 }));
 }
コード例 #13
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 /// <summary>Max of two images (pointwise)</summary>
 public ImageTex Max(ImageTex b)
 {
     return(effects.Xrender(new ImageTex[] { this, b }, "max"));
 }
コード例 #14
0
ファイル: Image.cs プロジェクト: tbayart/gpu-image
 /// <summary>Min of two images (pointwise)</summary>
 public ImageTex Min(ImageTex b)
 {
     return(effects.Xrender(new ImageTex[] { this, b }, "min"));
 }