summaryrefslogtreecommitdiffstats
path: root/tdegtk/raico-blur.c
blob: 3330ae2e83b4edf18d8b31c382c03d3984ebf1b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* The TdeGtk Theming Engine for Gtk+.
 * Copyright (C) 2009 Canonical Ltd
 *
 * This  library is free  software; you can  redistribute it and/or
 * modify it  under  the terms  of the  GNU Lesser  General  Public
 * License  as published  by the Free  Software  Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed  in the hope that it will be useful,
 * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License  along  with  this library;  if not,  write to  the Free
 * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * Authored by Mirco "MacSlow" Mueller <mirco.mueller@canonical.com>
 *
 */

#include "exponential-blur.h"
#include "raico-blur.h"

struct _raico_blur_private_t
{
  raico_blur_quality_t quality; /* low, medium, high */
  guint                radius;  /* blur-radius */
};

raico_blur_t*
raico_blur_create (void)
{
  raico_blur_t*         blur = NULL;
  raico_blur_private_t* priv = NULL;

  blur = g_new0 (raico_blur_t, 1);
  if (!blur)
    {
      g_debug ("raico_blur_create(): could not allocate blur struct");
      return NULL;
    }

  priv = g_new0 (raico_blur_private_t, 1);
  if (!priv)
    {
      g_debug ("raico_blur_create(): could not allocate priv struct");
      g_free ((gpointer) blur);
      return NULL;
    }

  priv->quality = RAICO_BLUR_QUALITY_LOW;

  priv->radius  = 0;

  blur->priv = priv;

  return blur;
}

raico_blur_quality_t
raico_blur_get_quality (raico_blur_t* blur)
{
  g_assert (blur != NULL);

  return blur->priv->quality;
}

void
raico_blur_set_quality (raico_blur_t*        blur,
                        raico_blur_quality_t quality)
{
  if (!blur)
    {
      g_debug ("raico_blur_set_quality(): NULL blur-pointer passed");
      return;
    }

  blur->priv->quality = quality;
}

guint
raico_blur_get_radius (raico_blur_t* blur)
{
  g_assert (blur != NULL);

  return blur->priv->radius;
}

void
raico_blur_set_radius (raico_blur_t* blur,
                       guint         radius)
{
  if (!blur)
    {
      g_debug ("raico_blur_set_radius(): NULL blur-pointer passed");
      return;
    }

  blur->priv->radius = radius;
}

void
raico_blur_apply (raico_blur_t*    blur,
                  cairo_surface_t* surface)
{
  cairo_format_t format;

  /* sanity checks */
  if (!blur)
    {
      g_debug ("raico_blur_apply(): NULL blur-pointer passed");
      return;
    }

  if (!surface)
    {
      g_debug ("raico_blur_apply(): NULL surface-pointer passed");
      return;
    }

  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
    {
      g_debug ("raico_blur_apply(): invalid surface status");
      return;
    }

  if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_IMAGE)
    {
      g_debug ("raico_blur_apply(): non-image surface passed");
      return;
    }

  format = cairo_image_surface_get_format (surface);
  if (format != CAIRO_FORMAT_A8 &&
      format != CAIRO_FORMAT_RGB24 &&
      format != CAIRO_FORMAT_ARGB32)
    {
      g_debug ("raico_blur_apply(): unsupported image-format");
      return;
    }

  /* stupid, but you never know */
  if (blur->priv->radius == 0)
    return;

  /* now do the real work */
  switch (blur->priv->quality)
  {
    default:
    case RAICO_BLUR_QUALITY_HIGH:
    case RAICO_BLUR_QUALITY_MEDIUM:
      /* Not implemented yet */
      //surface_gaussian_blur (surface, blur->priv->radius);
    case RAICO_BLUR_QUALITY_LOW:
      surface_exponential_blur (surface, blur->priv->radius);
      break;
  }
}

void
raico_blur_destroy (raico_blur_t* blur)
{
  if (!blur)
    {
      g_debug ("raico_blur_destroy(): invalid blur-pointer passed");
      return;
    }

  g_free ((gpointer) blur->priv);
  g_free ((gpointer) blur);
}