示例#1
0
 public Pixbuf(System.IO.Stream stream, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (stream, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#2
0
 public Pixbuf(System.Reflection.Assembly assembly, string resource, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#3
0
 public Pixbuf(System.IO.Stream stream, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (stream, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#4
0
 public Pixbuf(System.IO.Stream stream)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (stream)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#5
0
 public Pixbuf(System.Reflection.Assembly assembly, string resource, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (assembly == null ? System.Reflection.Assembly.GetCallingAssembly () : assembly, resource, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#6
0
 public Pixbuf(byte[] buffer)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (buffer)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#7
0
 public Pixbuf(byte[] buffer, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (buffer, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#8
0
 public Pixbuf(byte[] buffer)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (buffer)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#9
0
        private void load(string filename)
        {
            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
                long   length;
                bool   done;
                long   pos;
                byte[] buffer;

                length          = fs.Length;
                compressed_data = new byte[length];
                fs.Read(compressed_data, 0, (int)length);

                /* Feed small chunks at a time to a pixbuf loader until
                 * it emits the "size-prepared" signal.  This lets us
                 * avoid uncompressing the whole image just to figure
                 * out its size.
                 */

                using (Gdk.PixbufLoader loader = new Gdk.PixbufLoader()) {
                    loader.SizePrepared += new SizePreparedHandler(
                        delegate(object o, SizePreparedArgs args) {
                        done   = true;
                        width  = args.Width;
                        height = args.Height;
                    });

                    done   = false;
                    pos    = 0;
                    buffer = new byte[512];

                    while (!done)
                    {
                        long to_copy;

                        to_copy = length - pos;
                        if (to_copy > 512)
                        {
                            to_copy = 512;
                        }
                        else if (to_copy == 0)
                        {
                            break;
                        }

                        Array.Copy(compressed_data, pos, buffer, 0, to_copy);
                        loader.Write(buffer);

                        pos += to_copy;
                    }

                    try
                    {
                        loader.Close();
                    }
                    catch
                    {
                    }
                }
            }
        }
示例#10
0
 public Pixbuf(System.IO.Stream stream)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (stream)) {
         Raw = pl.PixbufHandle;
     }
 }
    static public void GetSize(string path, out int width, out int height)
    {
        Gdk.PixbufLoader loader = new Gdk.PixbufLoader();
        int  orig_width         = 0;
        int  orig_height        = 0;
        bool done = false;

        loader.SizePrepared += delegate(object obj, SizePreparedArgs args) {
            orig_width  = args.Width;
            orig_height = args.Height;
            done        = true;
        };

        using (Stream stream = File.OpenRead(path)) {
            byte [] data = new byte [4096];
            int     count;

            while (((count = stream.Read(data, 0, data.Length)) > 0) && loader.Write(data, (ulong)count))
            {
                if (done)
                {
                    break;
                }
            }
        }

        width  = orig_width;
        height = orig_height;
    }
示例#12
0
 public Pixbuf(byte[] buffer, int width, int height)
     : base(IntPtr.Zero)
 {
     using (PixbufLoader pl = new PixbufLoader (buffer, width, height)) {
         Raw = pl.PixbufHandle;
     }
 }
示例#13
0
 public PixbufAnimation(System.Reflection.Assembly assembly, string resource) : base(IntPtr.Zero)
 {
     if (assembly == null)
     {
         assembly = System.Reflection.Assembly.GetCallingAssembly();
     }
     Raw = new PixbufLoader(assembly, resource).AnimationHandle;
 }
示例#14
0
 static void Closed_cb(IntPtr inst)
 {
     try {
         PixbufLoader __obj = GLib.Object.GetObject(inst, false) as PixbufLoader;
         __obj.OnClosed();
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
示例#15
0
 static void AreaUpdated_cb(IntPtr inst, int x, int y, int width, int height)
 {
     try {
         PixbufLoader __obj = GLib.Object.GetObject(inst, false) as PixbufLoader;
         __obj.OnAreaUpdated(x, y, width, height);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
示例#16
0
 static void SizePrepared_cb(IntPtr inst, int width, int height)
 {
     try {
         PixbufLoader __obj = GLib.Object.GetObject(inst, false) as PixbufLoader;
         __obj.OnSizePrepared(width, height);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
示例#17
0
		public static unsafe PixbufLoader NewWithType(string image_type)
		{
			IntPtr native_image_type = GLib.Marshaller.StringToPtrGStrdup (image_type);
			IntPtr error = IntPtr.Zero;
			PixbufLoader result = new PixbufLoader (gdk_pixbuf_loader_new_with_type(native_image_type, out error));
			GLib.Marshaller.Free (native_image_type);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return result;
		}
示例#18
0
        public static unsafe bool Close(this PixbufLoader loader, bool force)
        {
            var  error   = IntPtr.Zero;
            bool raw_ret = gdk_pixbuf_loader_close(loader.Handle, out error);
            bool ret     = raw_ret;

            if (!force && error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
示例#19
0
        // Copied from f-spot
        // These should eventually appear in Gtk#
        private static Pixbuf LoadFromStream(System.IO.Stream input)
        {
            Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
            byte [] buffer = new byte [8192];
            ulong n;

            while ((n = (ulong) input.Read (buffer, 0, 8192)) != 0)
                loader.Write (buffer, n);

            loader.Close ();
            return loader.Pixbuf;
        }
示例#20
0
        public Gdk.Pixbuf MakePixbufFromCompressedData()
        {
            Gdk.Pixbuf pixbuf;

            using (Gdk.PixbufLoader loader = new Gdk.PixbufLoader()) {
                loader.Write(compressed_data);
                loader.Close();
                pixbuf = loader.Pixbuf;
            }

            return(pixbuf);
        }
示例#21
0
        public static unsafe PixbufLoader NewWithType(string image_type)
        {
            IntPtr       native_image_type = GLib.Marshaller.StringToPtrGStrdup(image_type);
            IntPtr       error             = IntPtr.Zero;
            PixbufLoader result            = new PixbufLoader(gdk_pixbuf_loader_new_with_type(native_image_type, out error));

            GLib.Marshaller.Free(native_image_type);
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(result);
        }
示例#22
0
 void LoadRemoteIcon(TreeIter it, string iconId, AddinRepositoryEntry arep, IAsyncResult res, AddinHeader info, object dataItem, AddinStatus status)
 {
     if (!disposed && treeStore.IterIsValid(it))
     {
         Gdk.Pixbuf customPix = null;
         try {
             Gdk.PixbufLoader loader = new Gdk.PixbufLoader(arep.EndDownloadSupportFile(res));
             customPix = loader.Pixbuf;
         } catch (Exception ex) {
             Console.WriteLine(ex);
         }
         cachedIcons [iconId] = customPix;
         StoreIcon(it, iconId, customPix, status);
     }
 }
    static public Pixbuf LoadFromStream(System.IO.Stream input)
    {
        Gdk.PixbufLoader loader = new Gdk.PixbufLoader();
        byte []          buffer = new byte [8192];
        int n;

        while ((n = input.Read(buffer, 0, 8192)) != 0)
        {
            loader.Write(buffer, (ulong)n);
        }

        loader.Close();

        return(loader.Pixbuf);
    }
示例#24
0
        public static Pixbuf LoadThumbnail(SafeUri uri, ThumbnailSize size, PixbufLoader loader)
        {
            var thumb_uri = ThumbUri (uri, size);
            var pixbuf = LoadFromUri (thumb_uri);
            if (!IsValid (uri, pixbuf)) {
                Log.DebugFormat ("Invalid thumbnail, reloading: {0}", uri);
                if (pixbuf != null)
                    pixbuf.Dispose ();

                if (loader == null)
                    return null;

                pixbuf = CreateFrom (uri, thumb_uri, size, loader);
            }
            return pixbuf;
        }
示例#25
0
        // TODO: Decide if we want to perform the same crazy error handling
        // gtk-demo does
        private bool ProgressiveTimeout()
        {
            if (imageStream == null)
            {
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("alphatest.png");
                imageStream  = new BinaryReader(stream);
                pixbufLoader = new Gdk.PixbufLoader();
                pixbufLoader.AreaPrepared += new EventHandler(ProgressivePreparedCallback);
                pixbufLoader.AreaUpdated  += new AreaUpdatedHandler(ProgressiveUpdatedCallback);
            }

            if (imageStream.PeekChar() != -1)
            {
                byte[] bytes = imageStream.ReadBytes(256);
                pixbufLoader.Write(bytes);
                return(true);                // leave the timeout active
            }
            else
            {
                imageStream.Close();
                return(false);                // removes the timeout
            }
        }
示例#26
0
    static public void GetSize(string path, out int width, out int height)
    {
#if true
        using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(path)) {
            width  = pixbuf.Width;
            height = pixbuf.Height;
        }
#else //yes, the pixbuf loader hack is smarter, but it leaks like an old women
        Gdk.PixbufLoader loader = new Gdk.PixbufLoader();
        int  orig_width         = 0;
        int  orig_height        = 0;
        bool done = false;

        loader.SizePrepared += delegate(object obj, SizePreparedArgs args) {
            orig_width  = args.Width;
            orig_height = args.Height;
            done        = true;
        };

        using (Stream stream = File.OpenRead(path)) {
            byte [] data = new byte [4096];
            int     count;

            while (((count = stream.Read(data, 0, data.Length)) > 0) && loader.Write(data, (ulong)count))
            {
                if (done)
                {
                    break;
                }
            }
        }

        width  = orig_width;
        height = orig_height;
#endif
    }
示例#27
0
    public static void GetSize(string path, out int width, out int height)
    {
        #if true
        using (Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (path)) {
            width = pixbuf.Width;
            height = pixbuf.Height;
        }
        #else //yes, the pixbuf loader hack is smarter, but it leaks like an old women
        Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
        int orig_width = 0;
        int orig_height = 0;
        bool done = false;

        loader.SizePrepared += delegate (object obj, SizePreparedArgs args) {
            orig_width = args.Width;
            orig_height = args.Height;
            done = true;
        };

        using (Stream stream = File.OpenRead (path)) {
            byte [] data = new byte [4096];
            int count;

            while (((count = stream.Read (data, 0, data.Length)) > 0) && loader.Write (data, (ulong)count)) {
                if (done)
                    break;
            }
        }

        width = orig_width;
        height = orig_height;
        #endif
    }
示例#28
0
 public static Gdk.Pixbuf LoadFromStream (System.IO.Stream stream)
 {
     using (var loader = new Gdk.PixbufLoader (stream))
         return loader.Pixbuf;
 }
示例#29
0
        private static Pixbuf CreateFrom(SafeUri uri, SafeUri thumb_uri, ThumbnailSize size, PixbufLoader loader)
        {
            var pixels = size == ThumbnailSize.Normal ? 128 : 256;
            Pixbuf pixbuf;
            try {
                pixbuf = loader (uri);
            } catch (Exception e) {
                Log.DebugFormat ("Failed loading image for thumbnailing: {0}", uri);
                Log.DebugException (e);
                return null;
            }
            double scale_x = (double) pixbuf.Width / pixels;
            double scale_y = (double) pixbuf.Height / pixels;
            double scale = Math.Max (1.0, Math.Max (scale_x, scale_y));
            int target_x = (int) (pixbuf.Width / scale);
            int target_y = (int) (pixbuf.Height / scale);
            var thumb_pixbuf = pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear);
            pixbuf.Dispose ();

            var file = GLib.FileFactory.NewForUri (uri);
            var info = file.QueryInfo ("time::modified", GLib.FileQueryInfoFlags.None, null);
            var mtime = info.GetAttributeULong ("time::modified").ToString ();

            thumb_pixbuf.Savev (thumb_uri.LocalPath, "png",
                                new string [] {ThumbUriOpt, ThumbMTimeOpt, null},
                                new string [] {uri, mtime});

            return thumb_pixbuf;
        }
示例#30
0
	static public void GetSize (string path, out int width, out int height)
	{
		Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
		int orig_width = 0;
		int orig_height = 0;
		bool done = false;

		loader.SizePrepared += delegate (object obj, SizePreparedArgs args) {
			orig_width = args.Width;
			orig_height = args.Height;
			done = true;
		};
		
		using (Stream stream = File.OpenRead (path)) {
			byte [] data = new byte [4096];
			int count;

			while (((count = stream.Read (data, 0, data.Length)) > 0) && loader.Write (data, (ulong)count)) {
				if (done)
					break;
			}
		}
		
		width = orig_width;
		height = orig_height;
	}
		void HandlePixbufLoaded (PixbufLoader pl, Uri uri, int order, Pixbuf p) {
			if (!thumb_cache.Contains (FSpot.ThumbnailGenerator.ThumbnailPath (uri))) {
				return;
			}
			
			//FIXME use QueueDrawArea
			//FIXME only invalidate if displayed
			QueueDraw ();
			

		}
示例#32
0
		// TODO: Decide if we want to perform the same crazy error handling
		// gtk-demo does
		private bool ProgressiveTimeout ()
		{
			if (imageStream == null) {
				Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("alphatest.png");
				imageStream = new BinaryReader (stream);
				pixbufLoader = new Gdk.PixbufLoader ();
				pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
				pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
			}

			if (imageStream.PeekChar () != -1) {
				byte[] bytes = imageStream.ReadBytes (256);
				pixbufLoader.Write (bytes);
				return true; // leave the timeout active
			} else {
				imageStream.Close ();
				return false; // removes the timeout
			}
		}
示例#33
0
 void LoadRemoteIcon(TreeIter it, string iconId, AddinRepositoryEntry arep, IAsyncResult res, AddinHeader info, object dataItem, AddinStatus status)
 {
     if (!disposed && treeStore.IterIsValid (it)) {
         Gdk.Pixbuf customPix = null;
         try {
             Gdk.PixbufLoader loader = new Gdk.PixbufLoader (arep.EndDownloadSupportFile (res));
             customPix = loader.Pixbuf;
         } catch (Exception ex) {
             Console.WriteLine (ex);
         }
         cachedIcons [iconId] = customPix;
         StoreIcon (it, iconId, customPix, status);
     }
 }
示例#34
0
        protected override void OnDestroyed()
        {
            if (timeout_id != 0) {
                GLib.Source.Remove (timeout_id);
                timeout_id = 0;
            }

            if (pixbufLoader != null) {
                pixbufLoader.Close ();
                pixbufLoader = null;
            }

            if (imageStream != null) {
                imageStream.Close ();
                imageStream = null;
            }
        }
示例#35
0
		private void load (string filename)
		{
			using (FileStream fs = new FileStream (filename, FileMode.Open, FileAccess.Read)) {
				long length;
				bool done;
				long pos;
				byte[] buffer;

				length = fs.Length;
				compressed_data = new byte[length];
				fs.Read (compressed_data, 0, (int) length);

				/* Feed small chunks at a time to a pixbuf loader until
				 * it emits the "size-prepared" signal.  This lets us
				 * avoid uncompressing the whole image just to figure
				 * out its size.
				 */

				using (Gdk.PixbufLoader loader = new Gdk.PixbufLoader ()) {
					loader.SizePrepared += new SizePreparedHandler (
						delegate (object o, SizePreparedArgs args) {
							done = true;
							width = args.Width;
							height = args.Height;
						});

					done = false;
					pos = 0;
					buffer = new byte[512];

					while (!done) {
						long to_copy;

						to_copy = length - pos;
						if (to_copy > 512)
							to_copy = 512;
						else if (to_copy == 0)
							break;

						Array.Copy (compressed_data, pos, buffer, 0, to_copy);
						loader.Write (buffer);

						pos += to_copy;
					}

					loader.Close ();
				}
			}
		}
示例#36
0
		public Gdk.Pixbuf LoadJpegInterchangeFormat (ImageDirectory directory)
		{
			uint offset = directory.Lookup (TagId.JPEGInterchangeFormat).ValueAsLong [0];
			uint length = directory.Lookup (TagId.JPEGInterchangeFormatLength).ValueAsLong [0];
			   
			using (System.IO.Stream file = Open ()) {
				file.Position = offset;
				
				byte [] data = new byte [32768];
				int read;

				Gdk.PixbufLoader loader = new Gdk.PixbufLoader ();
				
				while (length > 0) {
					read = file.Read (data, 0, (int)System.Math.Min ((int)data.Length, length));
					if (read <= 0)
						break;

					loader.Write (data, (ulong)read);
					length -= (uint) read;
				}
				Gdk.Pixbuf result = loader.Pixbuf;
				loader.Close ();
				return result; 
			}
		}
示例#37
0
		public PixbufAnimation (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero)
		{
			if (assembly == null)
				assembly = System.Reflection.Assembly.GetCallingAssembly ();
			Raw = new PixbufLoader (assembly, resource).AnimationHandle;
		}
示例#38
0
		public Gdk.Pixbuf MakePixbufFromCompressedData ()
		{
			Gdk.Pixbuf pixbuf;

			using (Gdk.PixbufLoader loader = new Gdk.PixbufLoader ()) {
				loader.Write (compressed_data);
				loader.Close ();
				pixbuf = loader.Pixbuf;
			}

			return pixbuf;
		}
示例#39
0
 public static Gdk.Pixbuf LoadFromStream(System.IO.Stream stream)
 {
     using (var loader = new Gdk.PixbufLoader(stream))
         return(loader.Pixbuf);
 }