コード例 #1
0
		public bool Convert (FilterRequest req)
		{
			string source = req.Current.LocalPath;
			Uri dest = req.TempUri (Path.GetExtension (source));
			
			using (ImageFile img = ImageFile.Create (source)) {
				using (Pixbuf pixbuf = img.Load ()) {
					using (ImageInfo info = new ImageInfo (pixbuf)) {
						MemorySurface surface = new MemorySurface (Format.Argb32, 
											   pixbuf.Width,
											   pixbuf.Height);
	
						Context ctx = new Context (surface);
						ctx.Matrix = info.Fill (info.Bounds, angle);
						Pattern p = new SurfacePattern (info.Surface);
						ctx.Source = p;
						ctx.Paint ();
						((IDisposable)ctx).Dispose ();
						p.Destroy ();
						using (Pixbuf result = CairoUtils.CreatePixbuf (surface)) {
							using (Stream output = File.OpenWrite (dest.LocalPath)) {
								img.Save (result, output);
							}
						}
						surface.Flush ();
						info.Dispose ();
						req.Current = dest;
						return true;
					}
				}
			}
		}
コード例 #2
0
        public Texture(Gdk.Pixbuf pixbuf)
            : this(pixbuf.Width, pixbuf.Height)
        {
            MemorySurface surface = CairoUtils.CreateSurface(pixbuf);

            CopyFromSurface(surface);
            surface.Destroy();
        }
コード例 #3
0
		public int CopyFromSurface (MemorySurface surface)
		{
			Bind ();

			int max_size;
			Gl.glGetIntegerv (Gl.GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, out max_size);
			float scale = (float)Math.Min (1.0, max_size / (double) Math.Max (width, height));
			//Log.DebugFormat ("max texture size {0} scaling to {1}", max_size, scale);
			
			if (surface.DataPtr == IntPtr.Zero)
				throw new TextureException ("Surface has no data");

			if (surface.Format != Format.Rgb24 && surface.Format != Format.Argb32)
				throw new TextureException ("Unsupported format type");

			IntPtr pixels = surface.DataPtr;
			IntPtr tmp = IntPtr.Zero;
			if (scale != 1.0) {
				int swidth = (int)(width * scale);
				int sheight = (int) (height * scale);
				tmp = Marshal.AllocHGlobal (swidth * sheight * 4);
				//LogDebugFormat ("scaling image {0} x {1}", swidth, sheight);

				Glu.gluScaleImage (Gl.GL_BGRA,
						  width,
						  height,
						  Gl.GL_UNSIGNED_INT_8_8_8_8_REV,
						  pixels,
						  swidth,
						  sheight,
						  Gl.GL_UNSIGNED_INT_8_8_8_8_REV,
						  tmp);
				pixels = tmp;
				width = swidth;
				height = sheight;
			}
			
			Gl.glTexImage2D (Gl.GL_TEXTURE_RECTANGLE_ARB,
					 0,
					 Gl.GL_RGBA,
					 width,
					 height,
					 0,
					 Gl.GL_BGRA,
					 Gl.GL_UNSIGNED_INT_8_8_8_8_REV,
					 pixels);
			

			if (tmp != IntPtr.Zero)
				Marshal.FreeHGlobal (tmp);

			if (Gl.glGetError () != Gl.GL_NO_ERROR)
				Log.Warning ("unable to allocate texture");
			//	throw new TextureException ("Unable to allocate texture resources");

			return texture_id;
		}
コード例 #4
0
		public static Gdk.Pixbuf CreatePixbuf (MemorySurface mem)
		{
			IntPtr result = NativeMethods.f_pixbuf_from_cairo_surface (mem.Handle);
			return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
		}
コード例 #5
0
 public Texture(MemorySurface surface)
     : this(surface.Width, surface.Height)
 {
     CopyFromSurface(surface);
 }
コード例 #6
0
        public int CopyFromSurface(MemorySurface surface)
        {
            Bind();

            int max_size;

            Gl.glGetIntegerv(Gl.GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, out max_size);
            float scale = (float)Math.Min(1.0, max_size / (double)Math.Max(width, height));

            System.Console.WriteLine("max texture size {0} scaling to {1}", max_size, scale);

            if (surface.Pixels == IntPtr.Zero)
            {
                throw new TextureException("Surface has no data");
            }

            if (surface.Format != Format.Rgb24 && surface.Format != Format.Argb32)
            {
                throw new TextureException("Unsupported format type");
            }

            IntPtr pixels = surface.Pixels;
            IntPtr tmp    = IntPtr.Zero;

            if (scale != 1.0)
            {
                int swidth  = (int)(width * scale);
                int sheight = (int)(height * scale);
                tmp = Marshal.AllocHGlobal(swidth * sheight * 4);
                System.Console.WriteLine("scaling image {0} x {1}", swidth, sheight);

                Glu.gluScaleImage(Gl.GL_BGRA,
                                  width,
                                  height,
                                  Gl.GL_UNSIGNED_BYTE,
                                  pixels,
                                  swidth,
                                  sheight,
                                  Gl.GL_UNSIGNED_BYTE,
                                  tmp);
                pixels = tmp;
                width  = swidth;
                height = sheight;
            }

            Gl.glTexImage2D(Gl.GL_TEXTURE_RECTANGLE_ARB,
                            0,
                            Gl.GL_RGBA,
                            width,
                            height,
                            0,
                            Gl.GL_BGRA,
                            Gl.GL_UNSIGNED_BYTE,
                            pixels);


            if (tmp != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(tmp);
            }

            if (Gl.glGetError() != Gl.GL_NO_ERROR)
            {
                System.Console.WriteLine("unable to allocate texture");
            }
            //	throw new TextureException ("Unable to allocate texture resources");

            return(texture_id);
        }
コード例 #7
0
		public Texture (MemorySurface surface) 
			: this (surface.Width, surface.Height)
		{
			CopyFromSurface (surface);
		}
コード例 #8
0
        public static Gdk.Pixbuf CreatePixbuf(MemorySurface mem)
        {
            IntPtr result = NativeMethods.f_pixbuf_from_cairo_surface(mem.Handle);

            return((Gdk.Pixbuf)GLib.Object.GetObject(result, true));
        }