Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
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;
		}
        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);
        }
Ejemplo n.º 5
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);
        }
		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 void ProcessImage (int image_num, Filters.FilterSet filter_set)
		{
			IBrowsableItem photo = collection [image_num];
			string photo_path = photo.DefaultVersionUri.LocalPath;
			string path;
			ScaleRequest req;

			req = requests [0];
			
			MakeDir (SubdirPath (req.Name));
			path = SubdirPath (req.Name, ImageName (image_num));
			
			using (Filters.FilterRequest request = new Filters.FilterRequest (photo.DefaultVersionUri)) {
				filter_set.Convert (request);
				if (request.Current.LocalPath == path)
					request.Preserve(request.Current);
				else
					File.Copy (request.Current.LocalPath, path, true); 

				if (photo != null && photo is Photo && Core.Database != null) {
					Core.Database.Exports.Create ((photo as Photo).Id, (photo as Photo).DefaultVersionId,
								      ExportStore.FolderExportType,
								      // FIXME this is wrong, the final path is the one
								      // after the Xfer.
								      UriList.PathToFileUriEscaped (path).ToString ());
				}

				using (Exif.ExifData data = new Exif.ExifData (photo_path)) {
					for (int i = 1; i < requests.Length; i++) {
						
						req = requests [i];
						if (scale && req.AvoidScale (size))
							continue;
				
						Filters.FilterSet req_set = new Filters.FilterSet ();
						req_set.Add (new Filters.ResizeFilter ((uint)Math.Max (req.Width, req.Height)));
						if ((bool)Preferences.Get (Preferences.EXPORT_FOLDER_SHARPEN)) {
							if (req.Name == "lq")
								req_set.Add (new Filters.SharpFilter (0.1, 2, 4));
							if (req.Name == "thumbs")
								req_set.Add (new Filters.SharpFilter (0.1, 2, 5));
						}
						using (Filters.FilterRequest tmp_req = new Filters.FilterRequest (photo.DefaultVersionUri)) {
							req_set.Convert (tmp_req);
							MakeDir (SubdirPath (req.Name));
							path = SubdirPath (req.Name, ImageName (image_num));
							System.IO.File.Copy (tmp_req.Current.LocalPath, path, true);
						}
						
					}
				}
			}
		}
        public void ProcessImage(int image_num, Filters.FilterSet filter_set)
        {
            IBrowsableItem photo      = collection [image_num];
            string         photo_path = photo.DefaultVersionUri.LocalPath;
            string         path;
            ScaleRequest   req;

            req = requests [0];

            MakeDir(SubdirPath(req.Name));
            path = SubdirPath(req.Name, ImageName(image_num));

            using (Filters.FilterRequest request = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                filter_set.Convert(request);
                if (request.Current.LocalPath == path)
                {
                    request.Preserve(request.Current);
                }
                else
                {
                    File.Copy(request.Current.LocalPath, path, true);
                }

                if (photo != null && photo is Photo && Core.Database != null)
                {
                    Core.Database.Exports.Create((photo as Photo).Id, (photo as Photo).DefaultVersionId,
                                                 ExportStore.FolderExportType,
                                                 // FIXME this is wrong, the final path is the one
                                                 // after the Xfer.
                                                 UriList.PathToFileUriEscaped(path).ToString());
                }

                using (Exif.ExifData data = new Exif.ExifData(photo_path)) {
                    for (int i = 1; i < requests.Length; i++)
                    {
                        req = requests [i];
                        if (scale && req.AvoidScale(size))
                        {
                            continue;
                        }

                        Filters.FilterSet req_set = new Filters.FilterSet();
                        req_set.Add(new Filters.ResizeFilter((uint)Math.Max(req.Width, req.Height)));
                        if ((bool)Preferences.Get(Preferences.EXPORT_FOLDER_SHARPEN))
                        {
                            if (req.Name == "lq")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 4));
                            }
                            if (req.Name == "thumbs")
                            {
                                req_set.Add(new Filters.SharpFilter(0.1, 2, 5));
                            }
                        }
                        using (Filters.FilterRequest tmp_req = new Filters.FilterRequest(photo.DefaultVersionUri)) {
                            req_set.Convert(tmp_req);
                            MakeDir(SubdirPath(req.Name));
                            path = SubdirPath(req.Name, ImageName(image_num));
                            System.IO.File.Copy(tmp_req.Current.LocalPath, path, true);
                        }
                    }
                }
            }
        }