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);
                    }
                }
            }
        }
		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;
					}
				}
			}
		}
        public bool Convert(FilterRequest req)
        {
            // FIXME this should copy metadata from the original
            // even when the source is not a jpeg
            string source = req.Current.LocalPath;

            using (ImageFile img = ImageFile.Create(source)) {
                if (img is JpegFile)
                {
                    return(false);
                }

                req.Current = req.TempUri("jpg");
                string dest = req.Current.LocalPath;

                Exif.ExifData exif_data;
                try {
                    exif_data = new Exif.ExifData(source);
                } catch (Exception) {
                    exif_data = new Exif.ExifData();
                }

                PixbufUtils.SaveJpeg(img.Load(), dest, (int)quality, exif_data);
            }

            return(true);
        }
		public bool Convert (FilterRequest req)
		{
			Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (req.Current.LocalPath));

			using (ImageFile img = ImageFile.Create (req.Current)) {
				using (Pixbuf in_pixbuf = img.Load ()) {
					using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask (in_pixbuf, radius, amount, threshold)) {
						string destination_extension = Path.GetExtension (dest_uri.LocalPath);
		
						if (Path.GetExtension (req.Current.LocalPath).ToLower () == Path.GetExtension (dest_uri.LocalPath).ToLower ()) {
							using (Stream output = File.OpenWrite (dest_uri.LocalPath)) {
								img.Save (out_pixbuf, output);
							}
						} else if (destination_extension == ".jpg") {
							// FIXME this is a bit of a nasty hack to work around
							// the lack of being able to change the path in this filter
							// and the lack of proper metadata copying yuck
							Exif.ExifData exif_data;
		
							exif_data = new Exif.ExifData (req.Current.LocalPath);
							
							PixbufUtils.SaveJpeg (out_pixbuf, dest_uri.LocalPath, 90, exif_data);
						} else 
							throw new NotImplementedException (String.Format (Catalog.GetString ("No way to save files of type \"{0}\""), destination_extension));
						
					}
				}
			}

			req.Current = dest_uri;
			return true;
		}
		public bool Convert (FilterRequest req)
		{
			// FIXME this should copy metadata from the original
			// even when the source is not a jpeg
			string source = req.Current.LocalPath;

			using (ImageFile img = ImageFile.Create (source)) {
				if (img is JpegFile)
					return false;

				req.Current = req.TempUri ("jpg");
				string dest = req.Current.LocalPath;

				Exif.ExifData exif_data;
				try {
					exif_data = new Exif.ExifData (source);
				} catch (Exception) {
					exif_data = new Exif.ExifData();
				}

				PixbufUtils.SaveJpeg (img.Load(), dest, (int) quality, exif_data);
			}

			return true;
		}
        public bool Convert(FilterRequest req)
        {
            Uri source = req.Current;

            using (ImageFile img = ImageFile.Create(source)) {
                pixbuf  = img.Load();
                profile = img.GetProfile();

                // If the image doesn't have an embedded profile assume it is sRGB
                if (profile == null)
                {
                    profile = Profile.CreateStandardRgb();
                }

                if (destination == null)
                {
                    destination = profile;
                }

                Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb,
                                                  false, 8,
                                                  pixbuf.Width,
                                                  pixbuf.Height);

                Profile [] list = Prepare(pixbuf);

                if (pixbuf.HasAlpha)
                {
                    Gdk.Pixbuf alpha     = PixbufUtils.Flatten(pixbuf);
                    Transform  transform = new Transform(list,
                                                         PixbufUtils.PixbufCmsFormat(alpha),
                                                         PixbufUtils.PixbufCmsFormat(final),
                                                         rendering_intent, 0x0000);
                    PixbufUtils.ColorAdjust(alpha, final, transform);
                    PixbufUtils.ReplaceColor(final, pixbuf);
                    alpha.Dispose();
                    final.Dispose();
                    final = pixbuf;
                }
                else
                {
                    Transform transform = new Transform(list,
                                                        PixbufUtils.PixbufCmsFormat(pixbuf),
                                                        PixbufUtils.PixbufCmsFormat(final),
                                                        rendering_intent, 0x0000);
                    PixbufUtils.ColorAdjust(pixbuf, final, transform);
                    pixbuf.Dispose();
                }

                Uri dest_uri = req.TempUri(Path.GetExtension(source.LocalPath));
                using (Stream output = File.OpenWrite(dest_uri.LocalPath)) {
                    img.Save(final, output);
                }
                final.Dispose();
                req.Current = dest_uri;

                return(true);
            }
        }
示例#7
0
        public bool Convert(FilterRequest req)
        {
            if (req.Current == req.Source) {
                var uri = req.TempUri ();
                System.IO.File.Copy (req.Current.LocalPath, uri.LocalPath, true);
                req.Current = uri;
            }

            Syscall.chmod (req.Current.LocalPath, mode);

            return true;
        }
		public bool Convert (FilterRequest req)
		{
			string source = req.Current.LocalPath;
			System.Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (source));
			string dest = dest_uri.LocalPath;

			using (ImageFile img = ImageFile.Create (source)) {
				bool changed = false;
				
				if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile) {
					JpegFile jimg = img as JpegFile;
					
					if (img.Orientation == PixbufOrientation.RightTop) {
						JpegUtils.Transform (source,
								     dest,
								     JpegUtils.TransformType.Rotate90);
						changed = true;
					} else if (img.Orientation == PixbufOrientation.LeftBottom) {
						JpegUtils.Transform (source,
								     dest,
								     JpegUtils.TransformType.Rotate270);
						changed = true;
					} else if (img.Orientation == PixbufOrientation.BottomRight) {
						JpegUtils.Transform (source,
								     dest,
								     JpegUtils.TransformType.Rotate180);
						changed = true;
					}
					
					int width, height;
	
					jimg = ImageFile.Create (dest) as JpegFile;
					
					PixbufUtils.GetSize (dest, out width, out height);
	
					jimg.SetOrientation (PixbufOrientation.TopLeft);
					jimg.SetDimensions (width, height);
	
					Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (dest, 160, 120, true);
					jimg.SetThumbnail (pixbuf);
					pixbuf.Dispose ();
	
					jimg.SaveMetaData (dest);
					jimg.Dispose ();
				}
	
				if (changed)
					req.Current = dest_uri;
	
				return changed;
			}
		}
示例#9
0
        public bool Convert(FilterRequest req)
        {
            if (req.Current == req.Source)
            {
                var uri = req.TempUri();
                System.IO.File.Copy(req.Current.LocalPath, uri.LocalPath, true);
                req.Current = uri;
            }

            Syscall.chmod(req.Current.LocalPath, mode);

            return(true);
        }
示例#10
0
        public bool Convert(FilterRequest req)
        {
            var dest_uri = req.TempUri(req.Current.GetExtension());

            using (var img = App.Instance.Container.Resolve <IImageFileFactory> ().Create(req.Current)) {
                using (Pixbuf in_pixbuf = img.Load()) {
                    using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask(in_pixbuf, radius, amount, threshold, null)) {
                        FSpot.Utils.PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, out_pixbuf);
                    }
                }
            }

            req.Current = dest_uri;
            return(true);
        }
示例#11
0
        public bool Convert(FilterRequest req)
        {
            var dest_uri = req.TempUri (req.Current.GetExtension ());

            using (var img = ImageFile.Create (req.Current)) {
                using (Pixbuf in_pixbuf = img.Load ()) {
                    using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask (in_pixbuf, radius, amount, threshold, null)) {
                        PixbufUtils.CreateDerivedVersion (req.Current, dest_uri, 95, out_pixbuf);
                    }
                }
            }

            req.Current = dest_uri;
            return true;
        }
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;

            System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source));
            string     dest     = dest_uri.LocalPath;

            using (ImageFile img = ImageFile.Create(source)) {
                using (Pixbuf pixbuf = img.Load()) {
                    if (pixbuf.Width < size && pixbuf.Height < size)
                    {
                        return(false);
                    }
                }

                using (Pixbuf pixbuf = img.Load((int)size, (int)size)) {
                    string destination_extension = Path.GetExtension(dest);

                    if (Path.GetExtension(source).ToLower() == Path.GetExtension(dest).ToLower())
                    {
                        using (Stream output = File.OpenWrite(dest)) {
                            img.Save(pixbuf, output);
                        }
                    }
                    else if (destination_extension == ".jpg")
                    {
                        // FIXME this is a bit of a nasty hack to work around
                        // the lack of being able to change the path in this filter
                        // and the lack of proper metadata copying yuck
                        Exif.ExifData exif_data;

                        exif_data = new Exif.ExifData(source);

                        PixbufUtils.SaveJpeg(pixbuf, dest, 95, exif_data);
                    }
                    else
                    {
                        throw new NotImplementedException(String.Format(Catalog.GetString("No way to save files of type \"{0}\""), destination_extension));
                    }
                }
            }

            req.Current = dest_uri;
            return(true);
        }
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;
            var dest_uri = req.TempUri (System.IO.Path.GetExtension (source));

            using (var img = ImageFile.Create (req.Current)) {

                using (Pixbuf pixbuf = img.Load ()) {
                    if (pixbuf.Width < size && pixbuf.Height < size)
                        return false;
                }

                using (Pixbuf pixbuf = img.Load ((int)size, (int)size)) {
                    PixbufUtils.CreateDerivedVersion (req.Current, dest_uri, 95, pixbuf);
                }
            }

            req.Current = dest_uri;
            return true;
        }
示例#14
0
        public bool Convert(FilterRequest req)
        {
            Uri source = req.Current;

            using (ImageFile img = ImageFile.Create(source)) {
                Pixbuf  pixbuf  = img.Load();
                Profile profile = img.GetProfile();

                Adjustment adjustment = CreateAdjustment(pixbuf, profile);
                Gdk.Pixbuf final      = adjustment.Adjust();

                Uri dest_uri = req.TempUri(Path.GetExtension(source.LocalPath));
                using (Stream output = File.OpenWrite(dest_uri.LocalPath)) {
                    img.Save(final, output);
                }
                final.Dispose();
                req.Current = dest_uri;

                return(true);
            }
        }
示例#15
0
        public bool Convert(FilterRequest req)
        {
            string source   = req.Current.LocalPath;
            var    dest_uri = req.TempUri(System.IO.Path.GetExtension(source));

            using (var img = App.Instance.Container.Resolve <IImageFileFactory> ().Create(req.Current)) {
                using (Pixbuf pixbuf = img.Load()) {
                    if (pixbuf.Width < Size && pixbuf.Height < Size)
                    {
                        return(false);
                    }
                }

                using (Pixbuf pixbuf = img.Load((int)Size, (int)Size)) {
                    FSpot.Utils.PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, pixbuf);
                }
            }

            req.Current = dest_uri;
            return(true);
        }
示例#16
0
        public bool Convert(FilterRequest req)
        {
            string source   = req.Current.LocalPath;
            var    dest_uri = req.TempUri(System.IO.Path.GetExtension(source));

            using (var img = ImageFile.Create(req.Current)) {
                using (Pixbuf pixbuf = img.Load()) {
                    if (pixbuf.Width < size && pixbuf.Height < size)
                    {
                        return(false);
                    }
                }

                using (Pixbuf pixbuf = img.Load((int)size, (int)size)) {
                    PixbufUtils.CreateDerivedVersion(req.Current, dest_uri, 95, pixbuf);
                }
            }

            req.Current = dest_uri;
            return(true);
        }
示例#17
0
        public bool Convert(FilterRequest req)
        {
            Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(req.Current.LocalPath));

            using (ImageFile img = ImageFile.Create(req.Current)) {
                using (Pixbuf in_pixbuf = img.Load()) {
                    using (Pixbuf out_pixbuf = PixbufUtils.UnsharpMask(in_pixbuf, radius, amount, threshold)) {
                        string destination_extension = Path.GetExtension(dest_uri.LocalPath);

                        if (Path.GetExtension(req.Current.LocalPath).ToLower() == Path.GetExtension(dest_uri.LocalPath).ToLower())
                        {
                            using (Stream output = File.OpenWrite(dest_uri.LocalPath)) {
                                img.Save(out_pixbuf, output);
                            }
                        }
                        else if (destination_extension == ".jpg")
                        {
                            // FIXME this is a bit of a nasty hack to work around
                            // the lack of being able to change the path in this filter
                            // and the lack of proper metadata copying yuck
                            Exif.ExifData exif_data;

                            exif_data = new Exif.ExifData(req.Current.LocalPath);

                            PixbufUtils.SaveJpeg(out_pixbuf, dest_uri.LocalPath, 90, exif_data);
                        }
                        else
                        {
                            throw new NotImplementedException(String.Format(Catalog.GetString("No way to save files of type \"{0}\""), destination_extension));
                        }
                    }
                }
            }

            req.Current = dest_uri;
            return(true);
        }
示例#18
0
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;
            System.Uri dest_uri = req.TempUri (System.IO.Path.GetExtension (source));
            string dest = dest_uri.LocalPath;

            using (ImageFile img = ImageFile.Create (req.Current)) {

                using (Pixbuf pixbuf = img.Load ()) {
                    if (pixbuf.Width < size && pixbuf.Height < size)
                        return false;
                }

                using (Pixbuf pixbuf = img.Load ((int)size, (int)size)) {
                    string destination_extension = Path.GetExtension (dest);

                    if (Path.GetExtension (source).ToLower () == Path.GetExtension (dest).ToLower ()) {
                        using (Stream output = File.OpenWrite (dest)) {
                            img.Save (pixbuf, output);
                        }
                    } else if (destination_extension == ".jpg") {
                        // FIXME this is a bit of a nasty hack to work around
                        // the lack of being able to change the path in this filter
                        // and the lack of proper metadata copying yuck
                        Exif.ExifData exif_data;

                        exif_data = new Exif.ExifData (source);

                        PixbufUtils.SaveJpeg (pixbuf, dest, 95, exif_data);
                    } else
                        throw new NotImplementedException (String.Format (Catalog.GetString ("No way to save files of type \"{0}\""), destination_extension));
                }
            }

            req.Current = dest_uri;
            return true;
        }
        public bool Convert(FilterRequest req)
        {
            string source = req.Current.LocalPath;

            System.Uri dest_uri = req.TempUri(System.IO.Path.GetExtension(source));
            string     dest     = dest_uri.LocalPath;

            using (ImageFile img = ImageFile.Create(source)) {
                bool changed = false;

                if (img.Orientation != PixbufOrientation.TopLeft && img is JpegFile)
                {
                    JpegFile jimg = img as JpegFile;

                    if (img.Orientation == PixbufOrientation.RightTop)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate90);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.LeftBottom)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate270);
                        changed = true;
                    }
                    else if (img.Orientation == PixbufOrientation.BottomRight)
                    {
                        JpegUtils.Transform(source,
                                            dest,
                                            JpegUtils.TransformType.Rotate180);
                        changed = true;
                    }

                    int width, height;

                    jimg = ImageFile.Create(dest) as JpegFile;

                    PixbufUtils.GetSize(dest, out width, out height);

                    jimg.SetOrientation(PixbufOrientation.TopLeft);
                    jimg.SetDimensions(width, height);

                    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(dest, 160, 120, true);
                    jimg.SetThumbnail(pixbuf);
                    pixbuf.Dispose();

                    jimg.SaveMetaData(dest);
                    jimg.Dispose();
                }

                if (changed)
                {
                    req.Current = dest_uri;
                }

                return(changed);
            }
        }
		public bool Convert (FilterRequest req)
		{
			Uri source = req.Current;
			using (ImageFile img = ImageFile.Create (source)) {
				pixbuf = img.Load ();
				profile = img.GetProfile ();
	
				// If the image doesn't have an embedded profile assume it is sRGB
				if (profile == null)
					profile = Profile.CreateStandardRgb ();
	
				if (destination == null)
					destination = profile;
	
				Gdk.Pixbuf final = new Gdk.Pixbuf (Gdk.Colorspace.Rgb,
								   false, 8,
								   pixbuf.Width, 
								   pixbuf.Height);
	
				Profile [] list = Prepare (pixbuf);
	
				if (pixbuf.HasAlpha) {
					Gdk.Pixbuf alpha = PixbufUtils.Flatten (pixbuf);
					Transform transform = new Transform (list,
									     PixbufUtils.PixbufCmsFormat (alpha),
									     PixbufUtils.PixbufCmsFormat (final),
									     rendering_intent, 0x0000);
					PixbufUtils.ColorAdjust (alpha, final, transform);
					PixbufUtils.ReplaceColor (final, pixbuf);
					alpha.Dispose ();
					final.Dispose ();
					final = pixbuf;
				} else {
					Transform transform = new Transform (list,
									     PixbufUtils.PixbufCmsFormat (pixbuf),
									     PixbufUtils.PixbufCmsFormat (final),
									     rendering_intent, 0x0000);
					PixbufUtils.ColorAdjust (pixbuf, final, transform);
					pixbuf.Dispose ();
				}
				
				Uri dest_uri = req.TempUri (Path.GetExtension (source.LocalPath));
				using (Stream output = File.OpenWrite (dest_uri.LocalPath)) {
					img.Save (final, output);
				}
				final.Dispose ();
				req.Current = dest_uri;
				
				return true;
			}
		}