f-spot-degrade
changeset 1:5b8d3801f95c tip
Implement the degrading from RAW to JPEG
| author | Emanuele Aina <em@nerd.ocracy.org> |
|---|---|
| date | Thu Jan 01 21:41:36 2009 +0100 (14 months ago) |
| parents | 5feef6944434 |
| children | |
| files | Degrade.cs |
line diff
1.1 --- a/Degrade.cs Thu Jan 01 18:38:52 2009 +0100 1.2 +++ b/Degrade.cs Thu Jan 01 21:41:36 2009 +0100 1.3 @@ -8,10 +8,40 @@ 1.4 */ 1.5 1.6 using System; 1.7 +using System.IO; 1.8 using FSpot; 1.9 using FSpot.Extensions; 1.10 +using FSpot.Filters; 1.11 +using FSpot.Utils; 1.12 1.13 namespace Degrade { 1.14 + // Move the file next to the original source, preserving 1.15 + // newly assigned file extensions 1.16 + public class NextToSourceFilter : IFilter 1.17 + { 1.18 + public bool Convert (FilterRequest request) 1.19 + { 1.20 + string source = request.Source.LocalPath; 1.21 + string current = request.Current.LocalPath; 1.22 + 1.23 + string dest = Path.GetFileNameWithoutExtension(source) + 1.24 + Path.GetExtension(current); 1.25 + 1.26 + int i = 1; 1.27 + while (System.IO.File.Exists (dest)) { 1.28 + string numbered_name = String.Format ("{0}-{1}{2}", 1.29 + Path.GetFileNameWithoutExtension(dest), 1.30 + i++, 1.31 + Path.GetExtension(dest)); 1.32 + dest = Path.Combine(Path.GetDirectoryName(dest), numbered_name); 1.33 + } 1.34 + 1.35 + System.IO.File.Copy (request.Current.LocalPath, dest); 1.36 + request.Current = UriUtils.PathToFileUri (dest); 1.37 + return true; 1.38 + } 1.39 + } 1.40 + 1.41 public class DegradeTool: ICommand 1.42 { 1.43 public void Debug(string fmt, params object[] args){ 1.44 @@ -23,8 +53,21 @@ 1.45 Debug("init"); 1.46 } 1.47 1.48 - public void Run (object o, EventArgs e) { 1.49 - Debug("run"); 1.50 + public void Run (object o, EventArgs e) { 1.51 + foreach (Photo photo in MainWindow.Toplevel.SelectedPhotos()) 1.52 + { 1.53 + FilterSet filters = new FilterSet(); 1.54 + filters.Add (new JpegFilter()); 1.55 + filters.Add (new ChmodFilter()); 1.56 + filters.Add (new NextToSourceFilter()); 1.57 + using (FilterRequest request = new FilterRequest(photo.DefaultVersionUri)) { 1.58 + filters.Convert(request); 1.59 + Debug("degrading from '{0}' to '{1}'", 1.60 + photo.DefaultVersion.Uri.LocalPath, 1.61 + request.Current.LocalPath); 1.62 + request.Preserve(request.Current); 1.63 + } 1.64 + } 1.65 } 1.66 } 1.67 }
