mypixmap.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* $Id$
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2, or (at your option)
  5. any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., Inc., 51 Franklin Street, Fifth Floor, Boston,
  13. MA 02110-1301, USA.
  14. xfwm4-windowck-plugin - (c) 2013 Cedric leporcq
  15. */
  16. #include <glib.h>
  17. #include "mypixmap.h"
  18. GdkPixbuf *
  19. pixbuf_alpha_load (const gchar * dir, const gchar * file)
  20. {
  21. gchar *filepng;
  22. gchar *filename;
  23. int i;
  24. static const char* image_types[] = {
  25. "svg",
  26. "png",
  27. "gif",
  28. "jpg",
  29. "bmp",
  30. NULL };
  31. i = 0;
  32. while ((image_types[i]))
  33. {
  34. filepng = g_strdup_printf ("%s.%s", file, image_types[i]);
  35. filename = g_build_filename (dir, filepng, NULL);
  36. g_free (filepng);
  37. if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
  38. {
  39. return gdk_pixbuf_new_from_file (filename, NULL);
  40. }
  41. g_free (filename);
  42. ++i;
  43. }
  44. return NULL;
  45. }
  46. static GdkPixbuf *
  47. pixmap_compose (GdkPixbuf *pixbuf, const gchar * dir, const gchar * file)
  48. {
  49. GdkPixbuf *alpha;
  50. gint width, height;
  51. alpha = pixbuf_alpha_load (dir, file);
  52. if (!alpha)
  53. {
  54. /* We have no suitable image to layer on top of the XPM, stop here... */
  55. return (pixbuf);
  56. }
  57. if (!pixbuf)
  58. {
  59. /* We have no XPM canvas and found a suitable image, use it... */
  60. return (alpha);
  61. }
  62. width = MIN (gdk_pixbuf_get_width (pixbuf),
  63. gdk_pixbuf_get_width (alpha));
  64. height = MIN (gdk_pixbuf_get_height (pixbuf),
  65. gdk_pixbuf_get_height (alpha));
  66. gdk_pixbuf_composite (alpha, pixbuf, 0, 0, width, height,
  67. 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 0xFF);
  68. g_object_unref (alpha);
  69. return pixbuf;
  70. }