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;
    }
Ejemplo n.º 2
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
                    {
                    }
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
        }
    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);
    }
Ejemplo n.º 6
0
        public Pixbuf Load(System.IO.Stream stream, ImageOrientation orientation)
        {
            int count;

            byte [] data = new byte [8192];
            while (((count = stream.Read(data, 0, data.Length)) > 0) && loader.Write(data, (ulong)count))
            {
                ;
            }

            loader.Close();
            Pixbuf orig = loader.Pixbuf;

            Gdk.Pixbuf rotated = FSpot.Utils.PixbufUtils.TransformOrientation(orig, orientation);

            if (orig != rotated)
            {
                orig.Dispose();
            }
            loader.Dispose();
            return(rotated);
        }
        public Pixbuf Load(System.IO.Stream stream, PixbufOrientation orientation)
        {
            int count;

            byte [] data = new byte [8192];
            while (((count = stream.Read(data, 0, data.Length)) > 0) && loader.Write(data, (ulong)count))
            {
                ;
            }

            loader.Close();
            Pixbuf orig = loader.Pixbuf;

            Gdk.Pixbuf rotated = TransformOrientation(orig, orientation, true);

            if (orig != rotated)
            {
                CopyThumbnailOptions(orig, rotated);
                orig.Dispose();
            }
            loader.Dispose();
            return(rotated);
        }
Ejemplo n.º 8
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
            }
        }
Ejemplo n.º 9
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
    }
Ejemplo n.º 10
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;
		}
Ejemplo n.º 11
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 ();
				}
			}
		}
Ejemplo n.º 12
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; 
			}
		}
Ejemplo n.º 13
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;
	}
Ejemplo n.º 14
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
    }