~ubuntu-branches/ubuntu/jaunty/gdesklets/jaunty-updates

« back to all changes in this revision

Viewing changes to utils/render.c

  • Committer: Bazaar Package Importer
  • Author(s): Deng Xiyue
  • Date: 2008-09-02 22:00:17 UTC
  • mfrom: (2.1.18 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080902220017-m66bj19l0ll8x7yh
Tags: 0.36-5
* Redo 40_dont_update_mime.diff to use a more compact syntax by 
  Loïc Minier's suggestion.  Thanks lool.
* Regenerate 70_relibtoolize.diff accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "render.h"
2
 
#include "filter.h"
3
2
 
4
3
#include <gdk/gdkx.h>
5
4
#include <string.h>
9
8
copy_n_rows (const GdkPixbuf *dest, const gint n,
10
9
             const gint row_size, const gint offset)
11
10
{
12
 
  guchar * const pixels = gdk_pixbuf_get_pixels (dest);
 
11
  guchar *pixels = gdk_pixbuf_get_pixels (dest);
13
12
  memcpy (pixels + offset, pixels, n * row_size);
14
13
}
15
14
 
43
42
}
44
43
 
45
44
 
 
45
static void
 
46
filter_opacity (const GdkPixbuf *pbuf, const gfloat opacity)
 
47
{
 
48
  guchar *data;
 
49
  gint x, y, rowstride, height;
 
50
 
 
51
  data  = gdk_pixbuf_get_pixels (pbuf);
 
52
 
 
53
  rowstride = gdk_pixbuf_get_rowstride (pbuf);
 
54
  height = gdk_pixbuf_get_height (pbuf);
 
55
  for (x = 3; x < rowstride; x += 4) {
 
56
    for (y = 0; y < height; y++) {
 
57
      data[y * rowstride + x] *= opacity;
 
58
    }
 
59
  }
 
60
}
 
61
 
46
62
void
47
 
render_to_image (GtkImage *image, GdkPixbuf *pbuf, gint width, gint height,
48
 
                 gfloat opacity, gfloat saturation)
 
63
render_to_image (GtkImage *image, GdkPixbuf *pbuf,
 
64
                 const gint width, const gint height,
 
65
                 const gfloat opacity, const gfloat saturation)
49
66
{
50
67
  GdkPixbuf *scaled;
51
68
 
62
79
  filter_opacity (scaled, opacity);
63
80
 
64
81
  /* set saturation */
65
 
  filter_saturation (scaled, saturation);
 
82
  gdk_pixbuf_saturate_and_pixelate (scaled, scaled, saturation, FALSE);
66
83
 
67
84
  /* set image */
68
85
  gtk_image_set_from_pixbuf (image, scaled);
104
121
 
105
122
void
106
123
render_background_fallback (GdkPixbuf *destination,
107
 
                            gint x, gint y, gint width, gint height)
 
124
                            const gint x, const gint y,
 
125
                            const gint width, const gint height)
108
126
{
109
 
  gint screen;
110
127
  Display *dpy;
 
128
  GdkWindow *gdkwin;
111
129
  XEvent ev;
112
 
  Window src;
113
 
  XSetWindowAttributes attrs = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L,
114
 
                                 0L, False, ExposureMask, 0L, True, 0, 0 };
115
 
  GdkWindow *gdkwin;
 
130
  XSetWindowAttributes attrs = { ParentRelative, 0L, 0, 0L, 0, 0, Always,
 
131
                                 0L, 0L, False, ExposureMask, 0L, True, 0, 0 };
116
132
 
117
133
  /* create overrideredirect window with CopyFromParent at the desired place */
118
 
  dpy = gdk_x11_get_default_xdisplay ();
119
 
  screen = DefaultScreen (dpy);
120
 
  src = XCreateWindow (dpy, RootWindow (dpy, screen), x, y,
 
134
  dpy                = gdk_x11_get_default_xdisplay ();
 
135
  const gint screen  = DefaultScreen (dpy);
 
136
  const Window src   = XCreateWindow (dpy, RootWindow (dpy, screen), x, y,
121
137
                       width, height, 0, CopyFromParent, CopyFromParent,
122
138
                       CopyFromParent, CWBackPixmap | CWBackingStore |
123
139
                       CWOverrideRedirect | CWEventMask,
148
164
                   glong wallpaper_id, gint x, gint y, gint width, gint height)
149
165
{
150
166
 
151
 
  gint         pwidth, pheight, sx, sy;
 
167
  gint         pwidth, pheight;
152
168
  GdkColormap *cmap;
153
169
  GdkPixmap   *pmap;
154
 
  GdkWindow   *rootwin;
155
170
 
 
171
  /* get root window */
 
172
  const GdkWindow *rootwin = gdk_get_default_root_window ();
 
173
  /* get colormap of root window */
 
174
  cmap = gdk_drawable_get_colormap (GDK_DRAWABLE (rootwin));
156
175
  /* get pixmap from X server */
157
176
  pmap = gdk_pixmap_foreign_new ((GdkNativeWindow) wallpaper_id);
 
177
  /* get dimensions */
158
178
  gdk_drawable_get_size (GDK_DRAWABLE (pmap), &pwidth, &pheight);
159
179
 
160
 
  rootwin = gdk_get_default_root_window ();
161
 
  cmap = gdk_drawable_get_colormap (GDK_DRAWABLE (rootwin));
162
 
 
163
180
  /* tile wallpaper over pixbuf */
164
 
  sx = - (x % pwidth);
165
 
  sy = - (y % pheight);
 
181
  const gint sx = - (x % pwidth);
 
182
  const gint sy = - (y % pheight);
166
183
  for (x = sx; x < width; x += pwidth) {
167
184
    for (y = sy; y < height; y += pheight) {
168
 
      gint dstx = MAX (0, x);
169
 
      gint dsty = MAX (0, y);
170
 
      gint srcx = dstx - x;
171
 
      gint srcy = dsty - y;
172
 
      gint w = MIN (pwidth - srcx, width - dstx);
173
 
      gint h = MIN (pheight - srcy, height - dsty);
 
185
      const gint dstx = MAX (0, x);
 
186
      const gint dsty = MAX (0, y);
 
187
      const gint srcx = dstx - x;
 
188
      const gint srcy = dsty - y;
 
189
      const gint w = MIN (pwidth - srcx, width - dstx);
 
190
      const gint h = MIN (pheight - srcy, height - dsty);
174
191
      gdk_pixbuf_get_from_drawable (destination, pmap, cmap, srcx, srcy,
175
192
                                    dstx, dsty, w, h);
176
193
    }