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
|
|
7 * the Free Software Foundation; under version 2 of the License.
|
|
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
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 */
|
|
18
|
|
19 #include <glib.h>
|
|
20
|
|
21 #include "platform/smartinclude.h"
|
|
22 #include "util.h"
|
|
23
|
|
24 #include <gdk-pixbuf/gdk-pixbuf.h>
|
|
25
|
|
26 static GdkPixbuf *
|
|
27 create_new_pixbuf (GdkPixbuf *src)
|
|
28 {
|
|
29 g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
|
|
30 g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
|
|
31 && gdk_pixbuf_get_n_channels (src) == 3)
|
|
32 || (gdk_pixbuf_get_has_alpha (src)
|
|
33 && gdk_pixbuf_get_n_channels (src) == 4), NULL);
|
|
34
|
|
35 return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
|
|
36 gdk_pixbuf_get_has_alpha (src),
|
|
37 gdk_pixbuf_get_bits_per_sample (src),
|
|
38 gdk_pixbuf_get_width (src),
|
|
39 gdk_pixbuf_get_height (src));
|
|
40 }
|
|
41
|
|
42 GdkPixbuf *
|
|
43 audacious_create_colorized_pixbuf (GdkPixbuf *src,
|
|
44 int red_value,
|
|
45 int green_value,
|
|
46 int blue_value)
|
|
47 {
|
|
48 int i, j;
|
|
49 int width, height, has_alpha, src_row_stride, dst_row_stride;
|
|
50 guchar *target_pixels;
|
|
51 guchar *original_pixels;
|
|
52 guchar *pixsrc;
|
|
53 guchar *pixdest;
|
|
54 GdkPixbuf *dest;
|
|
55
|
|
56 g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
|
|
57 g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
|
|
58 && gdk_pixbuf_get_n_channels (src) == 3)
|
|
59 || (gdk_pixbuf_get_has_alpha (src)
|
|
60 && gdk_pixbuf_get_n_channels (src) == 4), NULL);
|
|
61 g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
|
|
62
|
|
63 dest = create_new_pixbuf (src);
|
|
64
|
|
65 has_alpha = gdk_pixbuf_get_has_alpha (src);
|
|
66 width = gdk_pixbuf_get_width (src);
|
|
67 height = gdk_pixbuf_get_height (src);
|
|
68 src_row_stride = gdk_pixbuf_get_rowstride (src);
|
|
69 dst_row_stride = gdk_pixbuf_get_rowstride (dest);
|
|
70 target_pixels = gdk_pixbuf_get_pixels (dest);
|
|
71 original_pixels = gdk_pixbuf_get_pixels (src);
|
|
72
|
|
73 for (i = 0; i < height; i++) {
|
|
74 pixdest = target_pixels + i*dst_row_stride;
|
|
75 pixsrc = original_pixels + i*src_row_stride;
|
|
76 for (j = 0; j < width; j++) {
|
|
77 *pixdest++ = (*pixsrc++ * red_value) >> 8;
|
|
78 *pixdest++ = (*pixsrc++ * green_value) >> 8;
|
|
79 *pixdest++ = (*pixsrc++ * blue_value) >> 8;
|
|
80 if (has_alpha) {
|
|
81 *pixdest++ = *pixsrc++;
|
|
82 }
|
|
83 }
|
|
84 }
|
|
85 return dest;
|
|
86 }
|
|
87
|