示例#1
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
                    {
                    }
                }
            }
        }
示例#2
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);
        }
示例#3
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);
    }
示例#5
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);
        }
示例#7
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;
		}
示例#8
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 ();
				}
			}
		}
示例#9
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; 
			}
		}