~unico-team/unico/trunk

« back to all changes in this revision

Viewing changes to unico/raico-blur.c

  • Committer: Ken VanDine
  • Date: 2012-08-08 16:28:32 UTC
  • mfrom: (139 refactor)
  • mto: (139.1.1 unico)
  • mto: This revision was merged to the branch mainline in revision 140.
  • Revision ID: ken.vandine@canonical.com-20120808162832-vmgto6docfq65f4d
New snapshot from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The Unico Theming Engine for Gtk+.
2
 
 * Copyright (C) 2009 Canonical Ltd
3
 
 *
4
 
 * This  library is free  software; you can  redistribute it and/or
5
 
 * modify it  under  the terms  of the  GNU Lesser  General  Public
6
 
 * License  as published  by the Free  Software  Foundation; either
7
 
 * version 2 of the License, or (at your option) any later version.
8
 
 *
9
 
 * This library 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 GNU
12
 
 * Lesser General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License  along  with  this library;  if not,  write to  the Free
16
 
 * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
17
 
 * MA 02110-1301, USA.
18
 
 *
19
 
 * Authored by Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
20
 
 *
21
 
 */
22
 
 
23
 
#include "exponential-blur.h"
24
 
#include "raico-blur.h"
25
 
 
26
 
struct _raico_blur_private_t
27
 
{
28
 
  raico_blur_quality_t quality; /* low, medium, high */
29
 
  guint                radius;  /* blur-radius */
30
 
};
31
 
 
32
 
raico_blur_t*
33
 
raico_blur_create (void)
34
 
{
35
 
  raico_blur_t*         blur = NULL;
36
 
  raico_blur_private_t* priv = NULL;
37
 
 
38
 
  blur = g_new0 (raico_blur_t, 1);
39
 
  if (!blur)
40
 
    {
41
 
      g_debug ("raico_blur_create(): could not allocate blur struct");
42
 
      return NULL;
43
 
    }
44
 
 
45
 
  priv = g_new0 (raico_blur_private_t, 1);
46
 
  if (!priv)
47
 
    {
48
 
      g_debug ("raico_blur_create(): could not allocate priv struct");
49
 
      g_free ((gpointer) blur);
50
 
      return NULL;
51
 
    }
52
 
 
53
 
  priv->quality = RAICO_BLUR_QUALITY_LOW;
54
 
 
55
 
  priv->radius  = 0;
56
 
 
57
 
  blur->priv = priv;
58
 
 
59
 
  return blur;
60
 
}
61
 
 
62
 
raico_blur_quality_t
63
 
raico_blur_get_quality (raico_blur_t* blur)
64
 
{
65
 
  g_assert (blur != NULL);
66
 
 
67
 
  return blur->priv->quality;
68
 
}
69
 
 
70
 
void
71
 
raico_blur_set_quality (raico_blur_t*        blur,
72
 
                        raico_blur_quality_t quality)
73
 
{
74
 
  if (!blur)
75
 
    {
76
 
      g_debug ("raico_blur_set_quality(): NULL blur-pointer passed");
77
 
      return;
78
 
    }
79
 
 
80
 
  blur->priv->quality = quality;
81
 
}
82
 
 
83
 
guint
84
 
raico_blur_get_radius (raico_blur_t* blur)
85
 
{
86
 
  g_assert (blur != NULL);
87
 
 
88
 
  return blur->priv->radius;
89
 
}
90
 
 
91
 
void
92
 
raico_blur_set_radius (raico_blur_t* blur,
93
 
                       guint         radius)
94
 
{
95
 
  if (!blur)
96
 
    {
97
 
      g_debug ("raico_blur_set_radius(): NULL blur-pointer passed");
98
 
      return;
99
 
    }
100
 
 
101
 
  blur->priv->radius = radius;
102
 
}
103
 
 
104
 
void
105
 
raico_blur_apply (raico_blur_t*    blur,
106
 
                  cairo_surface_t* surface)
107
 
{
108
 
  cairo_format_t format;
109
 
 
110
 
  /* sanity checks */
111
 
  if (!blur)
112
 
    {
113
 
      g_debug ("raico_blur_apply(): NULL blur-pointer passed");
114
 
      return;
115
 
    }
116
 
 
117
 
  if (!surface)
118
 
    {
119
 
      g_debug ("raico_blur_apply(): NULL surface-pointer passed");
120
 
      return;
121
 
    }
122
 
 
123
 
  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
124
 
    {
125
 
      g_debug ("raico_blur_apply(): invalid surface status");
126
 
      return;
127
 
    }
128
 
 
129
 
  if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_IMAGE)
130
 
    {
131
 
      g_debug ("raico_blur_apply(): non-image surface passed");
132
 
      return;
133
 
    }
134
 
 
135
 
  format = cairo_image_surface_get_format (surface);
136
 
  if (format != CAIRO_FORMAT_A8 &&
137
 
      format != CAIRO_FORMAT_RGB24 &&
138
 
      format != CAIRO_FORMAT_ARGB32)
139
 
    {
140
 
      g_debug ("raico_blur_apply(): unsupported image-format");
141
 
      return;
142
 
    }
143
 
 
144
 
  /* stupid, but you never know */
145
 
  if (blur->priv->radius == 0)
146
 
    return;
147
 
 
148
 
  /* now do the real work */
149
 
  switch (blur->priv->quality)
150
 
  {
151
 
    default:
152
 
    case RAICO_BLUR_QUALITY_HIGH:
153
 
    case RAICO_BLUR_QUALITY_MEDIUM:
154
 
      /* Not implemented yet */
155
 
      //surface_gaussian_blur (surface, blur->priv->radius);
156
 
    case RAICO_BLUR_QUALITY_LOW:
157
 
      surface_exponential_blur (surface, blur->priv->radius);
158
 
      break;
159
 
  }
160
 
}
161
 
 
162
 
void
163
 
raico_blur_destroy (raico_blur_t* blur)
164
 
{
165
 
  if (!blur)
166
 
    {
167
 
      g_debug ("raico_blur_destroy(): invalid blur-pointer passed");
168
 
      return;
169
 
    }
170
 
 
171
 
  g_free ((gpointer) blur->priv);
172
 
  g_free ((gpointer) blur);
173
 
}