gegl_buffer_sample: change API

Made scale be a GeglMatrix2 instead of a gfloat, allowing to specify a more
correct sampling context. This is an API change, not many things are using the
GEGL so this should be fine. In GIMP there is one instance that needs updating
but it resides in #ifdef 0'd code so there should be no API conflict.
parent 1726d5b3
......@@ -1065,13 +1065,13 @@ gegl_buffer_get_abyss (GeglBuffer *buffer)
}
void
gegl_buffer_sample2 (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *scale,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation)
gegl_buffer_sample (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *scale,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation)
{
GType desired_type;
g_return_if_fail (GEGL_IS_BUFFER (buffer));
......@@ -1110,18 +1110,6 @@ gegl_buffer_sample2 (GeglBuffer *buffer,
gegl_sampler_get (buffer->sampler, x, y, dest);
}
void
gegl_buffer_sample (GeglBuffer *buffer,
gdouble x,
gdouble y,
gdouble scale,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation)
{
gegl_buffer_sample2 (buffer, x, y, NULL, dest, format, interpolation);
}
void
gegl_buffer_sample_cleanup (GeglBuffer *buffer)
{
......
......@@ -21,7 +21,7 @@
#include <glib-object.h>
#include <babl/babl.h>
#include <gegl/gegl-matrix.h>
#include <gegl-matrix.h>
G_BEGIN_DECLS
......@@ -322,11 +322,12 @@ typedef enum {
* @buffer: the GeglBuffer to sample from
* @x: x coordinate to sample in buffer coordinates
* @y: y coordinate to sample in buffer coordinates
* @scale: the scale we're fetching at (<1.0 can lead to decimation)
* @scale: a matrix that indicates scaling factors, see
* gegl_sampler_compute_scale the same.
* @dest: buffer capable of storing one pixel in @format.
* @format: the format to store the sampled color in.
* @interpolation: the interpolation behavior to use,
* to be ported from working code. Valid values: GEGL_INTERPOLATION_NEAREST and
* to be ported from working code. Valid values: GEGL_INTERPOLATION_NEAREST,
* GEGL_INTERPOLATION_LINEAR, GEGL_INTERPOLATION_CUBIC,
* GEGL_INTERPOLATION_LANCZOS and GEGL_INTERPOLATION_LOHALO
*
......@@ -334,21 +335,13 @@ typedef enum {
* of interpolation. The samplers used cache for a small neighbourhood of the
* buffer for more efficient access.
*/
void gegl_buffer_sample (GeglBuffer *buffer,
gdouble x,
gdouble y,
gdouble scale,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation);
void
gegl_buffer_sample2 (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *inverse_jacobian,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation);
void gegl_buffer_sample (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *scale,
gpointer dest,
const Babl *format,
GeglInterpolation interpolation);
/**
......
......@@ -105,15 +105,15 @@ const gchar * gegl_extension_handler_get_saver (const gchar *extensi
*
* #undef gegl_unmap // IMPORTANT undefine map macro
*/
#define gegl_sampler_compute_scale (matrix, x, y) \
#define gegl_sampler_compute_scale(matrix, x, y) \
{ \
float ax, ay, bx, by; \
gegl_inverse_map(x + 0.5, y, ax, ay); \
gegl_inverse_map(x - 0.5, y, bx, by); \
gegl_unmap(x + 0.5, y, ax, ay); \
gegl_unmap(x - 0.5, y, bx, by); \
matrix.coeff[0][0] = ax - bx; \
matrix.coeff[1][0] = ay - by; \
gegl_inverse_map(x, y + 0.5, ax, ay); \
gegl_inverse_map(x, y - 0.5, bx, by); \
gegl_unmap(x, y + 0.5, ax, ay); \
gegl_unmap(x, y - 0.5, bx, by); \
matrix.coeff[0][1] = ax - bx; \
matrix.coeff[1][1] = ay - by; \
}
......
......@@ -234,7 +234,7 @@ apply_mirror (double mirror_angle,
#ifndef DO_NOT_USE_BUFFER_SAMPLE
gegl_buffer_sample (src, cx, cy, 1.0, &dst_buf[(row * roi->width + col) * 4], format, GEGL_INTERPOLATION_LINEAR);
gegl_buffer_sample (src, cx, cy, NULL, &dst_buf[(row * roi->width + col) * 4], format, GEGL_INTERPOLATION_LINEAR);
#endif
#ifdef DO_NOT_USE_BUFFER_SAMPLE
......
......@@ -140,7 +140,7 @@ fractaltrace (GeglBuffer *input,
switch (fractal_type)
{
case FRACTAL_TYPE_JULIA:
#define gegl_inverse_map(u,v,ud,vd) {\
#define gegl_unmap(u,v,ud,vd) {\
gdouble rx, ry;\
cx = o->X1 + ((u) - picture->x) * scale_x; \
cy = o->Y1 + ((v) - picture->y) * scale_y; \
......@@ -149,12 +149,12 @@ fractaltrace (GeglBuffer *input,
vd = (ry - o->Y1) / scale_y + picture->y;\
}
gegl_sampler_compute_scale (scale, x, y);
gegl_inverse_map(x,y,px,py);
#undef gegl_inverse_map
gegl_unmap(x,y,px,py);
#undef gegl_unmap
break;
case FRACTAL_TYPE_MANDELBROT:
#define gegl_inverse_map(u,v,ud,vd) {\
#define gegl_unmap(u,v,ud,vd) {\
gdouble rx, ry;\
cx = o->X1 + ((u) - picture->x) * scale_x; \
cy = o->Y1 + ((v) - picture->y) * scale_y; \
......@@ -163,8 +163,8 @@ fractaltrace (GeglBuffer *input,
vd = (ry - o->Y1) / scale_y + picture->y;\
}
gegl_compute_inverse_jacobian (scale, x, y);
gegl_inverse_map(x,y,px,py);
#undef gegl_inverse_map
gegl_unmap(x,y,px,py);
#undef gegl_unmap
break;
default:
......
......@@ -90,9 +90,9 @@ apply_spread (gint x_amount,
calc_sample_coords (x1, y1, x_amount, y_amount, gr, &x, &y);
/* Only displace the pixel if it's within the bounds of the image. */
if (x >= 0 && x < img_width && y >= 0 && y < img_height)
gegl_buffer_sample (src, x, y, 1.0, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_INTERPOLATION_LINEAR);
gegl_buffer_sample (src, x, y, NULL, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_INTERPOLATION_LINEAR);
else /* Else just copy it */
gegl_buffer_sample (src, x1, y1, 1.0, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_INTERPOLATION_LINEAR);
gegl_buffer_sample (src, x1, y1, NULL, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_INTERPOLATION_LINEAR);
} /* for */
} /* for */
......
......@@ -218,13 +218,13 @@ do_plasma_big (PlasmaContext *context,
if (x1 == x2 && y1 == y2)
return FALSE;
gegl_buffer_sample (context->output, x1, y1, 1.0, tl, babl_format ("RGBA float"),
gegl_buffer_sample (context->output, x1, y1, NULL, tl, babl_format ("RGBA float"),
GEGL_INTERPOLATION_NEAREST);
gegl_buffer_sample (context->output, x1, y2, 1.0, bl, babl_format ("RGBA float"),
gegl_buffer_sample (context->output, x1, y2, NULL, bl, babl_format ("RGBA float"),
GEGL_INTERPOLATION_NEAREST);
gegl_buffer_sample (context->output, x2, y1, 1.0, tr, babl_format ("RGBA float"),
gegl_buffer_sample (context->output, x2, y1, NULL, tr, babl_format ("RGBA float"),
GEGL_INTERPOLATION_NEAREST);
gegl_buffer_sample (context->output, x2, y2, 1.0, br, babl_format ("RGBA float"),
gegl_buffer_sample (context->output, x2, y2, NULL, br, babl_format ("RGBA float"),
GEGL_INTERPOLATION_NEAREST);
ran = context->o->turbulence / (2.0 * scale_depth);
......
......@@ -142,14 +142,13 @@ apply_whirl_pinch (gdouble whirl, gdouble pinch, gdouble radius,
for (row = 0; row < roi->height; row++) {
for (col = 0; col < roi->width; col++) {
calc_undistorted_coords (roi->x + col, roi->y + row,
cen_x, cen_y,
scale_x, scale_y,
whirl, pinch, radius,
&cx, &cy);
gegl_buffer_sample (src, cx, cy, 1.0, &dst_buf[(row * roi->width + col) * 4], format, GEGL_INTERPOLATION_LINEAR);
gegl_buffer_sample (src, cx, cy, NULL, &dst_buf[(row * roi->width + col) * 4], format, GEGL_INTERPOLATION_LINEAR);
} /* for */
} /* for */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment