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