public static Gdk.Rectangle TransformAndCopy(Gdk.Pixbuf src, Gdk.Pixbuf dest, PixbufOrientation orientation, Gdk.Rectangle args)
    {
        Gdk.Rectangle area = TransformOrientation(src, args, orientation);

        int step = 256;

        Gdk.Rectangle rect = new Gdk.Rectangle(args.X, args.Y,
                                               Math.Min(step, args.Width),
                                               Math.Min(step, args.Height));

        Gdk.Rectangle trect = TransformOrientation(src, rect, orientation);
        Gdk.Pixbuf    tmp   = new Gdk.Pixbuf(src.Colorspace, src.HasAlpha,
                                             src.BitsPerSample,
                                             trect.Width, trect.Height);

        Gdk.Rectangle  subarea;
        BlockProcessor proc = new BlockProcessor(args, 256);

        while (proc.Step(out subarea))
        {
            Gdk.Rectangle trans = TransformOrientation(src, subarea, orientation);
            Gdk.Pixbuf    ssub  = new Gdk.Pixbuf(src, subarea.X, subarea.Y,
                                                 subarea.Width, subarea.Height);

            Gdk.Pixbuf tsub = new Gdk.Pixbuf(tmp, 0, 0, trans.Width, trans.Height);
            CopyWithOrientation(ssub, tsub, orientation);

            tsub.CopyArea(0, 0, trans.Width, trans.Height, dest, trans.X, trans.Y);
            ssub.Dispose();
            tsub.Dispose();
        }

        tmp.Dispose();
        return(area);
    }
 static public PixbufOrientation Rotate90(PixbufOrientation orientation)
 {
     orientation = Rotate270(orientation);
     orientation = Rotate270(orientation);
     orientation = Rotate270(orientation);
     return(orientation);
 }
Пример #3
0
	static public PixbufOrientation Rotate90 (PixbufOrientation orientation)
	{
		orientation = Rotate270 (orientation);
		orientation = Rotate270 (orientation);
		orientation = Rotate270 (orientation);
		return orientation;
	}
Пример #4
0
        public override PixbufOrientation GetOrientation()
        {
            PixbufOrientation orientation = PixbufOrientation.TopLeft;

#if USE_TIFF
            try {
                DirectoryEntry e = ExifHeader.Directory.Lookup(TagId.Orientation);
                orientation = (PixbufOrientation)e.ValueAsLong [0];
            } catch {
                System.Console.WriteLine("error checking orientation");
            }
#else
            Exif.ExifEntry e = this.ExifData.GetContents(Exif.Ifd.Zero).Lookup(Exif.Tag.Orientation);

            if (e != null)
            {
                ushort [] value = e.GetDataUShort();
                orientation = (PixbufOrientation)value [0];
            }
#endif
            if (orientation < PixbufOrientation.TopLeft || orientation > PixbufOrientation.LeftBottom)
            {
                orientation = PixbufOrientation.TopLeft;
            }

            return(orientation);
        }
Пример #5
0
            public void TestSave()
            {
                string            desc   = "this is an example description";
                string            desc2  = "\x00a9 Novell Inc.";
                PixbufOrientation orient = PixbufOrientation.TopRight;

                Gdk.Pixbuf test = new Gdk.Pixbuf(null, "f-spot-32.png");
                string     path = ImageFile.TempPath("joe.jpg");

                PixbufUtils.SaveJpeg(test, path, 75, new Exif.ExifData());
                JpegFile jimg = new JpegFile(path);

                jimg.SetDescription(desc);
                jimg.SetOrientation(orient);
                jimg.SaveMetaData(path);
                JpegFile mod = new JpegFile(path);

                Assert.AreEqual(mod.Orientation, orient);
                Assert.AreEqual(mod.Description, desc);
                jimg.SetDescription(desc2);
                jimg.SaveMetaData(path);
                mod = new JpegFile(path);
                Assert.AreEqual(mod.Description, desc2);

                File.Delete(path);
            }
Пример #6
0
        private static void RotateOrientation(string original_path, RotateDirection direction)
        {
            using (FSpot.ImageFile img = FSpot.ImageFile.Create(original_path)) {
                if (img is JpegFile)
                {
                    FSpot.JpegFile    jimg        = img as FSpot.JpegFile;
                    PixbufOrientation orientation = direction == RotateDirection.Clockwise
                                                ? PixbufUtils.Rotate90(img.Orientation)
                                                : PixbufUtils.Rotate270(img.Orientation);

                    jimg.SetOrientation(orientation);
                    jimg.SaveMetaData(original_path);
                }
                else if (img is PngFile)
                {
                    PngFile png       = img as PngFile;
                    bool    supported = false;

                    //FIXME there isn't much png specific here except the check
                    //the pixbuf is an accurate representation of the real file
                    //by checking the depth.  The check should be abstracted and
                    //this code made generic.
                    foreach (PngFile.Chunk c in png.Chunks)
                    {
                        PngFile.IhdrChunk ihdr = c as PngFile.IhdrChunk;

                        if (ihdr != null && ihdr.Depth == 8)
                        {
                            supported = true;
                        }
                    }

                    if (!supported)
                    {
                        throw new RotateException("Unable to rotate photo type", original_path);
                    }

                    string backup = ImageFile.TempPath(original_path);
                    using (Stream stream = File.Open(backup, FileMode.Truncate, FileAccess.Write)) {
                        using (Pixbuf pixbuf = img.Load()) {
                            PixbufOrientation fake = (direction == RotateDirection.Clockwise) ? PixbufOrientation.RightTop : PixbufOrientation.LeftBottom;
                            using (Pixbuf rotated = PixbufUtils.TransformOrientation(pixbuf, fake)) {
                                img.Save(rotated, stream);
                            }
                        }
                    }
                    File.Copy(backup, original_path, true);
                    File.Delete(backup);
                }
                else
                {
                    throw new RotateException("Unable to rotate photo type", original_path);
                }
            }
        }
 public Pixbuf LoadFromFile(string path)
 {
     try {
         orientation = GetOrientation(path);
         using (FileStream fs = File.OpenRead(path)) {
             return(Load(fs, orientation));
         }
     } catch (Exception) {
         System.Console.WriteLine("Error loading photo {0}", path);
         return(null);
     }
 }
Пример #8
0
        public void SetOrientation(PixbufOrientation orientation)
        {
            Exif.ExifEntry e = this.ExifData.GetContents(Exif.Ifd.Zero).GetEntry(Exif.Tag.Orientation);
            // System.Console.WriteLine ("Saving orientation as {0}", orientation);
            e.SetData((ushort)orientation);

            e = this.ExifData.GetContents(Exif.Ifd.One).Lookup(Exif.Tag.Orientation);
            if (e != null)
            {
                e.SetData((ushort)orientation);
            }
        }
		public static PixbufOrientation GetViewOrientation (PixbufOrientation po)
		{
			if (timer == 0 && available)
				SetupAccelerometer ();
				
			if (current_orientation == Orient.TiltCounterclockwise)
				return PixbufUtils.Rotate90 (po);

			if (current_orientation == Orient.TiltClockwise)
				return PixbufUtils.Rotate270 (po);

			return po;
		}
    public static PixbufOrientation GetOrientation(Exif.ExifData data)
    {
        PixbufOrientation orientation = PixbufOrientation.TopLeft;

        Exif.ExifEntry e = data.GetContents(Exif.Ifd.Zero).Lookup(Exif.Tag.Orientation);

        if (e != null)
        {
            ushort [] value = e.GetDataUShort();
            orientation = (PixbufOrientation)value [0];
        }

        return(orientation);
    }
Пример #11
0
        public string CreateFile()
        {
            Gdk.Pixbuf        test   = new Gdk.Pixbuf(null, "f-spot-32.png");
            string            path   = FSpot.ImageFile.TempPath("joe.jpg");
            string            desc   = "\x00a9 Novell Inc.";
            PixbufOrientation orient = PixbufOrientation.TopRight;

            PixbufUtils.SaveJpeg(test, path, quality, new Exif.ExifData());
            FSpot.JpegFile jimg = new FSpot.JpegFile(path);
            jimg.SetDescription(desc);
            jimg.SetOrientation(orient);
            jimg.SaveMetaData(path);

            return(path);
        }
    static public PixbufOrientation Rotate270(PixbufOrientation orientation)
    {
        PixbufOrientation [] rot = new PixbufOrientation [] {
            PixbufOrientation.LeftBottom,
            PixbufOrientation.LeftTop,
            PixbufOrientation.RightTop,
            PixbufOrientation.RightBottom,
            PixbufOrientation.BottomLeft,
            PixbufOrientation.TopLeft,
            PixbufOrientation.TopRight,
            PixbufOrientation.BottomRight
        };

        orientation = rot [((int)orientation) - 1];
        return(orientation);
    }
Пример #13
0
        public override PixbufOrientation GetOrientation()
        {
            PixbufOrientation orientation = PixbufOrientation.TopLeft;
            ImageDirectory    props       = Root.ReadDirectory(Tag.ImageProps);

            byte [] data = props.ReadEntry(Tag.ImageSpec);

            if (data != null)
            {
                orientation = new ImageSpec(data, little).Orientation;
            }
            //else
            //System.Console.WriteLine ("NO ORIENTATION");

            return(orientation);
        }
Пример #14
0
	static public PixbufOrientation Rotate270 (PixbufOrientation orientation)
	{
		PixbufOrientation [] rot = new PixbufOrientation [] {
			PixbufOrientation.LeftBottom, 
			PixbufOrientation.LeftTop,
			PixbufOrientation.RightTop,
			PixbufOrientation.RightBottom, 
			PixbufOrientation.BottomLeft,
			PixbufOrientation.TopLeft,
			PixbufOrientation.TopRight,
			PixbufOrientation.BottomRight
		};

		orientation = rot [((int)orientation) -1];
		return orientation;
	}
Пример #15
0
        public override PixbufOrientation GetOrientation()
        {
            PixbufOrientation orientation = PixbufOrientation.TopLeft;

            Exif.ExifEntry e = this.ExifData.GetContents(Exif.Ifd.Zero).Lookup(Exif.Tag.Orientation);
            if (e != null)
            {
                ushort [] value = e.GetDataUShort();
                orientation = (PixbufOrientation)value [0];
            }

            if (orientation < PixbufOrientation.TopLeft || orientation > PixbufOrientation.LeftBottom)
            {
                orientation = PixbufOrientation.TopLeft;
            }

            return(orientation);
        }
Пример #16
0
        public static PixbufOrientation GetViewOrientation(PixbufOrientation po)
        {
            if (timer == 0 && available)
            {
                SetupAccelerometer();
            }

            if (current_orientation == Orient.TiltCounterclockwise)
            {
                return(PixbufUtils.Rotate90(po));
            }

            if (current_orientation == Orient.TiltClockwise)
            {
                return(PixbufUtils.Rotate270(po));
            }

            return(po);
        }
Пример #17
0
 public static PixbufOrientation ReverseTransformation(PixbufOrientation orientation)
 {
     switch (orientation) {
     default:
     case PixbufOrientation.TopLeft:
     case PixbufOrientation.TopRight:
     case PixbufOrientation.BottomRight:
     case PixbufOrientation.BottomLeft:
         return orientation;
     case PixbufOrientation.LeftTop:
         return PixbufOrientation.RightBottom;
     case PixbufOrientation.RightTop:
         return PixbufOrientation.LeftBottom;
     case PixbufOrientation.RightBottom:
         return PixbufOrientation.LeftTop;
     case PixbufOrientation.LeftBottom:
         return PixbufOrientation.RightTop;
     }
 }
    public static Gdk.Pixbuf GetThumbnail(Exif.ExifData data)
    {
        byte [] thumb_data = data.Data;
        if (thumb_data.Length > 0)
        {
            PixbufOrientation orientation = GetOrientation(data);

            using (MemoryStream mem = new MemoryStream(thumb_data)) {
                Gdk.Pixbuf thumb = new Gdk.Pixbuf(mem);

                Gdk.Pixbuf rotated = PixbufUtils.TransformOrientation(thumb, orientation);

                if (rotated != thumb)
                {
                    thumb.Dispose();
                }
                return(rotated);
            }
        }
        return(null);
    }
    public static Gdk.Pixbuf TransformOrientation(Gdk.Pixbuf src, PixbufOrientation orientation, bool copy_data)
    {
        Gdk.Pixbuf pixbuf;
        if (src == null)
        {
            return(null);
        }

        switch (orientation)
        {
        case PixbufOrientation.LeftTop:
        case PixbufOrientation.LeftBottom:
        case PixbufOrientation.RightTop:
        case PixbufOrientation.RightBottom:
            pixbuf = new Gdk.Pixbuf(src.Colorspace, src.HasAlpha,
                                    src.BitsPerSample,
                                    src.Height, src.Width);
            break;

        case PixbufOrientation.TopRight:
        case PixbufOrientation.BottomRight:
        case PixbufOrientation.BottomLeft:
            pixbuf = new Gdk.Pixbuf(src.Colorspace, src.HasAlpha,
                                    src.BitsPerSample,
                                    src.Width, src.Height);
            break;

        default:
            pixbuf = src;
            break;
        }

        if (copy_data && src != pixbuf)
        {
            TransformAndCopy(src, pixbuf, orientation, new Gdk.Rectangle(0, 0, src.Width, src.Height));
        }

        return(pixbuf);
    }
        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);
        }
		public void Load (Uri uri)
		{
			this.uri = uri;

			delay.Stop ();

			if (!done_reading)
				Close ();

			done_reading = false;
			area_prepared = false;
			damage = Gdk.Rectangle.Zero;

			using (ImageFile img = ImageFile.Create (uri)) {
				orientation = Accelerometer.GetViewOrientation (img.Orientation);
			
				try {
					PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation (PixbufOrientation.TopLeft);
					thumb = new Gdk.Pixbuf (ThumbnailGenerator.ThumbnailPath (uri));
					thumb = PixbufUtils.TransformOrientation (thumb, thumb_orientation);
					
					if (FSpot.ColorManagement.IsEnabled && !thumb.HasAlpha) {
						if (img.GetProfile () == null)
							FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.StandartTransform ();
						else
							FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.CreateTransform (thumb, img.GetProfile ());
					}
					else
						FSpot.ColorManagement.PhotoImageView.Transform = null;
				} catch (System.Exception e) {
					//FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);	
					if (!(e is GLib.GException)) 
						System.Console.WriteLine (e.ToString ());
				}

				System.IO.Stream nstream = img.PixbufStream ();
				if (nstream == null) {
					FileLoad (img);
					return;
				} else
					stream = new StreamWrapper (nstream);

				loader = new Gdk.PixbufLoader ();
				loader.AreaPrepared += ap;
				loader.AreaUpdated += au;
				loader.Closed += ev;

				if (AreaPrepared != null && thumb != null) {
					pixbuf = thumb;
					AreaPrepared (this, new AreaPreparedArgs (true));
				}

				ThumbnailGenerator.Default.PushBlock ();
				//AsyncIORead (null);
				if (nstream is IOChannel) {
					((IOChannel)nstream).DataReady += IOChannelRead;
				} else
					delay.Start ();
			}

		}			
        public void Load(Uri uri)
        {
            this.uri = uri;

            delay.Stop();

            if (!done_reading)
            {
                Close();
            }

            done_reading  = false;
            area_prepared = false;
            damage        = Gdk.Rectangle.Zero;

            using (ImageFile img = ImageFile.Create(uri)) {
                orientation = Accelerometer.GetViewOrientation(img.Orientation);

                try {
                    PixbufOrientation thumb_orientation = Accelerometer.GetViewOrientation(PixbufOrientation.TopLeft);
                    thumb = new Gdk.Pixbuf(ThumbnailGenerator.ThumbnailPath(uri));
                    thumb = PixbufUtils.TransformOrientation(thumb, thumb_orientation);

                    if (FSpot.ColorManagement.IsEnabled && !thumb.HasAlpha)
                    {
                        if (img.GetProfile() == null)
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.StandartTransform();
                        }
                        else
                        {
                            FSpot.ColorManagement.PhotoImageView.Transform = FSpot.ColorManagement.CreateTransform(thumb, img.GetProfile());
                        }
                    }
                    else
                    {
                        FSpot.ColorManagement.PhotoImageView.Transform = null;
                    }
                } catch (System.Exception e) {
                    //FSpot.ThumbnailGenerator.Default.Request (uri.ToString (), 0, 256, 256);
                    if (!(e is GLib.GException))
                    {
                        System.Console.WriteLine(e.ToString());
                    }
                }

                System.IO.Stream nstream = img.PixbufStream();
                if (nstream == null)
                {
                    FileLoad(img);
                    return;
                }
                else
                {
                    stream = new StreamWrapper(nstream);
                }

                loader = new Gdk.PixbufLoader();
                loader.AreaPrepared += ap;
                loader.AreaUpdated  += au;
                loader.Closed       += ev;

                if (AreaPrepared != null && thumb != null)
                {
                    pixbuf = thumb;
                    AreaPrepared(this, new AreaPreparedArgs(true));
                }

                ThumbnailGenerator.Default.PushBlock();
                //AsyncIORead (null);
                if (nstream is IOChannel)
                {
                    ((IOChannel)nstream).DataReady += IOChannelRead;
                }
                else
                {
                    delay.Start();
                }
            }
        }
 public static Gdk.Pixbuf TransformOrientation(Gdk.Pixbuf src, PixbufOrientation orientation)
 {
     return(TransformOrientation(src, orientation, true));
 }
Пример #24
0
	public static Gdk.Rectangle TransformAndCopy (Gdk.Pixbuf src, Gdk.Pixbuf dest, PixbufOrientation orientation, Gdk.Rectangle args)
	{
		Gdk.Rectangle area = TransformOrientation (src, args, orientation);

		int step = 256;

		Gdk.Rectangle rect = new Gdk.Rectangle (args.X, args.Y, 
							Math.Min (step, args.Width),
							Math.Min (step, args.Height));

		Gdk.Rectangle trect = TransformOrientation (src, rect, orientation);
		Gdk.Pixbuf tmp = new Gdk.Pixbuf (src.Colorspace, src.HasAlpha, 
						 src.BitsPerSample,
						 trect.Width, trect.Height);

		Gdk.Rectangle subarea;
		BlockProcessor proc = new BlockProcessor (args, 256);
		while (proc.Step (out subarea)) {
			Gdk.Rectangle trans = TransformOrientation (src, subarea, orientation);
			Gdk.Pixbuf ssub = new Gdk.Pixbuf (src, subarea.X, subarea.Y,
							  subarea.Width, subarea.Height);

			Gdk.Pixbuf tsub = new Gdk.Pixbuf (tmp, 0, 0, trans.Width, trans.Height);
			CopyWithOrientation (ssub, tsub, orientation);

			tsub.CopyArea (0, 0, trans.Width, trans.Height, dest, trans.X, trans.Y);
			ssub.Dispose ();
			tsub.Dispose ();
		}

		tmp.Dispose ();
		return area;
	}
Пример #25
0
	public static void CopyWithOrientation (Gdk.Pixbuf src, Gdk.Pixbuf dest, PixbufOrientation orientation)
	{
		f_pixbuf_copy_with_orientation (src.Handle, dest.Handle, (int)orientation);
	}
Пример #26
0
		public void SetOrientation (PixbufOrientation orientation)
		{
			Exif.ExifEntry e = this.ExifData.GetContents (Exif.Ifd.Zero).GetEntry (Exif.Tag.Orientation);
			// System.Console.WriteLine ("Saving orientation as {0}", orientation);
			e.SetData ((ushort)orientation);
		       
			e = this.ExifData.GetContents (Exif.Ifd.One).Lookup (Exif.Tag.Orientation);
			if (e != null)
				e.SetData ((ushort)orientation);
		}
Пример #27
0
	public static Gdk.Rectangle TransformOrientation (int total_width, int total_height, Gdk.Rectangle args, PixbufOrientation orientation)
	{
		Gdk.Rectangle area = args;
		
		switch (orientation) {
		case PixbufOrientation.BottomRight:
			area.X = total_width - args.X - args.Width;
			area.Y = total_height - args.Y - args.Height;
			break;
		case PixbufOrientation.TopRight:
			area.X = total_width - args.X - args.Width;
			break;
		case PixbufOrientation.BottomLeft:
			area.Y = total_height - args.Y - args.Height;
			break;
		case PixbufOrientation.LeftTop:
			area.X = args.Y;
			area.Y = args.X;
			area.Width = args.Height;
			area.Height = args.Width;
			break;
		case PixbufOrientation.RightBottom:
			area.X = total_height - args.Y - args.Height;
			area.Y = total_width - args.X - args.Width;
			area.Width = args.Height;
			area.Height = args.Width;
			break;
		case PixbufOrientation.RightTop:
			area.X = total_height - args.Y - args.Height;
			area.Y = args.X;
			area.Width = args.Height;
			area.Height = args.Width;
			break;
		case PixbufOrientation.LeftBottom:
			area.X = args.Y;
			area.Y = total_width - args.X - args.Width;
			area.Width = args.Height;
			area.Height = args.Width;
			break;
		default:
			break;
		}
		
		return area;
	}
Пример #28
0
	public static Gdk.Pixbuf TransformOrientation (Gdk.Pixbuf src, PixbufOrientation orientation, bool copy_data)
	{
		Gdk.Pixbuf pixbuf;
		if (src == null)
			return null;
		
		switch (orientation) {
		case PixbufOrientation.LeftTop:
		case PixbufOrientation.LeftBottom:
		case PixbufOrientation.RightTop:
		case PixbufOrientation.RightBottom:	
			pixbuf = new Gdk.Pixbuf (src.Colorspace, src.HasAlpha, 
						 src.BitsPerSample,
						 src.Height, src.Width);
			break;
		case PixbufOrientation.TopRight:
		case PixbufOrientation.BottomRight:
		case PixbufOrientation.BottomLeft:
			pixbuf = new Gdk.Pixbuf (src.Colorspace, src.HasAlpha, 
						 src.BitsPerSample,
						 src.Width, src.Height);
			break;
		default:
			pixbuf = src;
			break;
		}

		if (copy_data && src != pixbuf) 
			TransformAndCopy (src, pixbuf, orientation, new Gdk.Rectangle (0, 0, src.Width, src.Height));

		return pixbuf;
	}
Пример #29
0
	public static Gdk.Pixbuf TransformOrientation (Gdk.Pixbuf src, PixbufOrientation orientation)
	{
		return TransformOrientation (src, orientation, true);
	}
 public static Gdk.Rectangle TransformOrientation(Gdk.Pixbuf src, Gdk.Rectangle args, PixbufOrientation orientation)
 {
     return(TransformOrientation(src.Width, src.Height, args, orientation));
 }
Пример #31
0
        public static Point TransformOrientation(int total_width, int total_height, Point args, PixbufOrientation orientation)
        {
            Point p = args;

            switch (orientation) {
            default:
            case PixbufOrientation.TopLeft:
                break;
            case PixbufOrientation.TopRight:
                p.X = total_width - p.X;
                break;
            case PixbufOrientation.BottomRight:
                p.X = total_width - p.X;
                p.Y = total_height - p.Y;
                break;
            case PixbufOrientation.BottomLeft:
                p.Y = total_height - p.Y;
                break;
            case PixbufOrientation.LeftTop:
                p.X = args.Y;
                p.Y = args.X;
                break;
            case PixbufOrientation.RightTop:
                p.X = total_height - args.Y;
                p.Y = args.X;
                break;
            case PixbufOrientation.RightBottom:
                p.X = total_height - args.Y;
                p.Y = total_width - args.X;
                break;
            case PixbufOrientation.LeftBottom:
                p.X = args.Y;
                p.Y = total_width - args.X;
                break;
            }
            return p;
        }
Пример #32
0
		public Pixbuf LoadFromFile (string path)
		{
			try {
				orientation = GetOrientation (path);
				using (FileStream fs = File.OpenRead (path)) {
					return Load (fs, orientation);
				}
			} catch (Exception) {
				System.Console.WriteLine ("Error loading photo {0}", path);
				return null;
			} 
		}
Пример #33
0
		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;
		}
Пример #34
0
        public static Pixbuf TransformOrientation(Pixbuf src, PixbufOrientation orientation)
        {
            Pixbuf dest;

            switch (orientation) {
            default:
            case PixbufOrientation.TopLeft:
                dest = PixbufUtils.ShallowCopy (src);
                break;
            case PixbufOrientation.TopRight:
                dest = src.Flip (false);
                break;
            case PixbufOrientation.BottomRight:
                dest = src.RotateSimple (PixbufRotation.Upsidedown);
                break;
            case PixbufOrientation.BottomLeft:
                dest = src.Flip (true);
                break;
            case PixbufOrientation.LeftTop:
                using (var rotated = src.RotateSimple (PixbufRotation.Clockwise)) {
                    dest = rotated.Flip (false);
                }
                break;
            case PixbufOrientation.RightTop:
                dest = src.RotateSimple (PixbufRotation.Clockwise);
                break;
            case PixbufOrientation.RightBottom:
                using (var rotated = src.RotateSimple (PixbufRotation.Counterclockwise)) {
                    dest = rotated.Flip (false);
                }
                break;
            case PixbufOrientation.LeftBottom:
                dest = src.RotateSimple (PixbufRotation.Counterclockwise);
                break;
            }

            return dest;
        }
 public static void CopyWithOrientation(Gdk.Pixbuf src, Gdk.Pixbuf dest, PixbufOrientation orientation)
 {
     f_pixbuf_copy_with_orientation(src.Handle, dest.Handle, (int)orientation);
 }
Пример #36
0
	public static Gdk.Rectangle TransformOrientation (Gdk.Pixbuf src, Gdk.Rectangle args, PixbufOrientation orientation)
	{
		return TransformOrientation (src.Width, src.Height, args, orientation);
	}
    public static Gdk.Rectangle TransformOrientation(int total_width, int total_height, Gdk.Rectangle args, PixbufOrientation orientation)
    {
        Gdk.Rectangle area = args;

        switch (orientation)
        {
        case PixbufOrientation.BottomRight:
            area.X = total_width - args.X - args.Width;
            area.Y = total_height - args.Y - args.Height;
            break;

        case PixbufOrientation.TopRight:
            area.X = total_width - args.X - args.Width;
            break;

        case PixbufOrientation.BottomLeft:
            area.Y = total_height - args.Y - args.Height;
            break;

        case PixbufOrientation.LeftTop:
            area.X      = args.Y;
            area.Y      = args.X;
            area.Width  = args.Height;
            area.Height = args.Width;
            break;

        case PixbufOrientation.RightBottom:
            area.X      = total_height - args.Y - args.Height;
            area.Y      = total_width - args.X - args.Width;
            area.Width  = args.Height;
            area.Height = args.Width;
            break;

        case PixbufOrientation.RightTop:
            area.X      = total_height - args.Y - args.Height;
            area.Y      = args.X;
            area.Width  = args.Height;
            area.Height = args.Width;
            break;

        case PixbufOrientation.LeftBottom:
            area.X      = args.Y;
            area.Y      = total_width - args.X - args.Width;
            area.Width  = args.Height;
            area.Height = args.Width;
            break;

        default:
            break;
        }

        return(area);
    }
Пример #38
0
        public void Load(Uri uri)
        {
            if (is_disposed)
                return;

            //First, send a thumbnail if we have one
            if ((thumb = ThumbnailFactory.LoadThumbnail (uri)) != null) {
                pixbuf_orientation = PixbufOrientation.TopLeft;
                EventHandler<AreaPreparedEventArgs> prep = AreaPrepared;
                if (prep != null)
                    prep (this, new AreaPreparedEventArgs (true));
                EventHandler<AreaUpdatedEventArgs> upd = AreaUpdated;
                if (upd != null)
                    upd (this, new AreaUpdatedEventArgs (new Rectangle (0, 0, thumb.Width, thumb.Height)));
            }

            using (ImageFile image_file = ImageFile.Create (uri)) {
                image_stream = image_file.PixbufStream ();
                pixbuf_orientation = image_file.Orientation;
            }

            loading = true;
            // The ThreadPool.QueueUserWorkItem hack is there cause, as the bytes to read are present in the stream,
            // the Read is CompletedAsynchronously, blocking the mainloop
            image_stream.BeginRead (buffer, 0, count, delegate (IAsyncResult r) {
                ThreadPool.QueueUserWorkItem (delegate {HandleReadDone (r);});
            }, null);
        }