static void lens_distort_func (gint ix, gint iy, guchar *dest, gint bpp, GimpPixelFetcher *pft) { gdouble src_x, src_y, mag; gdouble brighten; guchar pixel_buffer[16 * LENS_MAX_PIXEL_DEPTH]; guchar *pixel; gdouble dx, dy; gint x_int, y_int; gint x, y; lens_get_source_coords (ix, iy, &src_x, &src_y, &mag); brighten = 1.0 + mag * calc_vals.brighten; x_int = floor (src_x); dx = src_x - x_int; y_int = floor (src_y); dy = src_y - y_int; pixel = pixel_buffer; for (y = y_int - 1; y <= y_int + 2; y++) { for (x = x_int -1; x <= x_int + 2; x++) { if (x >= 0 && y >= 0 && x < drawable_width && y < drawable_height) { gimp_pixel_fetcher_get_pixel (pft, x, y, pixel); } else { gint i; for (i = 0; i < bpp; i++) pixel[i] = background_color[i]; } pixel += bpp; } } lens_cubic_interpolate (pixel_buffer, bpp * 4, bpp, dest, bpp, dx, dy, brighten); }
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) { 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 (input, x, y, NULL, temp, babl_format ("RGBA float"), 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]; }
static void lens_distort_func (gfloat *src_buf, gfloat *dst_buf, const GeglRectangle *extended, const GeglRectangle *result, const GeglRectangle *boundary, LensDistortion old, gint xx, gint yy, GeglBuffer *input) { 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, &old); brighten = 1.0 + mag * old.brighten; 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 >= 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 if (x >= boundary->x && x < boundary->x + boundary->width && y >= boundary->y && y < boundary->y + boundary->height) { gegl_buffer_sample (input, x, y, NULL, temp, babl_format ("RGBA float"), GEGL_SAMPLER_CUBIC, GEGL_ABYSS_NONE); } else { for (b=0; b<4; b++) temp[b] = 0.0; } 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]; }