protected override void SendImage(Photo photo, Stream dest) { Gdk.Pixbuf thumb = XdgThumbnailSpec.LoadThumbnail(photo.DefaultVersion.Uri, ThumbnailSize.Large); byte[] buf = thumb.SaveToBuffer("png"); SendHeadersAndStartContent(dest, "Content-Type: " + MimeTypeForExt(".png"), "Content-Length: " + buf.Length, "Last-Modified: " + photo.Time.ToString("r")); dest.Write(buf, 0, buf.Length); }
public void TestMissingFile() { XdgThumbnailSpec.DefaultLoader = (u) => { throw new Exception("not found!"); }; var uri = new SafeUri("file:///invalid"); var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large); Assert.IsNull(pixbuf); }
public void DeleteVersion(uint version_id, bool remove_original, bool keep_file) { if (version_id == OriginalVersionId && !remove_original) { throw new Exception("Cannot delete original version"); } SafeUri uri = VersionUri(version_id); if (!keep_file) { GLib.File file = GLib.FileFactory.NewForUri(uri); if (file.Exists) { try { file.Trash(null); } catch (GLib.GException) { Log.Debug("Unable to Trash, trying to Delete"); file.Delete(); } } try { XdgThumbnailSpec.RemoveThumbnail(uri); } catch { // ignore an error here we don't really care. } // do we really need to check if the parent is a directory? // i.e. is file.Parent always a directory if the file instance is // an actual file? GLib.File directory = file.Parent; GLib.FileType file_type = directory.QueryFileType(GLib.FileQueryInfoFlags.None, null); if (directory.Exists && file_type == GLib.FileType.Directory) { DeleteEmptyDirectory(directory); } } versions.Remove(version_id); changes.RemoveVersion(version_id); for (version_id = highest_version_id; version_id >= OriginalVersionId; version_id--) { if (versions.ContainsKey(version_id)) { DefaultVersionId = version_id; break; } } }
protected virtual void ProcessRequest(CacheEntry entry) { Gdk.Pixbuf loaded = null; try { loaded = XdgThumbnailSpec.LoadThumbnail(entry.Uri, ThumbnailSize.Large); Update(entry, loaded); } catch (GLib.GException) { if (loaded != null) { loaded.Dispose(); } } }
void HandleThumbnailIconViewButtonPressEvent(object sender, Gtk.ButtonPressEventArgs args) { // Store caption before switching StoreCaption(); int old_item = current_item; current_item = tray_view.CellAtPosition((int)args.Event.X, (int)args.Event.Y); if (current_item < 0 || current_item >= items.Length) { current_item = old_item; return; } string caption = captions [current_item]; if (caption == null) { captions [current_item] = caption = ""; } caption_textview.Buffer.Text = caption; caption_textview.Sensitive = true; tag_treeview.Model = new TagStore(account.Facebook, tags [current_item], friends); IPhoto item = items [current_item]; if (tag_image_eventbox.Children.Length > 0) { tag_image_eventbox.Remove(tag_image); tag_image.Destroy(); } using (Gdk.Pixbuf data = XdgThumbnailSpec.LoadThumbnail(item.DefaultVersion.Uri, ThumbnailSize.Large)) { 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(); } }
private static void RotateOrientation(string original_path, RotateDirection direction) { try { var uri = new SafeUri(original_path); using (var metadata = Metadata.Parse(uri)) { metadata.EnsureAvailableTags(); var tag = metadata.ImageTag; var orientation = direction == RotateDirection.Clockwise ? FSpot.Utils.PixbufUtils.Rotate90(tag.Orientation) : FSpot.Utils.PixbufUtils.Rotate270(tag.Orientation); tag.Orientation = orientation; var always_sidecar = Preferences.Get <bool> (Preferences.METADATA_ALWAYS_USE_SIDECAR); metadata.SaveSafely(uri, always_sidecar); XdgThumbnailSpec.RemoveThumbnail(uri); } } catch (Exception e) { Log.DebugException(e); throw new RotateException(Catalog.GetString("Unable to rotate this type of photo"), original_path); } }
public void Load(SafeUri uri) { if (is_disposed) { return; } //First, send a thumbnail if we have one if ((thumb = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null)) != null) { pixbuf_orientation = ImageOrientation.TopLeft; EventHandler <AreaPreparedEventArgs> prep = AreaPrepared; if (prep != null) { prep(this, new AreaPreparedEventArgs(true)); } EventHandler <AreaUpdatedEventArgs> upd = AreaUpdated; if (upd != null) { upd(this, new AreaUpdatedEventArgs(new Rectangle(0, 0, thumb.Width, thumb.Height))); } } using (var image_file = ImageFile.Create(uri)) { image_stream = image_file.PixbufStream(); pixbuf_orientation = image_file.Orientation; } loading = true; // The ThreadPool.QueueUserWorkItem hack is there cause, as the bytes to read are present in the stream, // the Read is CompletedAsynchronously, blocking the mainloop image_stream.BeginRead(buffer, 0, count, delegate(IAsyncResult r) { ThreadPool.QueueUserWorkItem(delegate { HandleReadDone(r); }); }, null); }
protected virtual Pixbuf GetPixbuf(int i, bool highlighted) { Pixbuf current = null; SafeUri uri = (selection.Collection [i]).DefaultVersion.Uri; try { var pixbuf = thumb_cache.Get(uri); if (pixbuf != null) { current = pixbuf.ShallowCopy(); } } catch (IndexOutOfRangeException) { current = null; } if (current == null) { var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null); if (pixbuf == null) { ThumbnailLoader.Default.Request(uri, ThumbnailSize.Large, 0); current = FSpot.Core.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (IconLookupFlags)0); } else { if (SquaredThumbs) { current = PixbufUtils.IconFromPixbuf(pixbuf, ThumbSize); } else { current = pixbuf.ScaleSimple(ThumbSize, ThumbSize, InterpType.Nearest); } pixbuf.Dispose(); thumb_cache.Add(uri, current); } } //FIXME: we might end up leaking a pixbuf here Cms.Profile screen_profile; if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile)) { Pixbuf t = current.Copy(); current = t; ColorManagement.ApplyProfile(current, screen_profile); } // Add a four pixel white border around the thumbnail // for some reason we cannot use "using" here, it looks like the pixbuf copy is not done properly Pixbuf whiteBorder = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height); whiteBorder.Fill(0); current.CopyArea(1, 1, current.Width - 8, current.Height - 8, whiteBorder, 4, 4); current = whiteBorder; if (!highlighted) { return(current); } Pixbuf highlight = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height); highlight.Fill(ColorToInt(Style.Light(StateType.Selected))); // Add a two pixel highlight around the thumbnail current.CopyArea(2, 2, current.Width - 4, current.Height - 4, highlight, 2, 2); return(highlight); }
protected override void ProcessRequest(RequestItem request) { var size = request.Width == 128 ? ThumbnailSize.Normal : ThumbnailSize.Large; request.Result = XdgThumbnailSpec.LoadThumbnail(request.Uri, size); }