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
|
/*
* GQview
* (C) 2001 John Ellis
*
* Author: John Ellis
*
* This software is released under the GNU General Public License (GNU GPL).
* Please read the included file COPYING for more information.
* This software comes with no warranty of any kind, use at your own risk!
*/
#include "pixbuf_util.h"
/*
* Returns a copy of pixbuf mirrored and or flipped.
* TO do a 180 degree rotations set both mirror and flipped TRUE
* if mirror and flip are FALSE, result is a simple copy.
*/
GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gint mirror, gint flip)
{
GdkPixbuf *dest;
gint has_alpha;
gint w, h, srs;
gint drs;
guchar *s_pix;
guchar *d_pix;
guchar *sp;
guchar *dp;
gint i, j;
gint a;
if (!src) return NULL;
w = gdk_pixbuf_get_width(src);
h = gdk_pixbuf_get_height(src);
has_alpha = gdk_pixbuf_get_has_alpha(src);
srs = gdk_pixbuf_get_rowstride(src);
s_pix = gdk_pixbuf_get_pixels(src);
dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, w, h);
drs = gdk_pixbuf_get_rowstride(dest);
d_pix = gdk_pixbuf_get_pixels(dest);
a = has_alpha ? 4 : 3;
for (i = 0; i < h; i++)
{
sp = s_pix + (i * srs);
if (flip)
{
dp = d_pix + ((h - i - 1) * drs);
}
else
{
dp = d_pix + (i * drs);
}
if (mirror)
{
dp += (w - 1) * a;
for (j = 0; j < w; j++)
{
*(dp++) = *(sp++); /* r */
*(dp++) = *(sp++); /* g */
*(dp++) = *(sp++); /* b */
if (has_alpha) *(dp) = *(sp++); /* a */
dp -= (a + 3);
}
}
else
{
for (j = 0; j < w; j++)
{
*(dp++) = *(sp++); /* r */
*(dp++) = *(sp++); /* g */
*(dp++) = *(sp++); /* b */
if (has_alpha) *(dp++) = *(sp++); /* a */
}
}
}
return dest;
}
/* Copyright 2006 Miguel DE IZARRA
* Base on function gdk_pixbuf_fill from gdk_pixbuf
*/
void pixbuf_add_transparent (GdkPixbuf *pixbuf,guint alpha)
{
guchar *pixels;
guchar *p;
guint w, h;
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
g_return_if_fail(gdk_pixbuf_get_has_alpha(pixbuf));
if (gdk_pixbuf_get_width(pixbuf) == 0 || gdk_pixbuf_get_height(pixbuf) == 0)
return;
pixels = gdk_pixbuf_get_pixels(pixbuf);
h = gdk_pixbuf_get_height(pixbuf);
while (h--) {
w = gdk_pixbuf_get_width(pixbuf);
p = pixels;
while (w--) {
if(p[3] > alpha)
p[3] = p[3] - alpha;
else
p[3] = 0;
p += 4;
}
pixels += gdk_pixbuf_get_rowstride(pixbuf);
}
}
|