static void lic_image (GimpPixelRgn *src_rgn, gint x, gint y, gdouble vx, gdouble vy, GimpRGB *color) { gdouble u, step = 2.0 * l / isteps; gdouble xx = (gdouble) x, yy = (gdouble) y; gdouble c, s; GimpRGB col = { 0, 0, 0, 0 }; GimpRGB col1, col2, col3; /* Get vector at x,y */ /* ================= */ c = vx; s = vy; /* Calculate integral numerically */ /* ============================== */ getpixel (src_rgn, &col1, xx + l * c, yy + l * s); if (source_drw_has_alpha) gimp_rgba_multiply (&col1, filter (-l)); else gimp_rgb_multiply (&col1, filter (-l)); for (u = -l + step; u <= l; u += step) { getpixel (src_rgn, &col2, xx - u * c, yy - u * s); if (source_drw_has_alpha) { gimp_rgba_multiply (&col2, filter (u)); col3 = col1; gimp_rgba_add (&col3, &col2); gimp_rgba_multiply (&col3, 0.5 * step); gimp_rgba_add (&col, &col3); } else { gimp_rgb_multiply (&col2, filter (u)); col3 = col1; gimp_rgb_add (&col3, &col2); gimp_rgb_multiply (&col3, 0.5 * step); gimp_rgb_add (&col, &col3); } col1 = col2; } if (source_drw_has_alpha) gimp_rgba_multiply (&col, 1.0 / l); else gimp_rgb_multiply (&col, 1.0 / l); gimp_rgb_clamp (&col); *color = col; }
static VALUE rb_gimp_rgba_multiply (VALUE self, VALUE factor) { GimpRGB result = rb2GimpRGB(self); gimp_rgba_multiply(&result, (gdouble)NUM2DBL(factor)); return GimpRGB2rb(&result); }
static void compute_lic (GimpDrawable *drawable, const guchar *scalarfield, gboolean rotate) { gint xcount, ycount; GimpRGB color; gdouble vx, vy, tmp; GimpPixelRgn src_rgn, dest_rgn; gimp_pixel_rgn_init (&src_rgn, drawable, border_x, border_y, border_w, border_h, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, drawable, border_x, border_y, border_w, border_h, TRUE, TRUE); for (ycount = 0; ycount < src_rgn.h; ycount++) { for (xcount = 0; xcount < src_rgn.w; xcount++) { /* Get derivative at (x,y) and normalize it */ /* ============================================================== */ vx = gradx (scalarfield, xcount, ycount); vy = grady (scalarfield, xcount, ycount); /* Rotate if needed */ if (rotate) { tmp = vy; vy = -vx; vx = tmp; } tmp = sqrt (vx * vx + vy * vy); if (tmp >= 0.000001) { tmp = 1.0 / tmp; vx *= tmp; vy *= tmp; } /* Convolve with the LIC at (x,y) */ /* ============================== */ if (licvals.effect_convolve == 0) { peek (&src_rgn, xcount, ycount, &color); tmp = lic_noise (xcount, ycount, vx, vy); if (source_drw_has_alpha) gimp_rgba_multiply (&color, tmp); else gimp_rgb_multiply (&color, tmp); } else { lic_image (&src_rgn, xcount, ycount, vx, vy, &color); } poke (&dest_rgn, xcount, ycount, &color); } gimp_progress_update ((gfloat) ycount / (gfloat) src_rgn.h); } gimp_progress_update (1.0); }