On 10/15/06, Geert Jordaens <geert.jordaens@xxxxxxxxxx> wrote:
I've added the implementation to bug report : Bug 360888 – Interpolation
snip
usage :
snip Maybe something along the following lines would be a better API? /Øyvind K. void displacementmap (GeglBuffer *src, GeglBuffer *aux, GeglBuffer *dst, gdouble scale, gint cx, gint cy) { gint i, j; gint dst_pos=0; gfloat *buf = g_malloc0 (4 * 4 * 4); gfloat *aux_buf = g_malloc0 (aux->width * aux->height * 4 * 4); gfloat *dst_buf = g_malloc0 (dst->width * dst->height * 4 * 4); gegl_buffer_get_fmt (aux, aux_buf, babl_format ("RGBA float")); gegl_buffer_get_fmt (dst, dst_buf, babl_format ("RaGaBaA float")); *GeglSampler *sampler = g_object_new (GEGL_TYPE_SAMPLER_CUBIC, "input", src, "format", babl_format ("RaGaBaA float"), "x", 50, "y", 50, "width", 200, /* or a rect could be passed, or a subbuffer of "height", 200, buffer expected to be created before making a sampler */ NULL); for (i = 0; i < src->height; i++) for (j = 0; j < src->width; j++) { gdouble dx, dy, xc, yc; /* Calculate x/y - offset relative to origin */ dx = (gdouble) j / (src->width-1.0); dy = (gdouble) i / (src->height-1.0); xc = j + (gint) (displacement (aux, aux_buf, dx, dy, cx) * scale); yc = i + (gint) (displacement (aux, aux_buf, dx, dy, cy) * scale); /* returns a freshly sampled pixel in dst */ gegl_sampler_get (sampler, xc, yc, buf); #if 0 /* using this form, might make more sense, since it would allow accurate sampling as needed by affine/perspective transforms that are scaling down as well as when scaling up/interpolating */ gegl_sampler_get_quad (sampler, xc-0.5, yc-0.5, xc+0.5, yc-0.5, xc+0.5, yc+0.5, xc-0.5, yc+0.5, buf); #endif { int component; for (component = 0 ; component < 4 ; component++) dst_buf[dst_pos+component]= buf[component]; } dst_pos+=4; } gegl_buffer_set_fmt (dst, dst_buf, babl_format ("RaGaBaA float")); g_object_unref (sampler); g_free (aux_buf); g_free (dst_buf); } -- «The future is already here. It's just not very evenly distributed» -- William Gibson http://pippin.gimp.org/ http://ffii.org/ _______________________________________________ Gegl-developer mailing list Gegl-developer@xxxxxxxxxxxxxxxxxxxxxx https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer