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", "GQview "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_LOGO, gqview_logo },
104 GdkPixbuf *pixbuf_inline(const gchar *key)
108 if (!key) return NULL;
111 while (inline_pixbuf_data[i].key)
113 if (strcmp(inline_pixbuf_data[i].key, key) == 0)
115 return gdk_pixbuf_new_from_inline(-1, inline_pixbuf_data[i].data, FALSE, NULL);
120 printf("warning: inline pixbuf key \"%s\" not found.\n", key);
126 *-----------------------------------------------------------------------------
128 *-----------------------------------------------------------------------------
131 gint util_clip_region(gint x, gint y, gint w, gint h,
132 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
133 gint *rx, gint *ry, gint *rw, gint *rh)
135 if (clip_x + clip_w <= x ||
137 clip_y + clip_h <= y ||
143 *rx = MAX(x, clip_x);
144 *rw = MIN((x + w), (clip_x + clip_w)) - *rx;
146 *ry = MAX(y, clip_y);
147 *rh = MIN((y + h), (clip_y + clip_h)) - *ry;
153 *-----------------------------------------------------------------------------
155 *-----------------------------------------------------------------------------
158 static void pixbuf_copy_block_rotate(guchar *src, gint src_row_stride, gint x, gint y,
159 guchar *dest, gint dest_row_stride, gint w, gint h,
160 gint bytes_per_pixel, gint counter_clockwise)
166 for (i = 0; i < h; i++)
168 sp = src + ((i + y) * src_row_stride) + (x * bytes_per_pixel);
169 for (j = 0; j < w; j++)
171 if (counter_clockwise)
173 dp = dest + ((w - j - 1) * dest_row_stride) + (i * bytes_per_pixel);
177 dp = dest + (j * dest_row_stride) + ((h - i - 1) * bytes_per_pixel);
179 *(dp++) = *(sp++); /* r */
180 *(dp++) = *(sp++); /* g */
181 *(dp++) = *(sp++); /* b */
182 if (bytes_per_pixel == 4) *(dp) = *(sp++); /* a */
188 static void pixbuf_copy_block(guchar *src, gint src_row_stride, gint w, gint h,
189 guchar *dest, gint dest_row_stride, gint x, gint y, gint bytes_per_pixel)
195 for (i = 0; i < h; i++)
197 sp = src + (i * src_row_stride);
198 dp = dest + ((y + i) * dest_row_stride) + (x * bytes_per_pixel);
199 memcpy(dp, sp, w * bytes_per_pixel);
203 #define ROTATE_BUFFER_WIDTH 48
204 #define ROTATE_BUFFER_HEIGHT 48
207 * Returns a copy of pixbuf src rotated 90 degrees clockwise or 90 counterclockwise
210 GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gint counter_clockwise)
229 if (!src) return NULL;
231 sw = gdk_pixbuf_get_width(src);
232 sh = gdk_pixbuf_get_height(src);
233 has_alpha = gdk_pixbuf_get_has_alpha(src);
234 srs = gdk_pixbuf_get_rowstride(src);
235 s_pix = gdk_pixbuf_get_pixels(src);
239 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, dw, dh);
240 drs = gdk_pixbuf_get_rowstride(dest);
241 d_pix = gdk_pixbuf_get_pixels(dest);
243 a = (has_alpha ? 4 : 3);
245 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8,
246 ROTATE_BUFFER_WIDTH, ROTATE_BUFFER_HEIGHT);
247 b_pix = gdk_pixbuf_get_pixels(buffer);
248 brs = gdk_pixbuf_get_rowstride(buffer);
250 for (i = 0; i < sh; i+= ROTATE_BUFFER_WIDTH)
252 w = MIN(ROTATE_BUFFER_WIDTH, (sh - i));
253 for (j = 0; j < sw; j += ROTATE_BUFFER_HEIGHT)
257 h = MIN(ROTATE_BUFFER_HEIGHT, (sw - j));
258 pixbuf_copy_block_rotate(s_pix, srs, j, i,
260 a, counter_clockwise);
262 if (counter_clockwise)
272 pixbuf_copy_block(b_pix, brs, w, h,
273 d_pix, drs, x, y, a);
277 gdk_pixbuf_unref(buffer);
280 /* this is the simple version of rotation (roughly 2-4x slower) */
282 for (i = 0; i < sh; i++)
284 sp = s_pix + (i * srs);
285 for (j = 0; j < sw; j++)
287 if (counter_clockwise)
289 dp = d_pix + ((dh - j - 1) * drs) + (i * a);
293 dp = d_pix + (j * drs) + ((dw - i - 1) * a);
296 *(dp++) = *(sp++); /* r */
297 *(dp++) = *(sp++); /* g */
298 *(dp++) = *(sp++); /* b */
299 if (has_alpha) *(dp) = *(sp++); /* a */
308 * Returns a copy of pixbuf mirrored and or flipped.
309 * TO do a 180 degree rotations set both mirror and flipped TRUE
310 * if mirror and flip are FALSE, result is a simple copy.
312 GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gint mirror, gint flip)
325 if (!src) return NULL;
327 w = gdk_pixbuf_get_width(src);
328 h = gdk_pixbuf_get_height(src);
329 has_alpha = gdk_pixbuf_get_has_alpha(src);
330 srs = gdk_pixbuf_get_rowstride(src);
331 s_pix = gdk_pixbuf_get_pixels(src);
333 dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, w, h);
334 drs = gdk_pixbuf_get_rowstride(dest);
335 d_pix = gdk_pixbuf_get_pixels(dest);
337 a = has_alpha ? 4 : 3;
339 for (i = 0; i < h; i++)
341 sp = s_pix + (i * srs);
344 dp = d_pix + ((h - i - 1) * drs);
348 dp = d_pix + (i * drs);
353 for (j = 0; j < w; j++)
355 *(dp++) = *(sp++); /* r */
356 *(dp++) = *(sp++); /* g */
357 *(dp++) = *(sp++); /* b */
358 if (has_alpha) *(dp) = *(sp++); /* a */
364 for (j = 0; j < w; j++)
366 *(dp++) = *(sp++); /* r */
367 *(dp++) = *(sp++); /* g */
368 *(dp++) = *(sp++); /* b */
369 if (has_alpha) *(dp++) = *(sp++); /* a */
379 *-----------------------------------------------------------------------------
380 * pixbuf drawing (rectangles)
381 *-----------------------------------------------------------------------------
385 * Fills region of pixbuf at x,y over w,h
386 * with colors red (r), green (g), blue (b)
387 * applying alpha (a), use a=255 for solid.
389 void pixbuf_draw_rect_fill(GdkPixbuf *pb,
390 gint x, gint y, gint w, gint h,
391 gint r, gint g, gint b, gint a)
401 pw = gdk_pixbuf_get_width(pb);
402 ph = gdk_pixbuf_get_height(pb);
404 if (x < 0 || x + w > pw) return;
405 if (y < 0 || y + h > ph) return;
407 p_alpha = gdk_pixbuf_get_has_alpha(pb);
408 prs = gdk_pixbuf_get_rowstride(pb);
409 p_pix = gdk_pixbuf_get_pixels(pb);
411 for (i = 0; i < h; i++)
413 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
414 for (j = 0; j < w; j++)
416 *pp = (r * a + *pp * (256-a)) >> 8;
418 *pp = (g * a + *pp * (256-a)) >> 8;
420 *pp = (b * a + *pp * (256-a)) >> 8;
427 void pixbuf_draw_rect(GdkPixbuf *pb,
428 gint x, gint y, gint w, gint h,
429 gint r, gint g, gint b, gint a,
430 gint left, gint right, gint top, gint bottom)
432 pixbuf_draw_rect_fill(pb, x + left, y, w - left - right, top,
434 pixbuf_draw_rect_fill(pb, x + w - right, y, right, h,
436 pixbuf_draw_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
438 pixbuf_draw_rect_fill(pb, x, y, left, h,
442 void pixbuf_set_rect_fill(GdkPixbuf *pb,
443 gint x, gint y, gint w, gint h,
444 gint r, gint g, gint b, gint a)
454 pw = gdk_pixbuf_get_width(pb);
455 ph = gdk_pixbuf_get_height(pb);
457 if (x < 0 || x + w > pw) return;
458 if (y < 0 || y + h > ph) return;
460 p_alpha = gdk_pixbuf_get_has_alpha(pb);
461 prs = gdk_pixbuf_get_rowstride(pb);
462 p_pix = gdk_pixbuf_get_pixels(pb);
464 for (i = 0; i < h; i++)
466 pp = p_pix + (y + i) * prs + (x * (p_alpha ? 4 : 3));
467 for (j = 0; j < w; j++)
472 if (p_alpha) { *pp = a; pp++; }
477 void pixbuf_set_rect(GdkPixbuf *pb,
478 gint x, gint y, gint w, gint h,
479 gint r, gint g, gint b, gint a,
480 gint left, gint right, gint top, gint bottom)
482 pixbuf_set_rect_fill(pb, x + left, y, w - left - right, top,
484 pixbuf_set_rect_fill(pb, x + w - right, y, right, h,
486 pixbuf_set_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
488 pixbuf_set_rect_fill(pb, x, y, left, h,
492 void pixbuf_pixel_set(GdkPixbuf *pb, gint x, gint y, gint r, gint g, gint b, gint a)
499 if (x < 0 || x >= gdk_pixbuf_get_width(pb) ||
500 y < 0 || y >= gdk_pixbuf_get_height(pb)) return;
502 buf = gdk_pixbuf_get_pixels(pb);
503 has_alpha = gdk_pixbuf_get_has_alpha(pb);
504 rowstride = gdk_pixbuf_get_rowstride(pb);
506 p = buf + (y * rowstride) + (x * (has_alpha ? 4 : 3));
510 if (has_alpha) *p = a;
515 *-----------------------------------------------------------------------------
516 * pixbuf text rendering
517 *-----------------------------------------------------------------------------
520 static void pixbuf_copy_font(GdkPixbuf *src, gint sx, gint sy,
521 GdkPixbuf *dest, gint dx, gint dy,
523 guint8 r, guint8 g, guint8 b, guint8 a)
538 if (!src || !dest) return;
540 sw = gdk_pixbuf_get_width(src);
541 sh = gdk_pixbuf_get_height(src);
543 if (sx < 0 || sx + w > sw) return;
544 if (sy < 0 || sy + h > sh) return;
546 dw = gdk_pixbuf_get_width(dest);
547 dh = gdk_pixbuf_get_height(dest);
549 if (dx < 0 || dx + w > dw) return;
550 if (dy < 0 || dy + h > dh) return;
552 s_alpha = gdk_pixbuf_get_has_alpha(src);
553 d_alpha = gdk_pixbuf_get_has_alpha(dest);
554 srs = gdk_pixbuf_get_rowstride(src);
555 drs = gdk_pixbuf_get_rowstride(dest);
556 s_pix = gdk_pixbuf_get_pixels(src);
557 d_pix = gdk_pixbuf_get_pixels(dest);
559 s_step = (s_alpha) ? 4 : 3;
560 d_step = (d_alpha) ? 4 : 3;
562 for (i = 0; i < h; i++)
564 sp = s_pix + (sy + i) * srs + sx * s_step;
565 dp = d_pix + (dy + i) * drs + dx * d_step;
566 for (j = 0; j < w; j++)
572 asub = a * sp[0] / 255;
573 *dp = (r * asub + *dp * (256-asub)) >> 8;
575 asub = a * sp[1] / 255;
576 *dp = (g * asub + *dp * (256-asub)) >> 8;
578 asub = a * sp[2] / 255;
579 *dp = (b * asub + *dp * (256-asub)) >> 8;
584 *dp = MAX(*dp, a * ((sp[0] + sp[1] + sp[2]) / 3) / 255);
598 void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *widget,
600 guint8 r, guint8 g, guint8 b, guint8 a)
609 if (!widget || !widget->window) return;
611 pango_layout_get_pixel_size(layout, &w, &h);
612 pixmap = gdk_pixmap_new(widget->window, w, h, -1);
614 gc = gdk_gc_new(widget->window);
615 gdk_gc_copy(gc, widget->style->black_gc);
616 gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, w, h);
617 gdk_gc_copy(gc, widget->style->white_gc);
618 gdk_draw_layout(pixmap, gc, 0, 0, layout);
621 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
622 gdk_pixbuf_get_from_drawable(buffer, pixmap,
623 gdk_drawable_get_colormap(widget->window),
625 g_object_unref(pixmap);
629 dw = gdk_pixbuf_get_width(pixbuf);
630 dh = gdk_pixbuf_get_height(pixbuf);
646 if (x + w > dw) w = dw - x;
647 if (y + h > dh) h = dh - y;
649 pixbuf_copy_font(buffer, sx, sy,
653 g_object_unref(buffer);
657 *-----------------------------------------------------------------------------
658 * pixbuf drawing (triangle)
659 *-----------------------------------------------------------------------------
662 void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
663 gint *rx, gint *ry, gint *rw, gint *rh)
671 tw = MAX(abs(x1 - x2), abs(x2 - x3));
672 tw = MAX(tw, abs(x3 - x1));
673 th = MAX(abs(y1 - y2), abs(y2 - y3));
674 th = MAX(th, abs(y3 - y1));
682 void pixbuf_draw_triangle(GdkPixbuf *pb,
683 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
684 gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
685 guint8 r, guint8 g, guint8 b, guint8 a)
697 gdouble slope1, slope2;
698 gint slope1_x, slope1_y;
705 pw = gdk_pixbuf_get_width(pb);
706 ph = gdk_pixbuf_get_height(pb);
708 if (!util_clip_region(0, 0, pw, ph,
709 clip_x, clip_y, clip_w, clip_h,
710 &rx, &ry, &rw, &rh)) return;
712 util_clip_triangle(x1, y1, x2, y2, x3, y3,
715 if (!util_clip_region(rx, ry, rw, rh,
717 &fx1, &fy1, &fw, &fh)) return;
721 p_alpha = gdk_pixbuf_get_has_alpha(pb);
722 prs = gdk_pixbuf_get_rowstride(pb);
723 p_pix = gdk_pixbuf_get_pixels(pb);
725 p_step = (p_alpha) ? 4 : 3;
729 t = x1; x1 = x2; x2 = t;
730 t = y1; y1 = y2; y2 = t;
734 t = x2; x2 = x3; x3 = t;
735 t = y2; y2 = y3; y3 = t;
739 t = x1; x1 = x2; x2 = t;
740 t = y1; y1 = y2; y2 = t;
743 slope1 = (gdouble)(y2 - y1);
744 if (slope1) slope1 = (gdouble)(x2 - x1) / slope1;
747 slope2 = (gdouble)(y3 - y1);
748 if (slope2) slope2 = (gdouble)(x3 - x1) / slope2;
750 for (y = fy1; y < fy2; y++)
754 if (!middle && y > y2)
756 slope1 = (gdouble)(y3 - y2);
757 if (slope1) slope1 = (gdouble)(x3 - x2) / slope1;
764 xa = slope1_x + ((gdouble)slope1 * (y - slope1_y) + 0.5);
765 xb = x1 + ((gdouble)slope2 * (y - y1) + 0.5);
769 t = xa; xa = xb; xb = t;
772 xa = CLAMP(xa, fx1, fx2);
773 xb = CLAMP(xb, fx1, fx2);
775 pp = p_pix + y * prs + xa * p_step;
779 *pp = (r * a + *pp * (256-a)) >> 8;
781 *pp = (g * a + *pp * (256-a)) >> 8;
783 *pp = (b * a + *pp * (256-a)) >> 8;
793 *-----------------------------------------------------------------------------
794 * pixbuf drawing (line)
795 *-----------------------------------------------------------------------------
798 static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdouble clip_h,
799 gdouble x1, gdouble y1, gdouble x2, gdouble y2,
800 gdouble *rx1, gdouble *ry1, gdouble *rx2, gdouble *ry2)
809 t = x1; x1 = x2; x2 = t;
810 t = y1; y1 = y2; y2 = t;
814 if (x2 < clip_x || x1 > clip_x + clip_w) return FALSE;
818 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
822 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
826 if (x1 >= clip_x && x2 <= clip_x + clip_w)
830 if (y1 >= clip_y && y2 <= clip_y + clip_h) return TRUE;
834 if (y2 >= clip_y && y1 <= clip_y + clip_h) return TRUE;
844 slope = (y2 - y1) / d;
847 y1 = y1 + slope * (clip_x - x1);
850 if (x2 > clip_x + clip_w)
852 y2 = y2 + slope * (clip_x + clip_w - x2);
853 x2 = clip_x + clip_w;
859 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE;
865 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE;
867 t = x1; x1 = x2; x2 = t;
868 t = y1; y1 = y2; y2 = t;
877 slope = (x2 - x1) / d;
880 x1 = x1 + slope * (clip_y - y1);
883 if (y2 > clip_y + clip_h)
885 x2 = x2 + slope * (clip_y + clip_h - y2);
886 y2 = clip_y + clip_h;
908 void pixbuf_draw_line(GdkPixbuf *pb,
909 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
910 gint x1, gint y1, gint x2, gint y2,
911 guint8 r, guint8 g, guint8 b, guint8 a)
916 gdouble rx1, ry1, rx2, ry2;
923 gint cx1, cy1, cx2, cy2;
927 pw = gdk_pixbuf_get_width(pb);
928 ph = gdk_pixbuf_get_height(pb);
930 if (!util_clip_region(0, 0, pw, ph,
931 clip_x, clip_y, clip_w, clip_h,
932 &rx, &ry, &rw, &rh)) return;
933 if (!util_clip_line((gdouble)rx, (gdouble)ry, (gdouble)rw, (gdouble)rh,
934 (gdouble)x1, (gdouble)y1, (gdouble)x2, (gdouble)y2,
935 &rx1, &ry1, &rx2, &ry2)) return;
942 p_alpha = gdk_pixbuf_get_has_alpha(pb);
943 prs = gdk_pixbuf_get_rowstride(pb);
944 p_pix = gdk_pixbuf_get_pixels(pb);
946 p_step = (p_alpha) ? 4 : 3;
948 if (fabs(rx2 - rx1) > fabs(ry2 - ry1))
953 t = rx1; rx1 = rx2; rx2 = t;
954 t = ry1; ry1 = ry2; ry2 = t;
958 if (slope != 0.0) slope = (ry2 - ry1) / slope;
959 for (x = rx1; x < rx2; x += 1.0)
961 px = (gint)(x + 0.5);
962 py = (gint)(ry1 + (x - rx1) * slope + 0.5);
964 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
966 pp = p_pix + py * prs + px * p_step;
967 *pp = (r * a + *pp * (256-a)) >> 8;
969 *pp = (g * a + *pp * (256-a)) >> 8;
971 *pp = (b * a + *pp * (256-a)) >> 8;
980 t = rx1; rx1 = rx2; rx2 = t;
981 t = ry1; ry1 = ry2; ry2 = t;
985 if (slope != 0.0) slope = (rx2 - rx1) / slope;
986 for (y = ry1; y < ry2; y += 1.0)
988 px = (gint)(rx1 + (y - ry1) * slope + 0.5);
989 py = (gint)(y + 0.5);
991 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2)
993 pp = p_pix + py * prs + px * p_step;
994 *pp = (r * a + *pp * (256-a)) >> 8;
996 *pp = (g * a + *pp * (256-a)) >> 8;
998 *pp = (b * a + *pp * (256-a)) >> 8;
1005 *-----------------------------------------------------------------------------
1006 * pixbuf drawing (fades and shadows)
1007 *-----------------------------------------------------------------------------
1010 static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gint p_alpha,
1011 gint s, gint vertical, gint border,
1012 gint x1, gint y1, gint x2, gint y2,
1013 guint8 r, guint8 g, guint8 b, guint8 a)
1020 p_step = (p_alpha) ? 4 : 3;
1021 for (j = y1; j < y2; j++)
1023 pp = p_pix + j * prs + x1 * p_step;
1024 if (!vertical) n = a - a * abs(j - s) / border;
1025 for (i = x1; i < x2; i++)
1027 if (vertical) n = a - a * abs(i - s) / border;
1028 *pp = (r * n + *pp * (256-n)) >> 8;
1030 *pp = (g * n + *pp * (256-n)) >> 8;
1032 *pp = (b * n + *pp * (256-n)) >> 8;
1039 static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gint p_alpha,
1040 gint sx, gint sy, gint border,
1041 gint x1, gint y1, gint x2, gint y2,
1042 guint8 r, guint8 g, guint8 b, guint8 a)
1048 p_step = (p_alpha) ? 4 : 3;
1049 for (j = y1; j < y2; j++)
1051 pp = p_pix + j * prs + x1 * p_step;
1052 for (i = x1; i < x2; i++)
1057 r = MIN(border, (gint)sqrt((i-sx)*(i-sx) + (j-sy)*(j-sy)));
1058 n = a - a * r / border;
1059 *pp = (r * n + *pp * (256-n)) >> 8;
1061 *pp = (g * n + *pp * (256-n)) >> 8;
1063 *pp = (b * n + *pp * (256-n)) >> 8;
1070 void pixbuf_draw_shadow(GdkPixbuf *pb,
1071 gint clip_x, gint clip_y, gint clip_w, gint clip_h,
1072 gint x, gint y, gint w, gint h, gint border,
1073 guint8 r, guint8 g, guint8 b, guint8 a)
1077 gint rx, ry, rw, rh;
1078 gint fx, fy, fw, fh;
1083 pw = gdk_pixbuf_get_width(pb);
1084 ph = gdk_pixbuf_get_height(pb);
1086 if (!util_clip_region(0, 0, pw, ph,
1087 clip_x, clip_y, clip_w, clip_h,
1088 &rx, &ry, &rw, &rh)) return;
1090 p_alpha = gdk_pixbuf_get_has_alpha(pb);
1091 prs = gdk_pixbuf_get_rowstride(pb);
1092 p_pix = gdk_pixbuf_get_pixels(pb);
1094 if (util_clip_region(x + border, y + border, w - border * 2, h - border * 2,
1096 &fx, &fy, &fw, &fh))
1098 pixbuf_draw_rect_fill(pb, fx, fy, fw, fh, r, g, b, a);
1101 if (border < 1) return;
1103 if (util_clip_region(x, y + border, border, h - border * 2,
1105 &fx, &fy, &fw, &fh))
1107 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1108 x + border, TRUE, border,
1109 fx, fy, fx + fw, fy + fh,
1112 if (util_clip_region(x + w - border, y + border, border, h - border * 2,
1114 &fx, &fy, &fw, &fh))
1116 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1117 x + w - border, TRUE, border,
1118 fx, fy, fx + fw, fy + fh,
1121 if (util_clip_region(x + border, y, w - border * 2, border,
1123 &fx, &fy, &fw, &fh))
1125 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1126 y + border, FALSE, border,
1127 fx, fy, fx + fw, fy + fh,
1130 if (util_clip_region(x + border, y + h - border, w - border * 2, border,
1132 &fx, &fy, &fw, &fh))
1134 pixbuf_draw_fade_linear(p_pix, prs, p_alpha,
1135 y + h - border, FALSE, border,
1136 fx, fy, fx + fw, fy + fh,
1139 if (util_clip_region(x, y, border, border,
1141 &fx, &fy, &fw, &fh))
1143 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1144 x + border, y + border, border,
1145 fx, fy, fx + fw, fy + fh,
1148 if (util_clip_region(x + w - border, y, border, border,
1150 &fx, &fy, &fw, &fh))
1152 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1153 x + w - border, y + border, border,
1154 fx, fy, fx + fw, fy + fh,
1157 if (util_clip_region(x, y + h - border, border, border,
1159 &fx, &fy, &fw, &fh))
1161 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1162 x + border, y + h - border, border,
1163 fx, fy, fx + fw, fy + fh,
1166 if (util_clip_region(x + w - border, y + h - border, border, border,
1168 &fx, &fy, &fw, &fh))
1170 pixbuf_draw_fade_radius(p_pix, prs, p_alpha,
1171 x + w - border, y + h - border, border,
1172 fx, fy, fx + fw, fy + fh,