void gegl_buffer_sample (GeglBuffer *buffer, gdouble x, gdouble y, GeglMatrix2 *scale, gpointer dest, const Babl *format, GeglSamplerType sampler_type, GeglAbyssPolicy repeat_mode) { gegl_buffer_sample_at_level (buffer, x, y, scale, dest, format, 0, sampler_type, repeat_mode); }
static void lens_distort_func (gfloat *src_buf, gfloat *dst_buf, const GeglRectangle *extended, const GeglRectangle *result, const GeglRectangle *boundary, LensValues *lens, gint xx, gint yy, GeglBuffer *input, gfloat *background, gint level) { gdouble sx, sy, mag; gdouble brighten; gfloat pixel_buffer [16 * 4], temp[4]; gdouble dx, dy; gint x_int, y_int, x = 0, y = 0, offset = 0; temp[0] = temp[1] = temp[2] = temp[3] = 0.0; lens_get_source_coord ((gdouble) xx, (gdouble) yy, &sx, &sy, &mag, lens); /* pseudo gamma transformation, since the input is scRGB */ brighten = pow (MAX (1.0 + mag * lens->brighten, 0.0), 2.4); x_int = floor (sx); dx = sx - x_int; y_int = floor (sy); dy = sy - y_int; for (y = y_int - 1; y <= y_int + 2; y++) { for (x = x_int - 1; x <= x_int + 2; x++) { gint b; if (x < boundary->x || x >= (boundary->x + boundary->width) || y < boundary->y || y >= (boundary->y + boundary->height)) { for (b = 0; b < 4; b++) pixel_buffer[offset++] = background[b]; } else { if (x >= extended->x && x < (extended->x + extended->width) && y >= extended->y && y < (extended->y + extended->height)) { gint src_off; src_off = (y - extended->y) * extended->width * 4 + (x - extended->x) * 4; for (b = 0; b < 4; b++) temp[b] = src_buf[src_off++]; } else { gegl_buffer_sample_at_level (input, x, y, NULL, temp, babl_format ("RGBA float"), level, GEGL_SAMPLER_LINEAR, GEGL_ABYSS_CLAMP); } for (b = 0; b < 4; b++) pixel_buffer[offset++] = temp[b]; } } } lens_cubic_interpolate (pixel_buffer, temp, dx, dy, brighten); offset = (yy - result->y) * result->width * 4 + (xx - result->x) * 4; for (x = 0; x < 4; x++) dst_buf[offset++] = temp[x]; }