Theme engine using TQt for GTK+ 3.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

raico-blur.c 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* The TdeGtk 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. #include "exponential-blur.h"
  23. #include "raico-blur.h"
  24. struct _raico_blur_private_t
  25. {
  26. raico_blur_quality_t quality; /* low, medium, high */
  27. guint radius; /* blur-radius */
  28. };
  29. raico_blur_t*
  30. raico_blur_create (void)
  31. {
  32. raico_blur_t* blur = NULL;
  33. raico_blur_private_t* priv = NULL;
  34. blur = g_new0 (raico_blur_t, 1);
  35. if (!blur)
  36. {
  37. g_debug ("raico_blur_create(): could not allocate blur struct");
  38. return NULL;
  39. }
  40. priv = g_new0 (raico_blur_private_t, 1);
  41. if (!priv)
  42. {
  43. g_debug ("raico_blur_create(): could not allocate priv struct");
  44. g_free ((gpointer) blur);
  45. return NULL;
  46. }
  47. priv->quality = RAICO_BLUR_QUALITY_LOW;
  48. priv->radius = 0;
  49. blur->priv = priv;
  50. return blur;
  51. }
  52. raico_blur_quality_t
  53. raico_blur_get_quality (raico_blur_t* blur)
  54. {
  55. g_assert (blur != NULL);
  56. return blur->priv->quality;
  57. }
  58. void
  59. raico_blur_set_quality (raico_blur_t* blur,
  60. raico_blur_quality_t quality)
  61. {
  62. if (!blur)
  63. {
  64. g_debug ("raico_blur_set_quality(): NULL blur-pointer passed");
  65. return;
  66. }
  67. blur->priv->quality = quality;
  68. }
  69. guint
  70. raico_blur_get_radius (raico_blur_t* blur)
  71. {
  72. g_assert (blur != NULL);
  73. return blur->priv->radius;
  74. }
  75. void
  76. raico_blur_set_radius (raico_blur_t* blur,
  77. guint radius)
  78. {
  79. if (!blur)
  80. {
  81. g_debug ("raico_blur_set_radius(): NULL blur-pointer passed");
  82. return;
  83. }
  84. blur->priv->radius = radius;
  85. }
  86. void
  87. raico_blur_apply (raico_blur_t* blur,
  88. cairo_surface_t* surface)
  89. {
  90. cairo_format_t format;
  91. /* sanity checks */
  92. if (!blur)
  93. {
  94. g_debug ("raico_blur_apply(): NULL blur-pointer passed");
  95. return;
  96. }
  97. if (!surface)
  98. {
  99. g_debug ("raico_blur_apply(): NULL surface-pointer passed");
  100. return;
  101. }
  102. if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
  103. {
  104. g_debug ("raico_blur_apply(): invalid surface status");
  105. return;
  106. }
  107. if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_IMAGE)
  108. {
  109. g_debug ("raico_blur_apply(): non-image surface passed");
  110. return;
  111. }
  112. format = cairo_image_surface_get_format (surface);
  113. if (format != CAIRO_FORMAT_A8 &&
  114. format != CAIRO_FORMAT_RGB24 &&
  115. format != CAIRO_FORMAT_ARGB32)
  116. {
  117. g_debug ("raico_blur_apply(): unsupported image-format");
  118. return;
  119. }
  120. /* stupid, but you never know */
  121. if (blur->priv->radius == 0)
  122. return;
  123. /* now do the real work */
  124. switch (blur->priv->quality)
  125. {
  126. default:
  127. case RAICO_BLUR_QUALITY_HIGH:
  128. case RAICO_BLUR_QUALITY_MEDIUM:
  129. /* Not implemented yet */
  130. //surface_gaussian_blur (surface, blur->priv->radius);
  131. case RAICO_BLUR_QUALITY_LOW:
  132. surface_exponential_blur (surface, blur->priv->radius);
  133. break;
  134. }
  135. }
  136. void
  137. raico_blur_destroy (raico_blur_t* blur)
  138. {
  139. if (!blur)
  140. {
  141. g_debug ("raico_blur_destroy(): invalid blur-pointer passed");
  142. return;
  143. }
  144. g_free ((gpointer) blur->priv);
  145. g_free ((gpointer) blur);
  146. }