static public Gdk.Pixbuf LoadAtMaxSize(IPhoto item, int width, int height) { using (var img = ImageFile.Create(item.DefaultVersion.Uri)) { Gdk.Pixbuf pixbuf = img.Load(width, height); return(pixbuf); } }
static public Gdk.Pixbuf Load(IPhoto item) { using (var img = ImageFile.Create(item.DefaultVersion.Uri)) { Gdk.Pixbuf pixbuf = img.Load(); return(pixbuf); } }
static public Gdk.Pixbuf LoadAtMaxSize(IBrowsableItem item, int width, int height) { using (ImageFile img = ImageFile.Create(item.DefaultVersionUri)) { Gdk.Pixbuf pixbuf = img.Load(width, height); ValidateThumbnail(item.DefaultVersionUri, pixbuf); return(pixbuf); } }
static public Gdk.Pixbuf Load(IBrowsableItem item) { using (ImageFile img = ImageFile.Create(item.DefaultVersionUri)) { Gdk.Pixbuf pixbuf = img.Load(); ValidateThumbnail(item, pixbuf); return(pixbuf); } }
public GoogleAccountDialog(Gtk.Window parent, GoogleAccount account, bool show_error, CaptchaException captcha_exception) : base("google_add_dialog") { this.Dialog.Modal = false; this.Dialog.TransientFor = parent; this.Dialog.DefaultResponse = Gtk.ResponseType.Ok; this.account = account; bool show_captcha = (captcha_exception != null); status_area.Visible = show_error; locked_area.Visible = show_captcha; captcha_label.Visible = show_captcha; captcha_entry.Visible = show_captcha; captcha_image.Visible = show_captcha; password_entry.ActivatesDefault = true; username_entry.ActivatesDefault = true; if (show_captcha) { try { using (ImageFile img = ImageFile.Create(new Uri(captcha_exception.CaptchaUrl))) { captcha_image.Pixbuf = img.Load(); token = captcha_exception.Token; } } catch (Exception) {} } if (account != null) { password_entry.Text = account.Password; username_entry.Text = account.Username; add_button.Label = Gtk.Stock.Ok; Dialog.Response += HandleEditResponse; } if (remove_button != null) { remove_button.Visible = account != null; } this.Dialog.Show(); password_entry.Changed += HandleChanged; username_entry.Changed += HandleChanged; HandleChanged(null, null); }
public static Gdk.Pixbuf Create(Uri uri) { try { using (ImageFile img = ImageFile.Create(uri)) { Gdk.Pixbuf thumb = img.Load(256, 256); if (thumb != null) { Save(thumb, uri); } return(thumb); } } catch { return(null); } }
private Texture CreateTexture() { if (glx == null || GdkWindow == null) { return(null); } glx.MakeCurrent(GdkWindow); Texture tex; try { using (ImageFile img = ImageFile.Create(item.Current.DefaultVersionUri)) { using (Gdk.Pixbuf pixbuf = img.Load()) { tex = new Texture(pixbuf); } } } catch (Exception) { tex = new Texture(PixbufUtils.ErrorPixbuf); } return(tex); }
//FIXME: won't work on non file uris public uint SaveVersion(Gdk.Pixbuf buffer, bool create_version) { uint version = DefaultVersionId; using (ImageFile img = ImageFile.Create(DefaultVersionUri)) { // Always create a version if the source is not a jpeg for now. create_version = create_version || !(img is FSpot.JpegFile); if (buffer == null) { throw new ApplicationException("invalid (null) image"); } if (create_version) { version = CreateDefaultModifiedVersion(DefaultVersionId, false); } try { string version_path = VersionUri(version).LocalPath; using (Stream stream = System.IO.File.OpenWrite(version_path)) { img.Save(buffer, stream); } FSpot.ThumbnailGenerator.Create(version_path).Dispose(); DefaultVersionId = version; } catch (System.Exception e) { System.Console.WriteLine(e); if (create_version) { DeleteVersion(version); } throw e; } } return(version); }
//FIXME: won't work on non file uris public uint SaveVersion(Gdk.Pixbuf buffer, bool create_version) { uint version = DefaultVersionId; using (var img = ImageFile.Create(DefaultVersion.Uri)) { // Always create a version if the source is not a jpeg for now. create_version = create_version || ImageFile.IsJpeg(DefaultVersion.Uri); if (buffer == null) { throw new ApplicationException("invalid (null) image"); } if (create_version) { version = CreateDefaultModifiedVersion(DefaultVersionId, false); } try { var versionUri = VersionUri(version); PixbufUtils.CreateDerivedVersion(DefaultVersion.Uri, versionUri, 95, buffer); GetVersion(version).ImportMD5 = HashUtils.GenerateMD5(VersionUri(version)); DefaultVersionId = version; } catch (System.Exception e) { Log.Exception(e); if (create_version) { DeleteVersion(version); } throw e; } } return(version); }
protected override void OnDrawPage(Gtk.PrintContext context, int page_nr) { base.OnDrawPage(context, page_nr); Context cr = context.CairoContext; int ppx, ppy; switch (photos_per_page) { default: case 1: ppx = ppy = 1; break; case 2: ppx = 1; ppy = 2; break; case 4: ppx = ppy = 2; break; case 9: ppx = ppy = 3; break; case 12: ppx = 3; ppy = 4; break; case 20: ppx = 4; ppy = 5; break; case 30: ppx = 5; ppy = 6; break; } //FIXME: if paper is landscape, swap ppx with ppy double w = context.Width / ppx; double h = context.Height / ppy; // compute picture size using 4800DPI double mx = (w / 25.4) * 4800, my = (h / 25.4) * 4800; for (int x = 0; x <= ppx; x++) { for (int y = 0; y <= ppy; y++) { int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x; if (crop_marks) { DrawCropMarks(cr, x * w, y * h, w * .1); } if (x == ppx || y == ppy || p_index >= selected_photos.Length) { continue; } using (var img = ImageFile.Create(selected_photos[p_index].DefaultVersion.Uri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load((int)mx, (int)my); Cms.Profile printer_profile; if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile)) { ColorManagement.ApplyProfile(pixbuf, img.GetProfile(), printer_profile); } } catch (Exception e) { Log.Exception("Unable to load image " + selected_photos[p_index].DefaultVersion.Uri + "\n", e); // If the image is not found load error pixbuf pixbuf = new Gdk.Pixbuf(PixbufUtils.ErrorPixbuf, 0, 0, PixbufUtils.ErrorPixbuf.Width, PixbufUtils.ErrorPixbuf.Height); } //Gdk.Pixbuf pixbuf = img.Load (100, 100); bool rotated = false; if (Math.Sign((double)pixbuf.Width / pixbuf.Height - 1.0) != Math.Sign(w / h - 1.0)) { Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple(Gdk.PixbufRotation.Counterclockwise); pixbuf.Dispose(); pixbuf = d_pixbuf; rotated = true; } DrawImage(cr, pixbuf, x * w, y * h, w, h); string tag_string = ""; foreach (Tag t in selected_photos[p_index].Tags) { tag_string = String.Concat(tag_string, t.Name); } string label = String.Format(print_label_format, comment, selected_photos[p_index].Name, selected_photos[p_index].Time.ToLocalTime().ToShortDateString(), selected_photos[p_index].Time.ToLocalTime().ToShortTimeString(), tag_string, selected_photos[p_index].Description); DrawComment(context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, label, rotated); pixbuf.Dispose(); } } } }
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(); } } }
static int Main(string [] args) { args = FixArgs(args); ApplicationContext.ApplicationName = "F-Spot"; ApplicationContext.TrySetProcessName(Defines.PACKAGE); Paths.ApplicationName = "f-spot"; ThreadAssist.InitializeMainThread(); ThreadAssist.ProxyToMainHandler = RunIdle; XdgThumbnailSpec.DefaultLoader = (uri) => { using (var file = ImageFile.Create(uri)) return(file.Load()); }; // Options and Option parsing bool shutdown = false; bool view = false; bool slideshow = false; bool import = false; GLib.GType.Init(); Catalog.Init("f-spot", Defines.LOCALE_DIR); FSpot.Core.Global.PhotoUri = new SafeUri(Preferences.Get <string> (Preferences.STORAGE_PATH)); ApplicationContext.CommandLine = new CommandLineParser(args, 0); if (ApplicationContext.CommandLine.ContainsStart("help")) { ShowHelp(); return(0); } if (ApplicationContext.CommandLine.Contains("version")) { ShowVersion(); return(0); } if (ApplicationContext.CommandLine.Contains("versions")) { ShowAssemblyVersions(); return(0); } if (ApplicationContext.CommandLine.Contains("shutdown")) { Log.Information("Shutting down existing F-Spot server..."); shutdown = true; } if (ApplicationContext.CommandLine.Contains("slideshow")) { Log.Information("Running F-Spot in slideshow mode."); slideshow = true; } if (ApplicationContext.CommandLine.Contains("basedir")) { string dir = ApplicationContext.CommandLine ["basedir"]; if (!string.IsNullOrEmpty(dir)) { FSpot.Core.Global.BaseDirectory = dir; Log.InformationFormat("BaseDirectory is now {0}", dir); } else { Log.Error("f-spot: -basedir option takes one argument"); return(1); } } if (ApplicationContext.CommandLine.Contains("photodir")) { string dir = ApplicationContext.CommandLine ["photodir"]; if (!string.IsNullOrEmpty(dir)) { FSpot.Core.Global.PhotoUri = new SafeUri(dir); Log.InformationFormat("PhotoDirectory is now {0}", dir); } else { Log.Error("f-spot: -photodir option takes one argument"); return(1); } } if (ApplicationContext.CommandLine.Contains("import")) { import = true; } if (ApplicationContext.CommandLine.Contains("view")) { view = true; } if (ApplicationContext.CommandLine.Contains("debug")) { Log.Debugging = true; // Debug GdkPixbuf critical warnings GLib.LogFunc logFunc = new GLib.LogFunc(GLib.Log.PrintTraceLogFunction); GLib.Log.SetLogHandler("GdkPixbuf", GLib.LogLevelFlags.Critical, logFunc); // Debug Gtk critical warnings GLib.Log.SetLogHandler("Gtk", GLib.LogLevelFlags.Critical, logFunc); // Debug GLib critical warnings GLib.Log.SetLogHandler("GLib", GLib.LogLevelFlags.Critical, logFunc); //Debug GLib-GObject critical warnings GLib.Log.SetLogHandler("GLib-GObject", GLib.LogLevelFlags.Critical, logFunc); GLib.Log.SetLogHandler("GLib-GIO", GLib.LogLevelFlags.Critical, logFunc); } // Validate command line options if ((import && (view || shutdown || slideshow)) || (view && (shutdown || slideshow)) || (shutdown && slideshow)) { Log.Error("Can't mix -import, -view, -shutdown or -slideshow"); return(1); } InitializeAddins(); // Gtk initialization Gtk.Application.Init(Defines.PACKAGE, ref args); // init web proxy globally Platform.WebProxy.Init(); if (File.Exists(Preferences.Get <string> (Preferences.GTK_RC))) { if (File.Exists(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc"))) { Gtk.Rc.AddDefaultFile(Path.Combine(FSpot.Core.Global.BaseDirectory, "gtkrc")); } FSpot.Core.Global.DefaultRcFiles = Gtk.Rc.DefaultFiles; Gtk.Rc.AddDefaultFile(Preferences.Get <string> (Preferences.GTK_RC)); Gtk.Rc.ReparseAllForSettings(Gtk.Settings.Default, true); } try { Gtk.Window.DefaultIconList = new Gdk.Pixbuf [] { GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 16, (Gtk.IconLookupFlags) 0), GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 22, (Gtk.IconLookupFlags) 0), GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 32, (Gtk.IconLookupFlags) 0), GtkUtil.TryLoadIcon(FSpot.Core.Global.IconTheme, "f-spot", 48, (Gtk.IconLookupFlags) 0) }; } catch {} CleanRoomStartup.Startup(Startup); return(0); }
private void Update() { Gtk.HTMLStream stream = this.Begin(null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll); string bg = Color(this.Style.Background(Gtk.StateType.Active)); string fg = Color(this.Style.Foreground(Gtk.StateType.Active)); string ig = Color(this.Style.Base(Gtk.StateType.Active)); stream.Write("<table width=100% cellpadding=5 cellspacing=0>"); bool empty = true; bool missing = false; System.Exception error = null; if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); if (entries.Length > 0) { empty = false; break; } } if (exif_info.Data.Length > 0) { stream.Write(String.Format("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" + "<img center src=\"exif:thumbnail\"></td></tr>", ig)); } int i = 0; foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); i++; if (entries.Length < 1) { continue; } stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1) + "</th><tr>"); foreach (Exif.ExifEntry entry in entries) { stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); if (entry.Title != null) { stream.Write(entry.Title); } else { stream.Write("<Unknown Tag ID=" + entry.Tag.ToString() + ">"); } stream.Write("</font></small></td><td>"); string s = entry.Value; if (s != null && s != String.Empty) { stream.Write(s); } stream.Write("</td><tr>"); } } } if (photo != null) { MetadataStore store = new MetadataStore(); try { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select(store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e) { // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } if (store.StatementCount > 0) { #if false using (System.IO.Stream xmpstream = System.IO.File.OpenWrite("tmp.xmp")) { xmpstream.Length = 0; FSpot.Xmp.XmpFile file; file = new FSpot.Xmp.XmpFile(); store.Select(file); file.Save(xmpstream); } #endif empty = false; stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Extended Metadata") + "</th></tr>"); foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0) { continue; } string title; string value; Description.GetDescription(store, stmt, out title, out value); stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); stream.Write(title); stream.Write("</font></small></td><td width=100%>"); if (value != null) { value = Escape(value); } else { MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load(); WriteCollection(substore, stream); } if (value != null && value != String.Empty) { stream.Write(value); } stream.Write("</td></tr>"); } } if (Core.Database != null && photo is Photo) { stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Exported Locations") + "</th></tr>"); Photo p = photo as Photo; foreach (ExportItem export in Core.Database.Exports.GetByImageId(p.Id, p.DefaultVersionId)) { string url = GetExportUrl(export); string label = GetExportLabel(export); if (url == null || label == null) { continue; } stream.Write("<tr colspan=2><td width=100%>"); stream.Write(String.Format("<a href=\"{0}\">{1}</a>", url, label)); stream.Write("</font></small></td></tr>"); } } } if (empty) { string msg; if (photo == null) { // FIXME we should pass the full selection to the info display and let it // handle multiple items however it wants. msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No active photo")); } else if (missing) { string text = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, text); } else { msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No metadata available")); if (error != null) { String.Format("<pre>{0}</pre>", error); } } stream.Write(msg); } stream.Write("</table>"); End(stream, Gtk.HTMLStreamStatus.Ok); }
public void Adjust() { bool create_version = photo.DefaultVersionId == Photo.OriginalVersionId; using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (image == null) { image = img.Load(); } if (image_profile == null) { image_profile = img.GetProfile(); } } if (image_profile == null) { image_profile = Cms.Profile.CreateStandardRgb(); } if (destination_profile == null) { destination_profile = image_profile; } Gdk.Pixbuf final = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height); Cms.Profile adjustment_profile = GenerateProfile(); Cms.Profile [] list; if (adjustment_profile != null) { list = new Cms.Profile [] { image_profile, adjustment_profile, destination_profile } } ; else { list = new Cms.Profile [] { image_profile, destination_profile } }; if (image.HasAlpha) { Pixbuf alpha = PixbufUtils.Flatten(image); Transform transform = new Transform(list, PixbufUtils.PixbufCmsFormat(alpha), PixbufUtils.PixbufCmsFormat(final), intent, 0x0000); PixbufUtils.ColorAdjust(alpha, final, transform); PixbufUtils.ReplaceColor(final, image); alpha.Dispose(); final.Dispose(); final = image; } else { Cms.Transform transform = new Cms.Transform(list, PixbufUtils.PixbufCmsFormat(image), PixbufUtils.PixbufCmsFormat(final), intent, 0x0000); PixbufUtils.ColorAdjust(image, final, transform); image.Dispose(); } photo.SaveVersion(final, create_version); final.Dispose(); } }