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); }
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(); } }
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); }