7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
14 #include "pixbuf_util.h"
16 #include "icons/icons_inline.h"
22 *-----------------------------------------------------------------------------
24 *-----------------------------------------------------------------------------
27 gboolean pixbuf_to_file_as_png (GdkPixbuf *pixbuf, const char *filename)
32 if (!pixbuf || !filename) return FALSE;
34 ret = gdk_pixbuf_save(pixbuf, filename, "png", &error,
35 "tEXt::Software", "Geeqie "VERSION, NULL);
39 printf("Error saving png file: %s\n", error->message);
47 *-----------------------------------------------------------------------------
49 *-----------------------------------------------------------------------------
52 gboolean pixbuf_to_file_as_jpg(GdkPixbuf *pixbuf, const gchar *filename, gint quality)
58 if (!pixbuf || !filename) return FALSE;
60 if (quality == -1) quality = 75;
61 if (quality < 1 || quality > 100)
63 printf("Jpeg not saved, invalid quality %d\n", quality);
67 qbuf = g_strdup_printf("%d", quality);
68 ret = gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", qbuf, NULL);
73 printf("Error saving jpeg to %s\n%s\n", filename, error->message);
81 *-----------------------------------------------------------------------------
83 *-----------------------------------------------------------------------------
86 typedef struct _PixbufInline PixbufInline;
93 static PixbufInline inline_pixbuf_data[] = {
94 { PIXBUF_INLINE_FOLDER_CLOSED, folder_closed },
95 { PIXBUF_INLINE_FOLDER_LOCKED, folder_locked },
96 { PIXBUF_INLINE_FOLDER_OPEN, folder_open },
97 { PIXBUF_INLINE_FOLDER_UP, folder_up },
98 { PIXBUF_INLINE_SCROLLER, icon_scroller },
99 { PIXBUF_INLINE_BROKEN, icon_broken },
100 { PIXBUF_INLINE_ICON, gqview_icon },
101 { PIXBUF_INLINE_LOGO, gqview_logo },
102 { PIXBUF_INLINE_ICON_FLOAT, icon_float },
103 { PIXBUF_INLINE_ICON_THUMB, icon_thumb },
104 { PIXBUF_INLINE_ICON_BOOK, icon_book },
105 { PIXBUF_INLINE_ICON_CONFIG, icon_config },
106 { PIXBUF_INLINE_ICON_TOOLS, icon_tools },
107 { PIXBUF_INLINE_ICON_VIEW, icon_view },
111 GdkPixbuf *pixbuf_inline(const gchar *key)
115 if (!key) return NULL;
118 while (inline_pixbuf_data[i].key)
120 if (strcmp(inline_pixbuf_data[i].key, key) == 0)
122 return gdk_pixbuf_new_from_inline(-1, inline_pixbuf_data[i].data, FALSE, NULL);
127 printf("warning: inline pixbuf key \"%s\" not found.\n", key);
133 *-----------------------------------------------------------------------------
135 *-----------------------------------------------------------------------------
138 gint util_clip_region(gint x, gint y, gint w, gint h,
139 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
140 gint *rx, gint *ry, gint *rw, gint *rh)
142 if (clip_x + clip_w <= x ||
144 clip_y + clip_h <= y ||
150 *rx = MAX(x, clip_x);
151 *rw = MIN((x + w), (clip_x + clip_w)) - *rx;
153 *ry = MAX(y, clip_y);
154 *rh = MIN((y + h), (clip_y + clip_h)) - *ry;
160 *-----------------------------------------------------------------------------
162 *-----------------------------------------------------------------------------
165 static void pixbuf_copy_block_rotate(guchar *src, gint src_row_stride, gint x, gint y,
166 guchar *dest, gint dest_row_stride, gint w, gint h,
167 gint bytes_per_pixel, gint counter_clockwise)
173 for (i = 0; i < h; i++)
175 sp = src + ((i + y) * src_row_stride) + (x * bytes_per_pixel);
176 for (j = 0; j < w; j++)
178 if (counter_clockwise)
180 dp = dest + ((w - j - 1) * dest_row_stride) + (i * bytes_per_pixel);
184 dp = dest + (j * dest_row_stride) + ((h - i - 1) * bytes_per_pixel);
186 *(dp++) = *(sp++); /* r */
187 *(dp++) = *(sp++); /* g */
188 *(dp++) = *(sp++); /* b */
189 if (bytes_per_pixel == 4) *(dp) = *(sp++); /* a */
195 static void pixbuf_copy_block(guchar *src, gint src_row_stride, gint w, gint h,
196 guchar *dest, gint dest_row_stride, gint x, gint y, gint bytes_per_pixel)
202 for (i = 0; i < h; i++)
204 sp = src + (i * src_row_stride);
205 dp = dest + ((y + i) * dest_row_stride) + (x * bytes_per_pixel);
206 memcpy(dp, sp, w * bytes_per_pixel);
210 #define ROTATE_BUFFER_WIDTH 48
211 #define ROTATE_BUFFER_HEIGHT 48
214 * Returns a copy of pixbuf src rotated 90 degrees clockwise or 90 counterclockwise
217 GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gint counter_clockwise)
236 if (!src) return NULL;
238 sw = gdk_pixbuf_get_width(src);
239 sh = gdk_pixbuf_get_height(src);
240 has_alpha = gdk_pixbuf_get_has_alpha(src);
241 srs = gdk_pixbuf_get_rowstride(src);
242 s_pix = gdk_pixbuf_get_pixels(src);
246 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, dw, dh);
247 drs = gdk_pixbuf_get_rowstride(dest);
248 d_pix = gdk_pixbuf_get_pixels(dest);
250 a = (has_alpha ? 4 : 3);
252 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8,
253 ROTATE_BUFFER_WIDTH, ROTATE_BUFFER_HEIGHT);
254 b_pix = gdk_pixbuf_get_pixels(buffer);
255 brs = gdk_pixbuf_get_rowstride(buffer);
257 for (i = 0; i < sh; i+= ROTATE_BUFFER_WIDTH)
259 w = MIN(ROTATE_BUFFER_WIDTH, (sh - i));
260 for (j = 0; j < sw; j += ROTATE_BUFFER_HEIGHT)
264 h = MIN(ROTATE_BUFFER_HEIGHT, (sw - j));
265 pixbuf_copy_block_rotate(s_pix, srs, j, i,
267 a, counter_clockwise);
269 if (counter_clockwise)
279 pixbuf_copy_block(b_pix, brs, w, h,
280 d_pix, drs, x, y, a);
284 gdk_pixbuf_unref(buffer);
287 /* this is the simple version of rotation (roughly 2-4x slower) */
289 for (i = 0; i < sh; i++)
291 sp = s_pix + (i * srs);
292 for (j = 0; j < sw; j++)
294 if (counter_clockwise)
296 dp = d_pix + ((dh - j - 1) * drs) + (i * a);
300 dp = d_pix + (j * drs) + ((dw - i - 1) * a);
303 *(dp++) = *(sp++); /* r */
304 *(dp++) = *(sp++); /* g */
305 *(dp++) = *(sp++); /* b */
306 if (has_alpha) *(dp) = *(sp++); /* a */
315 * Returns a copy of pixbuf mirrored and or flipped.
316 * TO do a 180 degree rotations set both mirror and flipped TRUE
317 * if mirror and flip are FALSE, result is a simple copy.
319 GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gint mirror, gint flip)
332 if (!src) return NULL;
334 w = gdk_pixbuf_get_width(src);
335 h = gdk_pixbuf_get_height(src);
336 has_alpha = gdk_pixbuf_get_has_alpha(src);
337 srs = gdk_pixbuf_get_rowstride(src);
338 s_pix = gdk_pixbuf_get_pixels(src);
340 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, w, h);
341 drs = gdk_pixbuf_get_rowstride(dest);
342 d_pix = gdk_pixbuf_get_pixels(dest);
344 a = has_alpha ? 4 : 3;
346 for (i = 0; i < h; i++)
348 sp = s_pix + (i * srs);
351 dp = d_pix + ((h - i - 1) * drs);
355 dp = d_pix + (i * drs);
360 for (j = 0; j < w; j++)
362 *(dp++) = *(sp++); /* r */
363 *(dp++) = *(sp++); /* g */
364 *(dp++) = *(sp++); /* b */
365 if (has_alpha) *(dp) = *(sp++); /* a */
371 for (j = 0; j < w; j++)
373 *(dp++) = *(sp++); /* r */
374 *(dp++) = *(sp++); /* g */
375 *(dp++) = *(sp++); /* b */
376 if (has_alpha) *(dp++) = *(sp++); /* a */
386 *-----------------------------------------------------------------------------
387 * pixbuf drawing (rectangles)
388 *-----------------------------------------------------------------------------
392 * Fills region of pixbuf at x,y over w,h
393 * with colors red (r), green (g), blue (b)
394 * applying alpha (a), use a=255 for solid.
396 void pixbuf_draw_rect_fill(GdkPixbuf *pb,
397 gint x, gint y, gint w, gint h,
398 gint r, gint g, gint b, gint a)
408 pw = gdk_pixbuf_get_width(pb);
409 ph = gdk_pixbuf_get_height(pb);
411 if (x < 0 || x + w > pw) return;
412 if (y < 0 || y + h > ph) return;
414 p_alpha = gdk_pixbuf_get_has_alpha(pb);
415 prs = gdk_pixbuf_get_rowstride(pb);
416 p_pix = gdk_pixbuf_get_pixels(pb);
418 for (i = 0; i < h; i++)
420 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
421 for (j = 0; j < w; j++)
423 *pp = (r * a + *pp * (256-a)) >> 8;
425 *pp = (g * a + *pp * (256-a)) >> 8;
427 *pp = (b * a + *pp * (256-a)) >> 8;
434 void pixbuf_draw_rect(GdkPixbuf *pb,
435 gint x, gint y, gint w, gint h,
436 gint r, gint g, gint b, gint a,
437 gint left, gint right, gint top, gint bottom)
439 pixbuf_draw_rect_fill(pb, x + left, y, w - left - right, top,
441 pixbuf_draw_rect_fill(pb, x + w - right, y, right, h,
443 pixbuf_draw_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
445 pixbuf_draw_rect_fill(pb, x, y, left, h,
449 void pixbuf_set_rect_fill(GdkPixbuf *pb,
450 gint x, gint y, gint w, gint h,
451 gint r, gint g, gint b, gint a)
461 pw = gdk_pixbuf_get_width(pb);
462 ph = gdk_pixbuf_get_height(pb);
464 if (x < 0 || x + w > pw) return;
465 if (y < 0 || y + h > ph) return;
467 p_alpha = gdk_pixbuf_get_has_alpha(pb);
468 prs = gdk_pixbuf_get_rowstride(pb);
469 p_pix = gdk_pixbuf_get_pixels(pb);
471 for (i = 0; i < h; i++)
473 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
474 for (j = 0; j < w; j++)
479 if (p_alpha) { *pp = a; pp++; }
484 void pixbuf_set_rect(GdkPixbuf *pb,
485 gint x, gint y, gint w, gint h,
486 gint r, gint g, gint b, gint a,
487 gint left, gint right, gint top, gint bottom)
489 pixbuf_set_rect_fill(pb, x + left, y, w - left - right, top,
491 pixbuf_set_rect_fill(pb, x + w - right, y, right, h,
493 pixbuf_set_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
495 pixbuf_set_rect_fill(pb, x, y, left, h,
499 void pixbuf_pixel_set(GdkPixbuf *pb, gint x, gint y, gint r, gint g, gint b, gint a)
506 if (x < 0 || x >= gdk_pixbuf_get_width(pb) ||
507 y < 0 || y >= gdk_pixbuf_get_height(pb)) return;
509 buf = gdk_pixbuf_get_pixels(pb);
510 has_alpha = gdk_pixbuf_get_has_alpha(pb);
511 rowstride = gdk_pixbuf_get_rowstride(pb);
513 p = buf + (y * rowstride) + (x * (has_alpha ? 4 : 3));
517 if (has_alpha) *p = a;
522 *-----------------------------------------------------------------------------
523 * pixbuf text rendering
524 *-----------------------------------------------------------------------------
527 static void pixbuf_copy_font(GdkPixbuf *src, gint sx, gint sy,
528 GdkPixbuf *dest, gint dx, gint dy,
530 guint8 r, guint8 g, guint8 b, guint8 a)
545 if (!src || !dest) return;
547 sw = gdk_pixbuf_get_width(src);
548 sh = gdk_pixbuf_get_height(src);
550 if (sx < 0 || sx + w > sw) return;
551 if (sy < 0 || sy + h > sh) return;
553 dw = gdk_pixbuf_get_width(dest);
554 dh = gdk_pixbuf_get_height(dest);
556 if (dx < 0 || dx + w > dw) return;
557 if (dy < 0 || dy + h > dh) return;
559 s_alpha = gdk_pixbuf_get_has_alpha(src);
560 d_alpha = gdk_pixbuf_get_has_alpha(dest);
561 srs = gdk_pixbuf_get_rowstride(src);
562 drs = gdk_pixbuf_get_rowstride(dest);
563 s_pix = gdk_pixbuf_get_pixels(src);
564 d_pix = gdk_pixbuf_get_pixels(dest);
566 s_step = (s_alpha) ? 4 : 3;
567 d_step = (d_alpha) ? 4 : 3;
569 for (i = 0; i < h; i++)
571 sp = s_pix + (sy + i) * srs + sx * s_step;
572 dp = d_pix + (dy + i) * drs + dx * d_step;
573 for (j = 0; j < w; j++)
579 asub = a * sp[0] / 255;
580 *dp = (r * asub + *dp * (256-asub)) >> 8;
582 asub = a * sp[1] / 255;
583 *dp = (g * asub + *dp * (256-asub)) >> 8;
585 asub = a * sp[2] / 255;
586 *dp = (b * asub + *dp * (256-asub)) >> 8;
591 *dp = MAX(*dp, a * ((sp[0] + sp[1] + sp[2]) / 3) / 255);
605 void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widget,
607 guint8 r, guint8 g, guint8 b, guint8 a)
616 if (!widget || !widget->window) return;
618 pango_layout_get_pixel_size(layout, &w, &h);
619 if (w < 1 || h < 1) return;
621 pixmap = gdk_pixmap_new(widget->window, w, h, -1);
623 gc = gdk_gc_new(widget->window);
624 gdk_gc_copy(gc, widget->style->black_gc);
625 gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, w, h);
626 gdk_gc_copy(gc, widget->style->white_gc);
627 gdk_draw_layout(pixmap, gc, 0, 0, layout);
630 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
631 gdk_pixbuf_get_from_drawable(buffer, pixmap,
632 gdk_drawable_get_colormap(widget->window),
634 g_object_unref(pixmap);
638 dw = gdk_pixbuf_get_width(pixbuf);
639 dh = gdk_pixbuf_get_height(pixbuf);
655 if (x + w > dw) w = dw - x;
656 if (y + h > dh) h = dh - y;
658 pixbuf_copy_font(buffer, sx, sy,
662 g_object_unref(buffer);
666 *-----------------------------------------------------------------------------
667 * pixbuf drawing (triangle)
668 *-----------------------------------------------------------------------------
671 void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
672 gint *rx, gint *ry, gint *rw, gint *rh)
680 tw = MAX(abs(x1 - x2), abs(x2 - x3));
681 tw = MAX(tw, abs(x3 - x1));
682 th = MAX(abs(y1 - y2), abs(y2 - y3));
683 th = MAX(th, abs(y3 - y1));
691 void pixbuf_draw_triangle(GdkPixbuf *pb,
692 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
693 gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
694 guint8 r, guint8 g, guint8 b, guint8 a)
706 gdouble slope1, slope2;
707 gint slope1_x, slope1_y;
714 pw = gdk_pixbuf_get_width(pb);
715 ph = gdk_pixbuf_get_height(pb);
717 if (!util_clip_region(0, 0, pw, ph,
718 clip_x, clip_y, clip_w, clip_h,
719 &rx, &ry, &rw, &rh)) return;
721 util_clip_triangle(x1, y1, x2, y2, x3, y3,
724 if (!util_clip_region(rx, ry, rw, rh,
726 &fx1, &fy1, &fw, &fh)) return;
730 p_alpha = gdk_pixbuf_get_has_alpha(pb);
731 prs = gdk_pixbuf_get_rowstride(pb);
732 p_pix = gdk_pixbuf_get_pixels(pb);
734 p_step = (p_alpha) ? 4 : 3;
738 t = x1; x1 = x2; x2 = t;
739 t = y1; y1 = y2; y2 = t;
743 t = x2; x2 = x3; x3 = t;
744 t = y2; y2 = y3; y3 = t;
748 t = x1; x1 = x2; x2 = t;
749 t = y1; y1 = y2; y2 = t;
752 slope1 = (gdouble)(y2 - y1);
753 if (slope1) slope1 = (gdouble)(x2 - x1) / slope1;
756 slope2 = (gdouble)(y3 - y1);
757 if (slope2) slope2 = (gdouble)(x3 - x1) / slope2;
759 for (y = fy1; y < fy2; y++)
763 if (!middle && y > y2)
765 slope1 = (gdouble)(y3 - y2);
766 if (slope1) slope1 = (gdouble)(x3 - x2) / slope1;
773 xa = slope1_x + ((gdouble)slope1 * (y - slope1_y) + 0.5);
774 xb = x1 + ((gdouble)slope2 * (y - y1) + 0.5);
778 t = xa; xa = xb; xb = t;
781 xa = CLAMP(xa, fx1, fx2);
782 xb = CLAMP(xb, fx1, fx2);
784 pp = p_pix + y * prs + xa * p_step;
788 *pp = (r * a + *pp * (256-a)) >> 8;
790 *pp = (g * a + *pp * (256-a)) >> 8;
792 *pp = (b * a + *pp * (256-a)) >> 8;
802 *-----------------------------------------------------------------------------
803 * pixbuf drawing (line)
804 *-----------------------------------------------------------------------------
807 static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdouble clip_h,
808 gdouble x1, gdouble y1, gdouble x2, gdouble y2,
809 gdouble *rx1, gdouble *ry1, gdouble *rx2, gdouble *ry2)
818 t = x1; x1 = x2; x2 = t;
819 t = y1; y1 = y2; y2 = t;
823 if (x2 < clip_x || x1 > clip_x + clip_w) return FALSE;
827 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
831 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
835 if (x1 >= clip_x && x2 <= clip_x + clip_w)
839 if (y1 >= clip_y && y2 <= clip_y + clip_h) return TRUE;
843 if (y2 >= clip_y && y1 <= clip_y + clip_h) return TRUE;
853 slope = (y2 - y1) / d;
856 y1 = y1 + slope * (clip_x - x1);
859 if (x2 > clip_x + clip_w)
861 y2 = y2 + slope * (clip_x + clip_w - x2);
862 x2 = clip_x + clip_w;
868 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
874 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
876 t = x1; x1 = x2; x2 = t;
877 t = y1; y1 = y2; y2 = t;
886 slope = (x2 - x1) / d;
889 x1 = x1 + slope * (clip_y - y1);
892 if (y2 > clip_y + clip_h)
894 x2 = x2 + slope * (clip_y + clip_h - y2);
895 y2 = clip_y + clip_h;
917 void pixbuf_draw_line(GdkPixbuf *pb,
918 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
919 gint x1, gint y1, gint x2, gint y2,
920 guint8 r, guint8 g, guint8 b, guint8 a)
925 gdouble rx1, ry1, rx2, ry2;
932 gint cx1, cy1, cx2, cy2;
936 pw = gdk_pixbuf_get_width(pb);
937 ph = gdk_pixbuf_get_height(pb);
939 if (!util_clip_region(0, 0, pw, ph,
940 clip_x, clip_y, clip_w, clip_h,
941 &rx, &ry, &rw, &rh)) return;
942 if (!util_clip_line((gdouble)rx, (gdouble)ry, (gdouble)rw, (gdouble)rh,
943 (gdouble)x1, (gdouble)y1, (gdouble)x2, (gdouble)y2,
944 &rx1, &ry1, &rx2, &ry2)) return;
951 p_alpha = gdk_pixbuf_get_has_alpha(pb);
952 prs = gdk_pixbuf_get_rowstride(pb);
953 p_pix = gdk_pixbuf_get_pixels(pb);
955 p_step = (p_alpha) ? 4 : 3;
957 if (fabs(rx2 - rx1) > fabs(ry2 - ry1))
962 t = rx1; rx1 = rx2; rx2 = t;
963 t = ry1; ry1 = ry2; ry2 = t;
967 if (slope != 0.0) slope = (ry2 - ry1) / slope;
968 for (x = rx1; x < rx2; x += 1.0)
970 px = (gint)(x + 0.5);
971 py = (gint)(ry1 + (x - rx1) * slope + 0.5);
973 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
975 pp = p_pix + py * prs + px * p_step;
976 *pp = (r * a + *pp * (256-a)) >> 8;
978 *pp = (g * a + *pp * (256-a)) >> 8;
980 *pp = (b * a + *pp * (256-a)) >> 8;
989 t = rx1; rx1 = rx2; rx2 = t;
990 t = ry1; ry1 = ry2; ry2 = t;
994 if (slope != 0.0) slope = (rx2 - rx1) / slope;
995 for (y = ry1; y < ry2; y += 1.0)
997 px = (gint)(rx1 + (y - ry1) * slope + 0.5);
998 py = (gint)(y + 0.5);
1000 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
1002 pp = p_pix + py * prs + px * p_step;
1003 *pp = (r * a + *pp * (256-a)) >> 8;
1005 *pp = (g * a + *pp * (256-a)) >> 8;
1007 *pp = (b * a + *pp * (256-a)) >> 8;
1014 *-----------------------------------------------------------------------------
1015 * pixbuf drawing (fades and shadows)
1016 *-----------------------------------------------------------------------------
1019 static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gint p_alpha,
1020 gint s, gint vertical, gint border,
1021 gint x1, gint y1, gint x2, gint y2,
1022 guint8 r, guint8 g, guint8 b, guint8 a)
1029 p_step = (p_alpha) ? 4 : 3;
1030 for (j = y1; j < y2; j++)
1032 pp = p_pix + j * prs + x1 * p_step;
1033 if (!vertical) n = a - a * abs(j - s) / border;
1034 for (i = x1; i < x2; i++)
1036 if (vertical) n = a - a * abs(i - s) / border;
1037 *pp = (r * n + *pp * (256-n)) >> 8;
1039 *pp = (g * n + *pp * (256-n)) >> 8;
1041 *pp = (b * n + *pp * (256-n)) >> 8;
1048 static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gint p_alpha,
1049 gint sx, gint sy, gint border,
1050 gint x1, gint y1, gint x2, gint y2,
1051 guint8 r, guint8 g, guint8 b, guint8 a)
1057 p_step = (p_alpha) ? 4 : 3;
1058 for (j = y1; j < y2; j++)
1060 pp = p_pix + j * prs + x1 * p_step;
1061 for (i = x1; i < x2; i++)
1066 r = MIN(border, (gint)sqrt((i-sx)*(i-sx) + (j-sy)*(j-sy)));
1067 n = a - a * r / border;
1068 *pp = (r * n + *pp * (256-n)) >> 8;
1070 *pp = (g * n + *pp * (256-n)) >> 8;
1072 *pp = (b * n + *pp * (256-n)) >> 8;
1079 void pixbuf_draw_shadow(GdkPixbuf *pb,
1080 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
1081 gint x, gint y, gint w, gint h, gint border,
1082 guint8 r, guint8 g, guint8 b, guint8 a)
1086 gint rx, ry, rw, rh;
1087 gint fx, fy, fw, fh;
1092 pw = gdk_pixbuf_get_width(pb);
1093 ph = gdk_pixbuf_get_height(pb);
1095 if (!util_clip_region(0, 0, pw, ph,
1096 clip_x, clip_y, clip_w, clip_h,
1097 &rx, &ry, &rw, &rh)) return;
1099 p_alpha = gdk_pixbuf_get_has_alpha(pb);
1100 prs = gdk_pixbuf_get_rowstride(pb);
1101 p_pix = gdk_pixbuf_get_pixels(pb);
1103 if (util_clip_region(x + border, y + border, w - border * 2, h - border * 2,
1105 &fx, &fy, &fw, &fh))
1107 pixbuf_draw_rect_fill(pb, fx, fy, fw, fh, r, g, b, a);
1110 if (border < 1) return;
1112 if (util_clip_region(x, y + border, border, h - border * 2,
1114 &fx, &fy, &fw, &fh))
1116 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1117 x + border, TRUE, border,
1118 fx, fy, fx + fw, fy + fh,
1121 if (util_clip_region(x + w - border, y + border, border, h - border * 2,
1123 &fx, &fy, &fw, &fh))
1125 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1126 x + w - border, TRUE, border,
1127 fx, fy, fx + fw, fy + fh,
1130 if (util_clip_region(x + border, y, w - border * 2, border,
1132 &fx, &fy, &fw, &fh))
1134 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1135 y + border, FALSE, border,
1136 fx, fy, fx + fw, fy + fh,
1139 if (util_clip_region(x + border, y + h - border, w - border * 2, border,
1141 &fx, &fy, &fw, &fh))
1143 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1144 y + h - border, FALSE, border,
1145 fx, fy, fx + fw, fy + fh,
1148 if (util_clip_region(x, y, border, border,
1150 &fx, &fy, &fw, &fh))
1152 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1153 x + border, y + border, border,
1154 fx, fy, fx + fw, fy + fh,
1157 if (util_clip_region(x + w - border, y, border, border,
1159 &fx, &fy, &fw, &fh))
1161 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1162 x + w - border, y + border, border,
1163 fx, fy, fx + fw, fy + fh,
1166 if (util_clip_region(x, y + h - border, border, border,
1168 &fx, &fy, &fw, &fh))
1170 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1171 x + border, y + h - border, border,
1172 fx, fy, fx + fw, fy + fh,
1175 if (util_clip_region(x + w - border, y + h - border, border, border,
1177 &fx, &fy, &fw, &fh))
1179 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1180 x + w - border, y + h - border, border,
1181 fx, fy, fx + fw, fy + fh,
1188 *-----------------------------------------------------------------------------
1189 * pixbuf color alterations
1190 *-----------------------------------------------------------------------------
1193 void pixbuf_desaturate_rect(GdkPixbuf *pb,
1194 gint x, gint y, gint w, gint h)
1204 pw = gdk_pixbuf_get_width(pb);
1205 ph = gdk_pixbuf_get_height(pb);
1207 if (x < 0 || x + w > pw) return;
1208 if (y < 0 || y + h > ph) return;
1210 p_alpha = gdk_pixbuf_get_has_alpha(pb);
1211 prs = gdk_pixbuf_get_rowstride(pb);
1212 p_pix = gdk_pixbuf_get_pixels(pb);
1214 for (i = 0; i < h; i++)
1216 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
1217 for (j = 0; j < w; j++)
1221 grey = (pp[0] + pp[1] + pp[2]) / 3;