annotate src/pixbuf_util.c @ 155:d06bccc7551e

show active marks in image overlay
author nadvornik
date Fri, 14 Dec 2007 21:51:46 +0000
parents eb9bb29cbd65
children f6e307c7bad6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * GQview
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #include "gqview.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #include "pixbuf_util.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "icons/icons_inline.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
33
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
18 #include <math.h>
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
19
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 * png save
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 gboolean pixbuf_to_file_as_png (GdkPixbuf *pixbuf, const char *filename)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 if (!pixbuf || !filename) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 ret = gdk_pixbuf_save(pixbuf, filename, "png", &error,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 "tEXt::Software", "GQview "VERSION, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 printf("Error saving png file: %s\n", error->message);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 * jpeg save
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 gboolean pixbuf_to_file_as_jpg(GdkPixbuf *pixbuf, const gchar *filename, gint quality)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 gchar *qbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 gboolean ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 if (!pixbuf || !filename) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 if (quality == -1) quality = 75;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 if (quality < 1 || quality > 100)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 printf("Jpeg not saved, invalid quality %d\n", quality);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 qbuf = g_strdup_printf("%d", quality);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 ret = gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", qbuf, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 g_free(qbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 printf("Error saving jpeg to %s\n%s\n", filename, error->message);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 * pixbuf from inline
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 typedef struct _PixbufInline PixbufInline;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 struct _PixbufInline
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 const gchar *key;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 const guint8 *data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 static PixbufInline inline_pixbuf_data[] = {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 { PIXBUF_INLINE_FOLDER_CLOSED, folder_closed },
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 { PIXBUF_INLINE_FOLDER_LOCKED, folder_locked },
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 { PIXBUF_INLINE_FOLDER_OPEN, folder_open },
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 { PIXBUF_INLINE_FOLDER_UP, folder_up },
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 { PIXBUF_INLINE_SCROLLER, icon_scroller },
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 { PIXBUF_INLINE_BROKEN, icon_broken },
91
d063f97503b7 Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 82
diff changeset
100 { PIXBUF_INLINE_ICON, gqview_icon },
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 { PIXBUF_INLINE_LOGO, gqview_logo },
41
6281cc38e5ca Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents: 33
diff changeset
102 { PIXBUF_INLINE_ICON_FLOAT, icon_float },
6281cc38e5ca Wed Apr 27 15:17:57 2005 John Ellis <johne@verizon.net>
gqview
parents: 33
diff changeset
103 { PIXBUF_INLINE_ICON_THUMB, icon_thumb },
91
d063f97503b7 Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 82
diff changeset
104 { PIXBUF_INLINE_ICON_BOOK, icon_book },
d063f97503b7 Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 82
diff changeset
105 { PIXBUF_INLINE_ICON_CONFIG, icon_config },
d063f97503b7 Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 82
diff changeset
106 { PIXBUF_INLINE_ICON_TOOLS, icon_tools },
d063f97503b7 Wed Nov 1 11:39:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 82
diff changeset
107 { PIXBUF_INLINE_ICON_VIEW, icon_view },
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 { NULL, NULL }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 };
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 GdkPixbuf *pixbuf_inline(const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 if (!key) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 i = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 while (inline_pixbuf_data[i].key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 if (strcmp(inline_pixbuf_data[i].key, key) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 return gdk_pixbuf_new_from_inline(-1, inline_pixbuf_data[i].data, FALSE, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 i++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 printf("warning: inline pixbuf key \"%s\" not found.\n", key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 *-----------------------------------------------------------------------------
33
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
134 * misc utils
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
135 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
136 */
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
137
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
138 gint util_clip_region(gint x, gint y, gint w, gint h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
139 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
140 gint *rx, gint *ry, gint *rw, gint *rh)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
141 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
142 if (clip_x + clip_w <= x ||
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
143 clip_x >= x + w ||
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
144 clip_y + clip_h <= y ||
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
145 clip_y >= y + h)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
146 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
147 return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
148 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
149
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
150 *rx = MAX(x, clip_x);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
151 *rw = MIN((x + w), (clip_x + clip_w)) - *rx;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
152
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
153 *ry = MAX(y, clip_y);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
154 *rh = MIN((y + h), (clip_y + clip_h)) - *ry;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
155
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
156 return TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
157 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
158
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
159 /*
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
160 *-----------------------------------------------------------------------------
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 * pixbuf rotation
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 static void pixbuf_copy_block_rotate(guchar *src, gint src_row_stride, gint x, gint y,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 guchar *dest, gint dest_row_stride, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 gint bytes_per_pixel, gint counter_clockwise)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 guchar *sp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 guchar *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 sp = src + ((i + y) * src_row_stride) + (x * bytes_per_pixel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 if (counter_clockwise)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 dp = dest + ((w - j - 1) * dest_row_stride) + (i * bytes_per_pixel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 dp = dest + (j * dest_row_stride) + ((h - i - 1) * bytes_per_pixel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 *(dp++) = *(sp++); /* r */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 *(dp++) = *(sp++); /* g */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 *(dp++) = *(sp++); /* b */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 if (bytes_per_pixel == 4) *(dp) = *(sp++); /* a */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 static void pixbuf_copy_block(guchar *src, gint src_row_stride, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 guchar *dest, gint dest_row_stride, gint x, gint y, gint bytes_per_pixel)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 guchar *sp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 guchar *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 sp = src + (i * src_row_stride);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 dp = dest + ((y + i) * dest_row_stride) + (x * bytes_per_pixel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 memcpy(dp, sp, w * bytes_per_pixel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 #define ROTATE_BUFFER_WIDTH 48
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 #define ROTATE_BUFFER_HEIGHT 48
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 * Returns a copy of pixbuf src rotated 90 degrees clockwise or 90 counterclockwise
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gint counter_clockwise)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 GdkPixbuf *dest;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 gint has_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 gint sw, sh, srs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 gint dw, dh, drs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 guchar *s_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 guchar *d_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 guchar *sp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 guchar *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 gint a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 GdkPixbuf *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 guchar *b_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 gint brs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 if (!src) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 sw = gdk_pixbuf_get_width(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 sh = gdk_pixbuf_get_height(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 has_alpha = gdk_pixbuf_get_has_alpha(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 srs = gdk_pixbuf_get_rowstride(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 s_pix = gdk_pixbuf_get_pixels(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 dw = sh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 dh = sw;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, dw, dh);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 drs = gdk_pixbuf_get_rowstride(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 d_pix = gdk_pixbuf_get_pixels(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 a = (has_alpha ? 4 : 3);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 ROTATE_BUFFER_WIDTH, ROTATE_BUFFER_HEIGHT);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 b_pix = gdk_pixbuf_get_pixels(buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 brs = gdk_pixbuf_get_rowstride(buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 for (i = 0; i < sh; i+= ROTATE_BUFFER_WIDTH)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 w = MIN(ROTATE_BUFFER_WIDTH, (sh - i));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 for (j = 0; j < sw; j += ROTATE_BUFFER_HEIGHT)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 gint x, y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 h = MIN(ROTATE_BUFFER_HEIGHT, (sw - j));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 pixbuf_copy_block_rotate(s_pix, srs, j, i,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 b_pix, brs, h, w,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 a, counter_clockwise);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 if (counter_clockwise)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 x = i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 y = sw - h - j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 x = sh - w - i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 y = j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 pixbuf_copy_block(b_pix, brs, w, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 d_pix, drs, x, y, a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 gdk_pixbuf_unref(buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 /* this is the simple version of rotation (roughly 2-4x slower) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 for (i = 0; i < sh; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 sp = s_pix + (i * srs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 for (j = 0; j < sw; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 if (counter_clockwise)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 dp = d_pix + ((dh - j - 1) * drs) + (i * a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 dp = d_pix + (j * drs) + ((dw - i - 1) * a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 *(dp++) = *(sp++); /* r */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 *(dp++) = *(sp++); /* g */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 *(dp++) = *(sp++); /* b */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 if (has_alpha) *(dp) = *(sp++); /* a */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 return dest;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 * Returns a copy of pixbuf mirrored and or flipped.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 * TO do a 180 degree rotations set both mirror and flipped TRUE
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 * if mirror and flip are FALSE, result is a simple copy.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gint mirror, gint flip)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 GdkPixbuf *dest;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 gint has_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 gint w, h, srs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 gint drs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 guchar *s_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 guchar *d_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 guchar *sp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 guchar *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 gint a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 if (!src) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 w = gdk_pixbuf_get_width(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 h = gdk_pixbuf_get_height(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 has_alpha = gdk_pixbuf_get_has_alpha(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 srs = gdk_pixbuf_get_rowstride(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 s_pix = gdk_pixbuf_get_pixels(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341 drs = gdk_pixbuf_get_rowstride(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 d_pix = gdk_pixbuf_get_pixels(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 a = has_alpha ? 4 : 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 sp = s_pix + (i * srs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 if (flip)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 dp = d_pix + ((h - i - 1) * drs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 dp = d_pix + (i * drs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 if (mirror)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 dp += (w - 1) * a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 *(dp++) = *(sp++); /* r */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 *(dp++) = *(sp++); /* g */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 *(dp++) = *(sp++); /* b */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 if (has_alpha) *(dp) = *(sp++); /* a */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 dp -= (a + 3);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 *(dp++) = *(sp++); /* r */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 *(dp++) = *(sp++); /* g */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 *(dp++) = *(sp++); /* b */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 if (has_alpha) *(dp++) = *(sp++); /* a */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 return dest;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 *-----------------------------------------------------------------------------
33
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
387 * pixbuf drawing (rectangles)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 * Fills region of pixbuf at x,y over w,h
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 * with colors red (r), green (g), blue (b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 * applying alpha (a), use a=255 for solid.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 void pixbuf_draw_rect_fill(GdkPixbuf *pb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 gint x, gint y, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 gint r, gint g, gint b, gint a)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 gint p_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 gint pw, ph, prs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 guchar *p_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 guchar *pp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 if (!pb) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 pw = gdk_pixbuf_get_width(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 ph = gdk_pixbuf_get_height(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 if (x < 0 || x + w > pw) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 if (y < 0 || y + h > ph) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 p_alpha = gdk_pixbuf_get_has_alpha(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 prs = gdk_pixbuf_get_rowstride(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 p_pix = gdk_pixbuf_get_pixels(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 *pp = (r * a + *pp * (256-a)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 *pp = (g * a + *pp * (256-a)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 *pp = (b * a + *pp * (256-a)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 if (p_alpha) pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 void pixbuf_draw_rect(GdkPixbuf *pb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 gint x, gint y, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 gint r, gint g, gint b, gint a,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 gint left, gint right, gint top, gint bottom)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 pixbuf_draw_rect_fill(pb, x + left, y, w - left - right, top,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 pixbuf_draw_rect_fill(pb, x + w - right, y, right, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 pixbuf_draw_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 pixbuf_draw_rect_fill(pb, x, y, left, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 void pixbuf_set_rect_fill(GdkPixbuf *pb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 gint x, gint y, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 gint r, gint g, gint b, gint a)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 gint p_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 gint pw, ph, prs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 guchar *p_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 guchar *pp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 if (!pb) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 pw = gdk_pixbuf_get_width(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 ph = gdk_pixbuf_get_height(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 if (x < 0 || x + w > pw) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 if (y < 0 || y + h > ph) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 p_alpha = gdk_pixbuf_get_has_alpha(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 prs = gdk_pixbuf_get_rowstride(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 p_pix = gdk_pixbuf_get_pixels(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 *pp = r; pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 *pp = g; pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 *pp = b; pp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 if (p_alpha) { *pp = a; pp++; }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 void pixbuf_set_rect(GdkPixbuf *pb,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 gint x, gint y, gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 gint r, gint g, gint b, gint a,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 gint left, gint right, gint top, gint bottom)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 pixbuf_set_rect_fill(pb, x + left, y, w - left - right, top,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 pixbuf_set_rect_fill(pb, x + w - right, y, right, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 pixbuf_set_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 pixbuf_set_rect_fill(pb, x, y, left, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 r, g, b ,a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 void pixbuf_pixel_set(GdkPixbuf *pb, gint x, gint y, gint r, gint g, gint b, gint a)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 guchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 gint has_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 gint rowstride;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 guchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 if (x < 0 || x >= gdk_pixbuf_get_width(pb) ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 y < 0 || y >= gdk_pixbuf_get_height(pb)) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 buf = gdk_pixbuf_get_pixels(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 has_alpha = gdk_pixbuf_get_has_alpha(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 rowstride = gdk_pixbuf_get_rowstride(pb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 p = buf + (y * rowstride) + (x * (has_alpha ? 4 : 3));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 *p = r; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 *p = g; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 *p = b; p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 if (has_alpha) *p = a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 * pixbuf text rendering
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 static void pixbuf_copy_font(GdkPixbuf *src, gint sx, gint sy,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 GdkPixbuf *dest, gint dx, gint dy,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 gint w, gint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 guint8 r, guint8 g, guint8 b, guint8 a)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 gint sw, sh, srs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 gint s_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 gint s_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 guchar *s_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 gint dw, dh, drs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 gint d_alpha;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 gint d_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 guchar *d_pix;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 guchar *sp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 guchar *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 gint i, j;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 if (!src || !dest) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 sw = gdk_pixbuf_get_width(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 sh = gdk_pixbuf_get_height(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 if (sx < 0 || sx + w > sw) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 if (sy < 0 || sy + h > sh) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 dw = gdk_pixbuf_get_width(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 dh = gdk_pixbuf_get_height(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 if (dx < 0 || dx + w > dw) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 if (dy < 0 || dy + h > dh) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 s_alpha = gdk_pixbuf_get_has_alpha(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 d_alpha = gdk_pixbuf_get_has_alpha(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 srs = gdk_pixbuf_get_rowstride(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 drs = gdk_pixbuf_get_rowstride(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 s_pix = gdk_pixbuf_get_pixels(src);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 d_pix = gdk_pixbuf_get_pixels(dest);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 s_step = (s_alpha) ? 4 : 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 d_step = (d_alpha) ? 4 : 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 for (i = 0; i < h; i++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 sp = s_pix + (sy + i) * srs + sx * s_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 dp = d_pix + (dy + i) * drs + dx * d_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 for (j = 0; j < w; j++)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 if (*sp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 guint8 asub;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 asub = a * sp[0] / 255;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 *dp = (r * asub + *dp * (256-asub)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 dp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 asub = a * sp[1] / 255;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 *dp = (g * asub + *dp * (256-asub)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 dp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 asub = a * sp[2] / 255;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 *dp = (b * asub + *dp * (256-asub)) >> 8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 dp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 if (d_alpha)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 *dp = MAX(*dp, a * ((sp[0] + sp[1] + sp[2]) / 3) / 255);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 dp++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597 dp += d_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 sp += s_step;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widget,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 gint x, gint y,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 guint8 r, guint8 g, guint8 b, guint8 a)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 GdkPixmap *pixmap;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 GdkPixbuf *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 gint w, h;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 GdkGC *gc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 gint sx, sy;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 gint dw, dh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 if (!widget || !widget->window) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 pango_layout_get_pixel_size(layout, &w, &h);
95
eb9bb29cbd65 Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 91
diff changeset
619 if (w < 1 || h < 1) return;
eb9bb29cbd65 Fri Nov 3 11:40:48 2006 John Ellis <johne@verizon.net>
gqview
parents: 91
diff changeset
620
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 pixmap = gdk_pixmap_new(widget->window, w, h, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 gc = gdk_gc_new(widget->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 gdk_gc_copy(gc, widget->style->black_gc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 gdk_gc_copy(gc, widget->style->white_gc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 gdk_draw_layout(pixmap, gc, 0, 0, layout);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 g_object_unref(gc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 gdk_pixbuf_get_from_drawable(buffer, pixmap,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 gdk_drawable_get_colormap(widget->window),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 0, 0, 0, 0, w, h);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 g_object_unref(pixmap);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 sx = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 sy = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 dw = gdk_pixbuf_get_width(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 dh = gdk_pixbuf_get_height(pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 if (x < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 w += x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 sx = -x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 x = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 if (y < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 h += y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 sy = -y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 y = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 if (x + w > dw) w = dw - x;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 if (y + h > dh) h = dh - y;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657
12
147f4c4b9025 ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
658 pixbuf_copy_font(buffer, sx, sy,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 pixbuf, x, y, w, h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 r, g, b, a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 g_object_unref(buffer);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664
33
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
665 /*
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
666 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
667 * pixbuf drawing (triangle)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
668 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
669 */
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
670
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
671 void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
672 gint *rx, gint *ry, gint *rw, gint *rh)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
673 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
674 gint tx, ty, tw, th;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
675
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
676 tx = MIN(x1, x2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
677 tx = MIN(tx, x3);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
678 ty = MIN(y1, y2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
679 ty = MIN(ty, y3);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
680 tw = MAX(abs(x1 - x2), abs(x2 - x3));
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
681 tw = MAX(tw, abs(x3 - x1));
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
682 th = MAX(abs(y1 - y2), abs(y2 - y3));
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
683 th = MAX(th, abs(y3 - y1));
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
684
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
685 *rx = tx;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
686 *ry = ty;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
687 *rw = tw;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
688 *rh = th;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
689 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
690
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
691 void pixbuf_draw_triangle(GdkPixbuf *pb,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
692 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
693 gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
694 guint8 r, guint8 g, guint8 b, guint8 a)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
695 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
696 gint p_alpha;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
697 gint pw, ph, prs;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
698 gint rx, ry, rw, rh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
699 gint tx, ty, tw, th;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
700 gint fx1, fy1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
701 gint fx2, fy2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
702 gint fw, fh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
703 guchar *p_pix;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
704 guchar *pp;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
705 gint p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
706 gdouble slope1, slope2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
707 gint slope1_x, slope1_y;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
708 gint y;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
709 gint t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
710 gint middle = FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
711
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
712 if (!pb) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
713
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
714 pw = gdk_pixbuf_get_width(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
715 ph = gdk_pixbuf_get_height(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
716
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
717 if (!util_clip_region(0, 0, pw, ph,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
718 clip_x, clip_y, clip_w, clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
719 &rx, &ry, &rw, &rh)) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
720
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
721 util_clip_triangle(x1, y1, x2, y2, x3, y3,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
722 &tx, &ty, &tw, &th);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
723
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
724 if (!util_clip_region(rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
725 tx, ty, tw, th,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
726 &fx1, &fy1, &fw, &fh)) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
727 fx2 = fx1 + fw;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
728 fy2 = fy1 + fh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
729
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
730 p_alpha = gdk_pixbuf_get_has_alpha(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
731 prs = gdk_pixbuf_get_rowstride(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
732 p_pix = gdk_pixbuf_get_pixels(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
733
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
734 p_step = (p_alpha) ? 4 : 3;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
735
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
736 if (y1 > y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
737 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
738 t = x1; x1 = x2; x2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
739 t = y1; y1 = y2; y2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
740 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
741 if (y2 > y3)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
742 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
743 t = x2; x2 = x3; x3 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
744 t = y2; y2 = y3; y3 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
745 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
746 if (y1 > y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
747 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
748 t = x1; x1 = x2; x2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
749 t = y1; y1 = y2; y2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
750 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
751
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
752 slope1 = (gdouble)(y2 - y1);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
753 if (slope1) slope1 = (gdouble)(x2 - x1) / slope1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
754 slope1_x = x1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
755 slope1_y = y1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
756 slope2 = (gdouble)(y3 - y1);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
757 if (slope2) slope2 = (gdouble)(x3 - x1) / slope2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
758
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
759 for (y = fy1; y < fy2; y++)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
760 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
761 gint xa, xb;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
762
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
763 if (!middle && y > y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
764 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
765 slope1 = (gdouble)(y3 - y2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
766 if (slope1) slope1 = (gdouble)(x3 - x2) / slope1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
767 slope1_x = x2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
768 slope1_y = y2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
769
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
770 middle = TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
771 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
772
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
773 xa = slope1_x + ((gdouble)slope1 * (y - slope1_y) + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
774 xb = x1 + ((gdouble)slope2 * (y - y1) + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
775
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
776 if (xa > xb)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
777 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
778 t = xa; xa = xb; xb = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
779 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
780
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
781 xa = CLAMP(xa, fx1, fx2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
782 xb = CLAMP(xb, fx1, fx2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
783
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
784 pp = p_pix + y * prs + xa * p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
785
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
786 while (xa < xb)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
787 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
788 *pp = (r * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
789 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
790 *pp = (g * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
791 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
792 *pp = (b * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
793 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
794 if (p_alpha) pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
795
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
796 xa++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
797 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
798 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
799 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
800
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
801 /*
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
802 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
803 * pixbuf drawing (line)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
804 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
805 */
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
806
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
807 static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdouble clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
808 gdouble x1, gdouble y1, gdouble x2, gdouble y2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
809 gdouble *rx1, gdouble *ry1, gdouble *rx2, gdouble *ry2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
810 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
811 gint flip = FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
812 gdouble d;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
813
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
814 if (x1 > x2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
815 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
816 gdouble t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
817
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
818 t = x1; x1 = x2; x2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
819 t = y1; y1 = y2; y2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
820 flip = TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
821 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
822
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
823 if (x2 < clip_x || x1 > clip_x + clip_w) return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
824
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
825 if (y1 < y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
826 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
827 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
828 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
829 else
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
830 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
831 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
832 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
833
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
834 #if 0
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
835 if (x1 >= clip_x && x2 <= clip_x + clip_w)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
836 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
837 if (y1 < y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
838 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
839 if (y1 >= clip_y && y2 <= clip_y + clip_h) return TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
840 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
841 else
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
842 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
843 if (y2 >= clip_y && y1 <= clip_y + clip_h) return TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
844 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
845 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
846 #endif
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
847
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
848 d = x2 - x1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
849 if (d > 0.0)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
850 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
851 gdouble slope;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
852
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
853 slope = (y2 - y1) / d;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
854 if (x1 < clip_x)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
855 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
856 y1 = y1 + slope * (clip_x - x1);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
857 x1 = clip_x;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
858 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
859 if (x2 > clip_x + clip_w)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
860 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
861 y2 = y2 + slope * (clip_x + clip_w - x2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
862 x2 = clip_x + clip_w;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
863 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
864 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
865
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
866 if (y1 < y2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
867 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
868 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
869 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
870 else
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
871 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
872 gdouble t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
873
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
874 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
875
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
876 t = x1; x1 = x2; x2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
877 t = y1; y1 = y2; y2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
878 flip = !flip;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
879 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
880
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
881 d = y2 - y1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
882 if (d > 0.0)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
883 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
884 gdouble slope;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
885
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
886 slope = (x2 - x1) / d;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
887 if (y1 < clip_y)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
888 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
889 x1 = x1 + slope * (clip_y - y1);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
890 y1 = clip_y;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
891 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
892 if (y2 > clip_y + clip_h)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
893 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
894 x2 = x2 + slope * (clip_y + clip_h - y2);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
895 y2 = clip_y + clip_h;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
896 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
897 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
898
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
899 if (flip)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
900 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
901 *rx1 = x2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
902 *ry1 = y2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
903 *rx2 = x1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
904 *ry2 = y1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
905 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
906 else
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
907 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
908 *rx1 = x1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
909 *ry1 = y1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
910 *rx2 = x2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
911 *ry2 = y2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
912 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
913
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
914 return TRUE;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
915 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
916
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
917 void pixbuf_draw_line(GdkPixbuf *pb,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
918 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
919 gint x1, gint y1, gint x2, gint y2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
920 guint8 r, guint8 g, guint8 b, guint8 a)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
921 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
922 gint p_alpha;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
923 gint pw, ph, prs;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
924 gint rx, ry, rw, rh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
925 gdouble rx1, ry1, rx2, ry2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
926 guchar *p_pix;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
927 guchar *pp;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
928 gint p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
929 gdouble slope;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
930 gdouble x, y;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
931 gint px, py;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
932 gint cx1, cy1, cx2, cy2;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
933
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
934 if (!pb) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
935
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
936 pw = gdk_pixbuf_get_width(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
937 ph = gdk_pixbuf_get_height(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
938
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
939 if (!util_clip_region(0, 0, pw, ph,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
940 clip_x, clip_y, clip_w, clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
941 &rx, &ry, &rw, &rh)) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
942 if (!util_clip_line((gdouble)rx, (gdouble)ry, (gdouble)rw, (gdouble)rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
943 (gdouble)x1, (gdouble)y1, (gdouble)x2, (gdouble)y2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
944 &rx1, &ry1, &rx2, &ry2)) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
945
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
946 cx1 = rx;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
947 cy1 = ry;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
948 cx2 = rx + rw;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
949 cy2 = ry + rh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
950
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
951 p_alpha = gdk_pixbuf_get_has_alpha(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
952 prs = gdk_pixbuf_get_rowstride(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
953 p_pix = gdk_pixbuf_get_pixels(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
954
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
955 p_step = (p_alpha) ? 4 : 3;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
956
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
957 if (fabs(rx2 - rx1) > fabs(ry2 - ry1))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
958 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
959 if (rx1 > rx2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
960 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
961 gdouble t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
962 t = rx1; rx1 = rx2; rx2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
963 t = ry1; ry1 = ry2; ry2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
964 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
965
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
966 slope = rx2 - rx1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
967 if (slope != 0.0) slope = (ry2 - ry1) / slope;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
968 for (x = rx1; x < rx2; x += 1.0)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
969 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
970 px = (gint)(x + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
971 py = (gint)(ry1 + (x - rx1) * slope + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
972
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
973 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
974 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
975 pp = p_pix + py * prs + px * p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
976 *pp = (r * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
977 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
978 *pp = (g * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
979 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
980 *pp = (b * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
981 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
982 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
983 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
984 else
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
985 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
986 if (ry1 > ry2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
987 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
988 gdouble t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
989 t = rx1; rx1 = rx2; rx2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
990 t = ry1; ry1 = ry2; ry2 = t;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
991 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
992
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
993 slope = ry2 - ry1;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
994 if (slope != 0.0) slope = (rx2 - rx1) / slope;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
995 for (y = ry1; y < ry2; y += 1.0)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
996 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
997 px = (gint)(rx1 + (y - ry1) * slope + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
998 py = (gint)(y + 0.5);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
999
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1000 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1001 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1002 pp = p_pix + py * prs + px * p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1003 *pp = (r * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1004 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1005 *pp = (g * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1006 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1007 *pp = (b * a + *pp * (256-a)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1008 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1009 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1010 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1011 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1012
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1013 /*
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1014 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1015 * pixbuf drawing (fades and shadows)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1016 *-----------------------------------------------------------------------------
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1017 */
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1018
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1019 static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gint p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1020 gint s, gint vertical, gint border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1021 gint x1, gint y1, gint x2, gint y2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1022 guint8 r, guint8 g, guint8 b, guint8 a)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1023 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1024 guchar *pp;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1025 gint p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1026 guint8 n = a;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1027 gint i, j;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1028
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1029 p_step = (p_alpha) ? 4 : 3;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1030 for (j = y1; j < y2; j++)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1031 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1032 pp = p_pix + j * prs + x1 * p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1033 if (!vertical) n = a - a * abs(j - s) / border;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1034 for (i = x1; i < x2; i++)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1035 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1036 if (vertical) n = a - a * abs(i - s) / border;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1037 *pp = (r * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1038 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1039 *pp = (g * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1040 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1041 *pp = (b * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1042 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1043 if (p_alpha) pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1044 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1045 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1046 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1047
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1048 static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gint p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1049 gint sx, gint sy, gint border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1050 gint x1, gint y1, gint x2, gint y2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1051 guint8 r, guint8 g, guint8 b, guint8 a)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1052 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1053 guchar *pp;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1054 gint p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1055 gint i, j;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1056
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1057 p_step = (p_alpha) ? 4 : 3;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1058 for (j = y1; j < y2; j++)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1059 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1060 pp = p_pix + j * prs + x1 * p_step;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1061 for (i = x1; i < x2; i++)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1062 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1063 guint8 n;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1064 gint r;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1065
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1066 r = MIN(border, (gint)sqrt((i-sx)*(i-sx) + (j-sy)*(j-sy)));
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1067 n = a - a * r / border;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1068 *pp = (r * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1069 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1070 *pp = (g * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1071 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1072 *pp = (b * n + *pp * (256-n)) >> 8;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1073 pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1074 if (p_alpha) pp++;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1075 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1076 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1077 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1078
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1079 void pixbuf_draw_shadow(GdkPixbuf *pb,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1080 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1081 gint x, gint y, gint w, gint h, gint border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1082 guint8 r, guint8 g, guint8 b, guint8 a)
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1083 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1084 gint p_alpha;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1085 gint pw, ph, prs;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1086 gint rx, ry, rw, rh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1087 gint fx, fy, fw, fh;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1088 guchar *p_pix;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1089
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1090 if (!pb) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1091
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1092 pw = gdk_pixbuf_get_width(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1093 ph = gdk_pixbuf_get_height(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1094
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1095 if (!util_clip_region(0, 0, pw, ph,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1096 clip_x, clip_y, clip_w, clip_h,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1097 &rx, &ry, &rw, &rh)) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1098
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1099 p_alpha = gdk_pixbuf_get_has_alpha(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1100 prs = gdk_pixbuf_get_rowstride(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1101 p_pix = gdk_pixbuf_get_pixels(pb);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1102
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1103 if (util_clip_region(x + border, y + border, w - border * 2, h - border * 2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1104 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1105 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1106 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1107 pixbuf_draw_rect_fill(pb, fx, fy, fw, fh, r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1108 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1109
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1110 if (border < 1) return;
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1111
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1112 if (util_clip_region(x, y + border, border, h - border * 2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1113 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1114 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1115 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1116 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1117 x + border, TRUE, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1118 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1119 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1120 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1121 if (util_clip_region(x + w - border, y + border, border, h - border * 2,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1122 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1123 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1124 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1125 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1126 x + w - border, TRUE, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1127 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1128 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1129 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1130 if (util_clip_region(x + border, y, w - border * 2, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1131 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1132 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1133 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1134 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1135 y + border, FALSE, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1136 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1137 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1138 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1139 if (util_clip_region(x + border, y + h - border, w - border * 2, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1140 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1141 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1142 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1143 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1144 y + h - border, FALSE, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1145 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1146 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1147 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1148 if (util_clip_region(x, y, border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1149 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1150 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1151 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1152 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1153 x + border, y + border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1154 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1155 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1156 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1157 if (util_clip_region(x + w - border, y, border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1158 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1159 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1160 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1161 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1162 x + w - border, y + border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1163 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1164 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1165 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1166 if (util_clip_region(x, y + h - border, border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1167 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1168 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1169 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1170 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1171 x + border, y + h - border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1172 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1173 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1174 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1175 if (util_clip_region(x + w - border, y + h - border, border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1176 rx, ry, rw, rh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1177 &fx, &fy, &fw, &fh))
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1178 {
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1179 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1180 x + w - border, y + h - border, border,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1181 fx, fy, fx + fw, fy + fh,
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1182 r, g, b, a);
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1183 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1184 }
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1185
a41ecbb26a96 Wed Apr 6 06:41:25 2005 John Ellis <johne@verizon.net>
gqview
parents: 12
diff changeset
1186
82
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1187 /*
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1188 *-----------------------------------------------------------------------------
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1189 * pixbuf color alterations
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1190 *-----------------------------------------------------------------------------
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1191 */
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1192
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1193 void pixbuf_desaturate_rect(GdkPixbuf *pb,
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1194 gint x, gint y, gint w, gint h)
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1195 {
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1196 gint p_alpha;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1197 gint pw, ph, prs;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1198 guchar *p_pix;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1199 guchar *pp;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1200 gint i, j;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1201
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1202 if (!pb) return;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1203
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1204 pw = gdk_pixbuf_get_width(pb);
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1205 ph = gdk_pixbuf_get_height(pb);
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1206
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1207 if (x < 0 || x + w > pw) return;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1208 if (y < 0 || y + h > ph) return;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1209
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1210 p_alpha = gdk_pixbuf_get_has_alpha(pb);
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1211 prs = gdk_pixbuf_get_rowstride(pb);
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1212 p_pix = gdk_pixbuf_get_pixels(pb);
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1213
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1214 for (i = 0; i < h; i++)
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1215 {
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1216 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1217 for (j = 0; j < w; j++)
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1218 {
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1219 guint8 grey;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1220
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1221 grey = (pp[0] + pp[1] + pp[2]) / 3;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1222 *pp = grey;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1223 pp++;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1224 *pp = grey;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1225 pp++;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1226 *pp = grey;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1227 pp++;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1228 if (p_alpha) pp++;
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1229 }
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1230 }
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1231 }
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1232
a4c1b7014e6e Thu Oct 19 15:20:51 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1233