public static Gdk.Pixbuf FadeIcon(Gdk.Pixbuf source) { Gdk.Pixbuf result = source.Copy (); result.Fill (0); result = result.AddAlpha (true, 0, 0, 0); source.Composite (result, 0, 0, source.Width, source.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 128); return result; }
public CrossfadeIcon (Gdk.Pixbuf primary, Gdk.Pixbuf secondary) { if (primary == null) throw new ArgumentNullException ("primary"); if (secondary == null) throw new ArgumentNullException ("secondary"); this.primary = primary.Copy (); this.secondary = secondary.Copy (); }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { ProjectFile file = (ProjectFile) dataObject; label = file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName; if (!File.Exists (file.FilePath)) { label = "<span foreground='red'>" + label + "</span>"; } icon = DesktopService.GetPixbufForFile (file.FilePath, Gtk.IconSize.Menu); if (file.IsLink && icon != null) { icon = icon.Copy (); using (Gdk.Pixbuf overlay = Gdk.Pixbuf.LoadFromResource ("Icons.16x16.LinkOverlay.png")) { overlay.Composite (icon, 0, 0, icon.Width, icon.Width, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); } } }
/// <summary> /// This creates a new gray scale pixbuf. Note that this pixbuf needs to be disposed. /// </summary> /// <param name="icon"> /// A <see cref="Gdk.Pixbuf"/>. /// </param> /// <returns> /// A <see cref="Gdk.Pixbuf"/> gray scale version of "icon". /// </returns> public static Gdk.Pixbuf MakeGrayscale (Gdk.Pixbuf icon) { Gdk.Pixbuf copy = icon.Copy (); copy.SaturateAndPixelate (copy, 0, false); return copy; }
public static Gdk.Pixbuf MakeTransparent (Gdk.Pixbuf icon, double opacity) { Gdk.Pixbuf result = icon.Copy (); result.Fill (0); result = result.AddAlpha (true, 0, 0, 0); icon.Composite (result, 0, 0, icon.Width, icon.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, (int)(256 * opacity)); return result; }
public unsafe static Gdk.Pixbuf RemoveRedeye (Gdk.Pixbuf src, Gdk.Rectangle area, int threshold) //threshold, factors and comparisons borrowed from the gimp plugin 'redeye.c' by Robert Merkel #endif { Gdk.Pixbuf copy = src.Copy (); Gdk.Pixbuf selection = new Gdk.Pixbuf (copy, area.X, area.Y, area.Width, area.Height); #if OLREDEYE f_pixbuf_remove_redeye (selection.Handle); selection.Dispose (); #else byte *spix = (byte *)selection.Pixels; int h = selection.Height; int w = selection.Width; int channels = src.NChannels; double RED_FACTOR = 0.5133333; double GREEN_FACTOR = 1; double BLUE_FACTOR = 0.1933333; for (int j = 0; j < h; j++) { byte *s = spix; for (int i = 0; i < w; i++) { int adjusted_red = (int)(s[0] * RED_FACTOR); int adjusted_green = (int)(s[1] * GREEN_FACTOR); int adjusted_blue = (int)(s[2] * BLUE_FACTOR); if (adjusted_red >= adjusted_green - threshold && adjusted_red >= adjusted_blue - threshold) s[0] = (byte)(((double)(adjusted_green + adjusted_blue)) / (2.0 * RED_FACTOR)); s += channels; } spix += selection.Rowstride; } #endif return copy; }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { ProjectFile file = (ProjectFile) dataObject; label = GLib.Markup.EscapeText (file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName); if (!File.Exists (file.FilePath)) { label = "<span foreground='red'>" + label + "</span>"; } icon = DesktopService.GetPixbufForFile (file.FilePath, Gtk.IconSize.Menu); if (file.IsLink && icon != null) { var overlay = ImageService.GetPixbuf ("md-link-overlay", Gtk.IconSize.Menu); var cached = Context.GetComposedIcon (icon, overlay); if (cached != null) icon = cached; else { var res = icon.Copy (); overlay.Composite (res, 0, 0, icon.Width, icon.Width, 0, 0, 1, 1, Gdk.InterpType.Bilinear, 255); Context.CacheComposedIcon (icon, overlay, res); icon = res; } } }
//threshold, factors and comparisons borrowed from the gimp plugin 'redeye.c' by Robert Merkel public static unsafe Gdk.Pixbuf RemoveRedeye(Gdk.Pixbuf src, Gdk.Rectangle area, int threshold = -15) { Gdk.Pixbuf copy = src.Copy (); Gdk.Pixbuf selection = new Gdk.Pixbuf (copy, area.X, area.Y, area.Width, area.Height); byte * spix = (byte *)selection.Pixels; int h = selection.Height; int w = selection.Width; int channels = src.NChannels; double RED_FACTOR = 0.5133333; double GREEN_FACTOR = 1; double BLUE_FACTOR = 0.1933333; for (int j = 0; j < h; j++) { byte * s = spix; for (int i = 0; i < w; i++) { int adjusted_red = (int)(s [0] * RED_FACTOR); int adjusted_green = (int)(s [1] * GREEN_FACTOR); int adjusted_blue = (int)(s [2] * BLUE_FACTOR); if (adjusted_red >= adjusted_green - threshold && adjusted_red >= adjusted_blue - threshold) s [0] = (byte)(((double)(adjusted_green + adjusted_blue)) / (2.0 * RED_FACTOR)); s += channels; } spix += selection.Rowstride; } return copy; }
public Gdk.Pixbuf MakeTransparent(Gdk.Pixbuf icon, double opacity) { // If somebody knows a better way of doing this, please redo. Gdk.Pixbuf gicon = icon.Copy (); gicon.Fill (0); gicon = gicon.AddAlpha (true,0,0,0); icon.Composite (gicon, 0, 0, icon.Width, icon.Height, 0, 0, 1, 1, Gdk.InterpType.Bilinear, (int)(256 * opacity)); return gicon; }
public static Gdk.Pixbuf MakeInverted(Gdk.Pixbuf icon) { if (icon.BitsPerSample != 8) throw new NotSupportedException (); Gdk.Pixbuf copy = icon.Copy (); unsafe { byte* pix = (byte*)copy.Pixels; bool hasAlpha = copy.HasAlpha; for (int y = 0; y < copy.Height; y++) { var start = pix; for (int x = 0; x < copy.Width; x++) { pix [0] = (byte)~pix [0]; pix [1] = (byte)~pix [1]; pix [2] = (byte)~pix [2]; pix += hasAlpha ? 4 : 3; } pix = start + copy.Rowstride; } } return copy; }
Gdk.Pixbuf ExpandImageVertically (Gdk.Pixbuf img, int newHeight) { if (newHeight <= img.Height) return img.Copy (); var res = new Gdk.Pixbuf (img.Colorspace, img.HasAlpha, img.BitsPerSample, img.Width, newHeight); var h1 = img.Height / 2; var h2 = img.Height - h1; res.Fill (0xff000000); img.Composite (res, 0, h1, res.Width, newHeight - img.Height, 0, 0, 1, (double)newHeight / (double)img.Height, InterpType.Bilinear, 255); img.Composite (res, 0, 0, img.Width, h1, 0, 0, 1, 1, InterpType.Bilinear, 255); img.Composite (res, 0, newHeight - h2, img.Width, h2, 0, newHeight - img.Height, 1, 1, InterpType.Bilinear, 255); return res; }
/// <summary> /// This creates a new gray scale pixbuf. Note that this pixbuf needs to be disposed. /// </summary> /// <param name="icon"> /// A <see cref="Gdk.Pixbuf"/>. /// </param> /// <returns> /// A <see cref="Gdk.Pixbuf"/> gray scale version of "icon". /// </returns> public static Gdk.Pixbuf MakeGrayscale (Gdk.Pixbuf icon) { Gdk.Pixbuf copy = icon.Copy (); copy.SaturateAndPixelate (copy, 0, false); var icon2x = Get2xIconVariant (icon); if (icon2x != null) Set2xIconVariant (copy, MakeGrayscale (icon2x)); return copy; }
public override void BuildNode(ITreeBuilder builder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { // Add status overlays if (!(dataObject is ProjectFile)) return; if (!builder.Options["ShowVersionControlOverlays"]) return; ProjectFile file = (ProjectFile) dataObject; // TODO: Monitor changes not just to project files // but also to .svn directories to catch commits // and updates. WatchProject(file.Project); // When a file had a status and later has no status, // for whatever reason, it needs to be removed from the hashtable. fileStatus.Remove(file.FilePath); try { NodeStatus status = GetStatus(file.FilePath); if (status == NodeStatus.Unknown) return; fileStatus[file.FilePath] = status; Gdk.Pixbuf overlay = VersionControlService.LoadIconForStatus(status); double scale = (double)(2*icon.Width/3) / (double)overlay.Width; int w = (int)(overlay.Width*scale); int h = (int)(overlay.Height*scale); icon = icon.Copy(); overlay.Composite(icon, icon.Width-w, icon.Height-h, w, h, icon.Width-w, icon.Height-h, scale,scale, Gdk.InterpType.Bilinear, 255); } catch (Exception e) { } }