Mercurial > audlegacy
annotate src/audacious/pixbuf_effects.c @ 3251:f02623377013
goodbye widgets directory
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Sun, 05 Aug 2007 16:43:53 +0200 |
parents | f1c756f39e6c |
children |
rev | line source |
---|---|
2313 | 1 /* |
2 * Audacious | |
3 * Copyright (c) 2006-2007 Audacious development team. | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2313
diff
changeset
|
7 * the Free Software Foundation; under version 3 of the License. |
2313 | 8 * |
9 * This program 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 | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2313
diff
changeset
|
15 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
16 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
17 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
18 * Audacious or using our public API to be a derived work. |
2313 | 19 */ |
20 | |
21 #include <glib.h> | |
22 | |
23 #include "platform/smartinclude.h" | |
24 #include "util.h" | |
25 | |
26 #include <gdk-pixbuf/gdk-pixbuf.h> | |
27 | |
28 static GdkPixbuf * | |
29 create_new_pixbuf (GdkPixbuf *src) | |
30 { | |
31 g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL); | |
32 g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src) | |
33 && gdk_pixbuf_get_n_channels (src) == 3) | |
34 || (gdk_pixbuf_get_has_alpha (src) | |
35 && gdk_pixbuf_get_n_channels (src) == 4), NULL); | |
36 | |
37 return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src), | |
38 gdk_pixbuf_get_has_alpha (src), | |
39 gdk_pixbuf_get_bits_per_sample (src), | |
40 gdk_pixbuf_get_width (src), | |
41 gdk_pixbuf_get_height (src)); | |
42 } | |
43 | |
44 GdkPixbuf * | |
45 audacious_create_colorized_pixbuf (GdkPixbuf *src, | |
46 int red_value, | |
47 int green_value, | |
48 int blue_value) | |
49 { | |
50 int i, j; | |
51 int width, height, has_alpha, src_row_stride, dst_row_stride; | |
52 guchar *target_pixels; | |
53 guchar *original_pixels; | |
54 guchar *pixsrc; | |
55 guchar *pixdest; | |
56 GdkPixbuf *dest; | |
57 | |
58 g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL); | |
59 g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src) | |
60 && gdk_pixbuf_get_n_channels (src) == 3) | |
61 || (gdk_pixbuf_get_has_alpha (src) | |
62 && gdk_pixbuf_get_n_channels (src) == 4), NULL); | |
63 g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL); | |
64 | |
65 dest = create_new_pixbuf (src); | |
66 | |
67 has_alpha = gdk_pixbuf_get_has_alpha (src); | |
68 width = gdk_pixbuf_get_width (src); | |
69 height = gdk_pixbuf_get_height (src); | |
70 src_row_stride = gdk_pixbuf_get_rowstride (src); | |
71 dst_row_stride = gdk_pixbuf_get_rowstride (dest); | |
72 target_pixels = gdk_pixbuf_get_pixels (dest); | |
73 original_pixels = gdk_pixbuf_get_pixels (src); | |
74 | |
75 for (i = 0; i < height; i++) { | |
76 pixdest = target_pixels + i*dst_row_stride; | |
77 pixsrc = original_pixels + i*src_row_stride; | |
78 for (j = 0; j < width; j++) { | |
79 *pixdest++ = (*pixsrc++ * red_value) >> 8; | |
80 *pixdest++ = (*pixsrc++ * green_value) >> 8; | |
81 *pixdest++ = (*pixsrc++ * blue_value) >> 8; | |
82 if (has_alpha) { | |
83 *pixdest++ = *pixsrc++; | |
84 } | |
85 } | |
86 } | |
87 return dest; | |
88 } | |
89 |