// Private utility methods. protected virtual void ProcessRequest(RequestItem request) { Pixbuf orig_image; try { using (FSpot.ImageFile img = System.IO.File.Exists(request.path) ? FSpot.ImageFile.Create(request.path) : FSpot.ImageFile.Create(new Uri(request.path))) { if (request.width > 0) { orig_image = img.Load(request.width, request.height); } else { orig_image = img.Load(); } } } catch (GLib.GException e) { System.Console.WriteLine(e.ToString()); return; } if (orig_image == null) { return; } request.result = orig_image; }
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); } }
private void FileLoad(ImageFile img) { pixbuf = img.Load(); done_reading = true; if (Done != null) { Done(this, System.EventArgs.Empty); } }
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 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); }
private void CreateTagIconFromExternalPhoto() { try { using (FSpot.ImageFile img = FSpot.ImageFile.Create(new Uri(external_photo_chooser.Uri))) { using (Gdk.Pixbuf external_image = img.Load()) { PreviewPixbuf = PixbufUtils.TagIconFromPixbuf(external_image); PreviewPixbuf_WithoutProfile = PreviewPixbuf.Copy(); FSpot.ColorManagement.ApplyScreenProfile(PreviewPixbuf); } } } catch (Exception) { string caption = Catalog.GetString("Unable to load image"); string message = String.Format(Catalog.GetString("Unable to load \"{0}\" as icon for the tag"), external_photo_chooser.Uri.ToString()); HigMessageDialog md = new HigMessageDialog(this.Dialog, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, caption, message); md.Run(); md.Destroy(); } }
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 (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load ((int) mx, (int) my); Cms.Profile printer_profile; if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_OUTPUT_PROFILE), out printer_profile)) FSpot.ColorManagement.ApplyProfile (pixbuf, img.GetProfile (), printer_profile); } catch (Exception e) { Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\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 (); } } } }
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; } //FIXME: if paper is landscape, swap ppx with ppy double w = context.Width / ppx; double h = context.Height / ppy; 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 (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load (); FSpot.ColorManagement.ApplyPrinterProfile (pixbuf, img.GetProfile ()); } catch (Exception e) { Log.Exception ("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\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); DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated); pixbuf.Dispose (); } } } }
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(); } }
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; } //FIXME: if paper is landscape, swap ppx with ppy double w = context.Width / ppx; double h = context.Height / ppy; 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 (ImageFile img = new ImageFile(selected_photos[p_index].DefaultVersionUri)) { Gdk.Pixbuf pixbuf; try { pixbuf = img.Load(); FSpot.ColorManagement.ApplyPrinterProfile(pixbuf, img.GetProfile()); } catch (Exception e) { Log.Exception("Unable to load image " + selected_photos[p_index].DefaultVersionUri + "\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); DrawComment(context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated); pixbuf.Dispose(); } } } }
private void FileLoad (ImageFile img) { pixbuf = img.Load (); done_reading = true; if (Done != null) Done (this, System.EventArgs.Empty); }
private void HandleThumbnailIconViewButtonPressEvent (object sender, Gtk.ButtonPressEventArgs args) { int old_item = current_item; current_item = thumbnail_iconview.CellAtPosition ((int) args.Event.X, (int) args.Event.Y, false); if (current_item < 0 || current_item >= items.Length) { current_item = old_item; return; } captions [old_item] = caption_textview.Buffer.Text; string caption = captions [current_item]; if (caption == null) captions [current_item] = caption = ""; caption_textview.Buffer.Text = caption; tag_treeview.Model = new TagStore (account.Facebook, tags [current_item], friends); IBrowsableItem item = items [current_item]; string thumbnail_path = ThumbnailGenerator.ThumbnailPath (item.DefaultVersionUri); if (tag_image_eventbox.Children.Length > 0) { tag_image_eventbox.Remove (tag_image); tag_image.Destroy (); } using (ImageFile image = new ImageFile (thumbnail_path)) { Gdk.Pixbuf data = image.Load (); data = PixbufUtils.ScaleToMaxSize (data, 400, 400); tag_image_height = data.Height; tag_image_width = data.Width; tag_image = new Gtk.Image (data); tag_image_eventbox.Add (tag_image); tag_image_eventbox.ShowAll (); } }