~ubuntu-branches/ubuntu/oneiric/docky/oneiric

« back to all changes in this revision

Viewing changes to Docky.Services/Docky.Services/Extensions/GdkPixbufExtension.cs

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2010-07-01 21:21:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100701212150-1dqehqxey8rrvtlo
Tags: 2.0.5-1
* New upstream release 2.0.5 "Be proud of your dock",
  changes include:
  + remove --debug flag from launcher for lower memory usage
  + update the about dialog credits to list documenters and make translation 
    tab easier to read
  + change url in about dialog to the launchpad project page
  + Window-Matching
    - fix for applications commandline
    - properly match qt creator (LP: #594814)
    - prefer local over global launchers (LP: #588073) (LP: #592841)
    - match prefix for gksudo (LP: #516433)
    - fix nautilus items showing active indicator when desktop 
      is focused (LP: #487113)
    - fix matching wine apps that use a prefixed launcher (LP: #596092)
  + Memory Leaks
    - dispose of calendar painter when the clock item is disposed
    - fix leak in AutoHideManager
    - several fixes using Cairo.Context.Target and Pango.Layout
    - fix leak in PagingPainters
    - fix leak in recursive file-deletion
    - fix leaking SeparatorItems, WnckDockItems
    - fix leaks with FileEmblems
    - fix Pixbuf related leaks
    - fix some leaks regarding FileMonitors
    - fix leaks regarding Tiles and AbtractTileObjects
    - fix leaking Glib.FileAdapter caused by unreferenced Action in 
      FileDockItem
  + Handle invalid desktopfile entry and UriFormatException in 
    FileApplicationProvider (LP: #595921)
  + fix potential crash for invalid HelperMetadata
  + handle drops correctly
  + fix handling of Helpers in HelperService
  + make the sliders in preferences behave better
  + fix drawing of rotated items
  + fix HoveredItem click-position
  + avoids fatal errors on console when loading embedded icons when no 
    height or width is specified and when dock items have a null Icon
  + fix icon theme change not refreshing the dock icons (LP: #590205)
  + fix SVG rendering bug
  + fix iconsize temporarily getting large when adding to full dock 
    (LP: #579576)
  + fix the 'crash in PinToDock' (LP: #588073)
  + make 3d background height more consistent and a tad larger (LP: #503038)
  + fix dragging multiple files to a folder on the dock, which caused 
    a crash and data corruption (LP: #579049)
  + don't request animations if urgent state is removed from a window and 
    fix glow location (LP: #596422)
  + fix window previews being offset (LP: #495065)
  + fix broken zoom after shrinking icon size (LP: #598924)
  + fix problem with hovers still visible when painters show
  + fix displaying default icon in place of missing file emblem (LP: #534651)
  + fix crash when gconf key for menus_have_icons is not set (LP: #573751)
  + make sure painters fit on screen (LP: #589978)
  + fix icon minimize animations not working immediately for some newly 
    opened windows
  + don't dispose our static DockyItem
  + fix CurrentDesktopOnly not working when dragging a window across desktops
    (LP: #600290)
  + GMail: 
    - fix thread-guards and remove deprecated code
    - fix problem with feeds that don't have an author entry (LP: #595530)
  + NPR: fix bug where removing your last NPR station unloaded the docklet
    and fix station icon
  + NetworkManager: fix crash caused when NM goes away
    and fix icons and add another fallback icon (LP: #588581)
  + Mounter:
    - fixed some leaks
    - only remove mounted items if they were successfully unmounted 
      (LP: #597637)
    - fix duplicate icons showing in mounter (LP: #525306)
  + Weather: fix feels like temp showing incorrect for metric (LP: #597670)
  + RecentDocuments: 
    - fixed some leaks
    - fix sensitivity of recent docs clear menu item - even if docky shows 
      the list as empty does not mean it cant be cleared
* debian/patches/01_use_cli_for_wrapper.patch:
  + patch wrapper script to meet the Debian CLI Policy
* debian/control:
  + Bump Standards version to 3.9.0 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  Copyright (C) 2010 Robert Dyer
 
3
// 
 
4
//  This program is free software: you can redistribute it and/or modify
 
5
//  it under the terms of the GNU General Public License as published by
 
6
//  the Free Software Foundation, either version 3 of the License, or
 
7
//  (at your option) any later version.
 
8
// 
 
9
//  This program is distributed in the hope that it will be useful,
 
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
//  GNU General Public License for more details.
 
13
// 
 
14
//  You should have received a copy of the GNU General Public License
 
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
// 
 
17
using System;
 
18
 
 
19
using Cairo;
 
20
using Gdk;
 
21
 
 
22
namespace Docky.Services
 
23
{
 
24
        public static class GdkPixbufExtension
 
25
        {
 
26
                // these methods all assume that the BitsPerSample is 8 (byte).  Pixbuf documentation
 
27
                // states that values from 1-16 are allowed, but currently only 8 bit samples are supported.
 
28
                // http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf--bits-per-sample
 
29
                
 
30
                /// <summary>
 
31
                /// Applies a color transformation to each pixel in a pixbuf.
 
32
                /// </summary>
 
33
                /// <param name="colorTransform">
 
34
                /// A <see cref="Func<Cairo.Color, Cairo.Color>"/>
 
35
                /// </param>
 
36
                /// <returns>
 
37
                /// A reference to the input Pixbuf (the 'this' reference).
 
38
                /// </returns>
 
39
                public static Pixbuf PixelColorTransform (this Pixbuf source, Func<Cairo.Color, Cairo.Color> colorTransform)
 
40
                {
 
41
                        try {
 
42
                                int offset = (source.HasAlpha) ? 4 : 3;
 
43
                                unsafe {
 
44
                                        double r, g, b;
 
45
                                        byte* pixels = (byte*) source.Pixels;
 
46
                                        for (int i = 0; i < source.Height * source.Width; i++) {
 
47
                                                r = (double) pixels[0];
 
48
                                                g = (double) pixels[1];
 
49
                                                b = (double) pixels[2];
 
50
                                                
 
51
                                                Cairo.Color color = new Cairo.Color (r / byte.MaxValue, 
 
52
                                                                                     g / byte.MaxValue, 
 
53
                                                                                     b / byte.MaxValue);
 
54
                                                
 
55
                                                color = colorTransform.Invoke (color);
 
56
                                                                                                
 
57
                                                pixels[0] = (byte) (color.R * byte.MaxValue);
 
58
                                                pixels[1] = (byte) (color.G * byte.MaxValue);
 
59
                                                pixels[2] = (byte) (color.B * byte.MaxValue);
 
60
                                                
 
61
                                                pixels += offset;
 
62
                                        }
 
63
                                }
 
64
                        } catch (Exception e) {
 
65
                                Log<DrawingService>.Error ("Error transforming pixbuf: {0}", e.Message);
 
66
                                Log<DrawingService>.Debug (e.StackTrace);
 
67
                        }
 
68
                        return source;
 
69
                }
 
70
                
 
71
                /// <summary>
 
72
                /// Returns a monochrome version of the supplied pixbuf.
 
73
                /// </summary>
 
74
                /// <returns>
 
75
                /// A reference to the input Pixbuf (the 'this' reference).
 
76
                /// </returns>
 
77
                public static Pixbuf MonochromePixbuf (this Pixbuf source)
 
78
                {
 
79
                        return source.PixelColorTransform ((c) => c.DarkenBySaturation (0.5).SetSaturation (0));
 
80
                }
 
81
                
 
82
                /// <summary>
 
83
                /// Adds a hue shift to the supplpied pixbuf.
 
84
                /// </summary>
 
85
                /// <param name="shift">
 
86
                /// A <see cref="System.Double"/>
 
87
                /// </param>
 
88
                /// <returns>
 
89
                /// A reference to the input Pixbuf (the 'this' reference).
 
90
                /// </returns>
 
91
                public static Pixbuf AddHueShift (this Pixbuf source, double shift)
 
92
                {
 
93
                        if (shift != 0)
 
94
                                source.PixelColorTransform ((c) => c.AddHue (shift));
 
95
                        return source;
 
96
                }
 
97
                
 
98
                /// <summary>
 
99
                /// Scale a pixbuf to the desired width or height maintaining the aspect ratio of the supplied pixbuf.
 
100
                /// Note that due to maintaining the aspect ratio, the returned pixbuf may not have the exact width AND height as is specified.
 
101
                /// Though it is guaranteed that one of these measurements will be correct.
 
102
                /// </summary>
 
103
                /// <param name="width">
 
104
                /// A <see cref="System.Int32"/>
 
105
                /// </param>
 
106
                /// <param name="height">
 
107
                /// A <see cref="System.Int32"/>
 
108
                /// </param>
 
109
                /// <param name="pixbuf">
 
110
                /// A <see cref="Pixbuf"/>
 
111
                /// </param>
 
112
                /// <returns>
 
113
                /// </returns>
 
114
                public static Pixbuf ARScale (this Pixbuf source, int width, int height)
 
115
                {                       
 
116
                        double xScale = (double) width / (double) source.Width;
 
117
                        double yScale = (double) height / (double) source.Height;
 
118
                        double scale = Math.Min (xScale, yScale);
 
119
                        
 
120
                        if (scale == 1)
 
121
                                return source;
 
122
                        
 
123
                        Pixbuf tmp = source.ScaleSimple ((int) (source.Width * scale),
 
124
                                                                                           (int) (source.Height * scale),
 
125
                                                                                           InterpType.Hyper);
 
126
                        source.Dispose ();
 
127
                        
 
128
                        return tmp;
 
129
                }
 
130
        }
 
131
}