sampler: add level argument to api calls

parent e164a23e
......@@ -409,6 +409,17 @@ GeglBuffer * gegl_buffer_dup (GeglBuffer *buffer);
* of interpolation. The samplers used cache for a small neighbourhood of the
* buffer for more efficient access.
*/
void gegl_buffer_sample_at_level (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *scale,
gpointer dest,
const Babl *format,
gint level,
GeglSamplerType sampler_type,
GeglAbyssPolicy repeat_mode);
void gegl_buffer_sample (GeglBuffer *buffer,
gdouble x,
gdouble y,
......@@ -460,6 +471,12 @@ GeglSampler * gegl_buffer_sampler_new (GeglBuffer *buffer,
const Babl *format,
GeglSamplerType sampler_type);
GeglSampler * gegl_buffer_sampler_new_at_level (GeglBuffer *buffer,
const Babl *format,
GeglSamplerType sampler_type,
gint level);
/**
* gegl_sampler_get:
* @sampler: a GeglSampler gotten from gegl_buffer_sampler_new
......
......@@ -42,6 +42,7 @@ enum
PROP_0,
PROP_BUFFER,
PROP_FORMAT,
PROP_LEVEL,
PROP_CONTEXT_RECT,
PROP_LAST
};
......@@ -98,6 +99,15 @@ gegl_sampler_class_init (GeglSamplerClass *klass)
"babl format",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
PROP_LEVEL,
g_param_spec_int ("level",
"level",
"mimmap level to sample from",
0, 100, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
PROP_BUFFER,
......@@ -391,6 +401,10 @@ get_property (GObject *object,
g_value_set_pointer (value, (void*)self->format);
break;
case PROP_LEVEL:
g_value_set_int (value, self->lvel);
break;
default:
break;
}
......@@ -414,6 +428,10 @@ set_property (GObject *object,
self->format = g_value_get_pointer (value);
break;
case PROP_LEVEL:
self->lvel = g_value_get_int (value);
break;
default:
break;
}
......@@ -469,14 +487,15 @@ gegl_sampler_gtype_from_enum (GeglSamplerType sampler_type)
}
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 (GeglBuffer *buffer,
gdouble x,
gdouble y,
GeglMatrix2 *scale,
gpointer dest,
const Babl *format,
gint level,
GeglSamplerType sampler_type,
GeglAbyssPolicy repeat_mode)
{
GType desired_type;
/*
......@@ -519,6 +538,7 @@ gegl_buffer_sample (GeglBuffer *buffer,
buffer->sampler = g_object_new (desired_type,
"buffer", buffer,
"format", format,
"level", level,
NULL);
buffer->sampler_format = format;
gegl_sampler_prepare (buffer->sampler);
......@@ -528,10 +548,25 @@ gegl_buffer_sample (GeglBuffer *buffer,
g_mutex_unlock (&mutex);
}
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);
}
GeglSampler *
gegl_buffer_sampler_new (GeglBuffer *buffer,
const Babl *format,
GeglSamplerType sampler_type)
gegl_buffer_sampler_new_at_level (GeglBuffer *buffer,
const Babl *format,
GeglSamplerType sampler_type,
gint level)
{
GeglSampler *sampler;
GType desired_type;
......@@ -544,6 +579,7 @@ gegl_buffer_sampler_new (GeglBuffer *buffer,
sampler = g_object_new (desired_type,
"buffer", buffer,
"format", format,
"level", level,
NULL);
gegl_sampler_prepare (sampler);
......@@ -551,6 +587,15 @@ gegl_buffer_sampler_new (GeglBuffer *buffer,
return sampler;
}
GeglSampler *
gegl_buffer_sampler_new (GeglBuffer *buffer,
const Babl *format,
GeglSamplerType sampler_type)
{
return gegl_buffer_sampler_new_at_level (buffer, format, sampler_type, 0);
}
const GeglRectangle*
gegl_sampler_get_context_rect (GeglSampler *sampler)
{
......
......@@ -68,6 +68,7 @@ struct _GeglSampler
/*< private >*/
GeglBuffer *buffer;
gint lvel;
const Babl *format;
const Babl *interpolate_format;
const Babl *fish;
......
......@@ -67,7 +67,8 @@ static void c2g (GeglBuffer *src,
gint radius,
gint samples,
gint iterations,
gdouble rgamma)
gdouble rgamma,
gint level)
{
const Babl *format = babl_format ("RGBA float");
......@@ -75,7 +76,7 @@ static void c2g (GeglBuffer *src,
{
GeglBufferIterator *i = gegl_buffer_iterator_new (dst, dst_rect, 0, babl_format("YA float"),
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
GeglSampler *sampler = gegl_buffer_sampler_new (src, format, GEGL_SAMPLER_NEAREST);
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (src, format, GEGL_SAMPLER_NEAREST, level);
while (gegl_buffer_iterator_next (i))
{
......@@ -330,7 +331,8 @@ process (GeglOperation *operation,
o->radius,
o->samples,
o->iterations,
/*o->rgamma*/RGAMMA);
/*o->rgamma*/RGAMMA,
level);
return TRUE;
}
......
......@@ -227,13 +227,15 @@ process (GeglOperation *operation,
grey_blur_buffer (input, o->mask_radius, &dest1, &dest2);
sampler1 = gegl_buffer_sampler_new (dest1,
sampler1 = gegl_buffer_sampler_new_at_level (dest1,
babl_format ("Y' float"),
GEGL_SAMPLER_LINEAR);
GEGL_SAMPLER_LINEAR,
level);
sampler2 = gegl_buffer_sampler_new (dest2,
sampler2 = gegl_buffer_sampler_new_at_level (dest2,
babl_format ("Y' float"),
GEGL_SAMPLER_LINEAR);
GEGL_SAMPLER_LINEAR,
level);
ramp = compute_ramp (sampler1, sampler2, result, o->pct_black);
......
......@@ -533,7 +533,7 @@ process (GeglOperation *operation,
ix = CLAMP (x, boundary.x, boundary.x + boundary.width - 1);
iy = CLAMP (y, boundary.y, boundary.y + boundary.height - 1);
gegl_buffer_sample (input, ix, iy, NULL, color, format,
gegl_buffer_sample_at_level (input, ix, iy, NULL, color, format, level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
fill_poly_color (&poly, &extended, &boundary, dst_buf, color);
......
......@@ -114,13 +114,15 @@ julia (gdouble x,
static void
fractaltrace (GeglBuffer *input,
GeglSampler *sampler,
const GeglRectangle *picture,
gfloat *dst_buf,
const GeglRectangle *roi,
GeglProperties *o,
GeglProperties *o,
gint y,
GeglFractalTraceType fractal_type,
const Babl *format)
GeglFractalTraceType fractal_type,
const Babl *format,
gint level)
{
GeglMatrix2 scale; /* a matrix indicating scaling factors around the
current center pixel.
......@@ -129,7 +131,6 @@ fractaltrace (GeglBuffer *input,
gdouble scale_x, scale_y;
gdouble bailout2;
gfloat dest[4];
GeglSampler *sampler = gegl_buffer_sampler_new (input, format, GEGL_SAMPLER_NOHALO);
scale_x = (o->X2 - o->X1) / picture->width;
scale_y = (o->Y2 - o->Y1) / picture->height;
......@@ -183,7 +184,6 @@ fractaltrace (GeglBuffer *input,
for (i = 0; i < 4; i++)
dst_buf[offset++] = dest[i];
}
g_object_unref (sampler);
}
static gboolean
......@@ -196,6 +196,7 @@ process (GeglOperation *operation,
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglRectangle boundary;
const Babl *format;
GeglSampler *sampler;
gfloat *dst_buf;
gint y;
......@@ -203,11 +204,13 @@ process (GeglOperation *operation,
format = babl_format ("RGBA float");
dst_buf = g_new0 (gfloat, result->width * result->height * 4);
sampler = gegl_buffer_sampler_new_at_level (input, format, GEGL_SAMPLER_NOHALO, level);
for (y = result->y; y < result->y + result->height; y++)
fractaltrace (input, &boundary, dst_buf, result, o, y, o->fractal, format);
fractaltrace (input, sampler, &boundary, dst_buf, result, o, y, o->fractal, format, level);
gegl_buffer_set (output, result, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE);
g_object_unref (sampler);
g_free (dst_buf);
......
......@@ -331,7 +331,8 @@ lens_distort_func (gfloat *src_buf,
gint xx,
gint yy,
GeglBuffer *input,
gfloat *background)
gfloat *background,
gint level)
{
gdouble sx, sy, mag;
gdouble brighten;
......@@ -379,8 +380,9 @@ lens_distort_func (gfloat *src_buf,
}
else
{
gegl_buffer_sample (input, x, y, NULL, temp,
gegl_buffer_sample_at_level (input, x, y, NULL, temp,
babl_format ("RGBA float"),
level,
GEGL_SAMPLER_LINEAR,
GEGL_ABYSS_CLAMP);
}
......@@ -448,7 +450,7 @@ process (GeglOperation *operation,
for (x = chunked_result.x; x < chunked_result.x + chunked_result.width; x++)
{
lens_distort_func (src_buf, dst_buf, &area, &chunked_result, &boundary,
&lens, x, y, input, background);
&lens, x, y, input, background, level);
}
gegl_buffer_set (output, &chunked_result, 0, babl_format ("RGBA float"),
......
......@@ -70,7 +70,7 @@ process (GeglOperation *operation,
format_io = babl_format ("RGBA float");
format_coords = babl_format_n (babl_type ("float"), 2);
sampler = gegl_buffer_sampler_new (input, format_io, o->sampler_type);
sampler = gegl_buffer_sampler_new_at_level (input, format_io, level, o->sampler_type);
if (aux != NULL)
{
......
......@@ -75,7 +75,7 @@ process (GeglOperation *operation,
format_io = babl_format ("RGBA float");
format_coords = babl_format_n (babl_type ("float"), 2);
sampler = gegl_buffer_sampler_new (input, format_io, o->sampler_type);
sampler = gegl_buffer_sampler_new_at_level (input, format_io, o->sampler_type, level);
if (aux != NULL)
{
......
......@@ -156,7 +156,8 @@ apply_mirror (double mirror_angle,
GeglRectangle *in_boundary,
GeglBuffer *dst,
GeglRectangle *boundary,
const GeglRectangle *roi)
const GeglRectangle *roi,
gint level)
{
gfloat *dst_buf;
gint row, col;
......@@ -265,7 +266,7 @@ apply_mirror (double mirror_angle,
#ifndef DO_NOT_USE_BUFFER_SAMPLE
gegl_buffer_sample (src, cx, cy, NULL, &dst_buf[(row * roi->width + col) * 4], format, GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE);
gegl_buffer_sample_at_level (src, cx, cy, NULL, &dst_buf[(row * roi->width + col) * 4], format, level, GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE);
#endif
#ifdef DO_NOT_USE_BUFFER_SAMPLE
......@@ -404,7 +405,8 @@ process (GeglOperation *operation,
&eff_boundary,
output,
&boundary,
result);
result,
level);
return TRUE;
}
......
......@@ -114,7 +114,8 @@ process (GeglOperation *operation,
}
}
gegl_buffer_sample (input, pos_x, pos_y, NULL, data, format,
gegl_buffer_sample_at_level (input, pos_x, pos_y, NULL, data, format,
level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_CLAMP);
data += bpp;
}
......
......@@ -126,7 +126,8 @@ process (GeglOperation *operation,
}
}
gegl_buffer_sample (input, pos_x, pos_y, NULL, data, format,
gegl_buffer_sample_at_level (input, pos_x, pos_y, NULL, data, format,
level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_CLAMP);
data += bpp;
}
......
......@@ -128,7 +128,7 @@ process (GeglOperation *operation,
calc_sample_coords (i, j, amount_x, amount_y, o->rand, &x, &y);
gegl_buffer_sample (input, x, y, NULL, data, format,
gegl_buffer_sample_at_level (input, x, y, NULL, data, format, level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_CLAMP);
data += bpp;
}
......
......@@ -367,7 +367,8 @@ process (GeglOperation *operation,
prepare_transform2 (&transform, operation);
format_io = babl_format ("RaGaBaA float");
sampler = gegl_buffer_sampler_new (input, format_io, o->sampler_type);
sampler = gegl_buffer_sampler_new_at_level (input, format_io, o->sampler_type,
level);
if (o->sampler_type == GEGL_SAMPLER_NOHALO ||
o->sampler_type == GEGL_SAMPLER_LOHALO)
......
......@@ -171,7 +171,8 @@ do_plasma (PlasmaContext *context,
gint x2,
gint y2,
gint plasma_depth,
gint recursion_depth)
gint recursion_depth,
gint level)
{
gfloat tl[3], ml[3], bl[3], mt[3], mm[3], mb[3], tr[3], mr[3], br[3];
gfloat tmp[3];
......@@ -198,7 +199,7 @@ do_plasma (PlasmaContext *context,
context->buffer_y = y1;
context->buffer_width = x2 - x1 + 1;
ret = do_plasma (context, x1, y1, x2, y2, plasma_depth, recursion_depth);
ret = do_plasma (context, x1, y1, x2, y2, plasma_depth, recursion_depth, level);
context->using_buffer = FALSE;
......@@ -248,17 +249,17 @@ do_plasma (PlasmaContext *context,
if (x1 == x2 && y1 == y2)
return FALSE;
gegl_buffer_sample (context->output, x1, y1, NULL, tl,
babl_format ("R'G'B' float"),
gegl_buffer_sample_at_level (context->output, x1, y1, NULL, tl,
babl_format ("R'G'B' float"), level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
gegl_buffer_sample (context->output, x1, y2, NULL, bl,
babl_format ("R'G'B' float"),
gegl_buffer_sample_at_level (context->output, x1, y2, NULL, bl,
babl_format ("R'G'B' float"), level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
gegl_buffer_sample (context->output, x2, y1, NULL, tr,
babl_format ("R'G'B' float"),
gegl_buffer_sample_at_level (context->output, x2, y1, NULL, tr,
babl_format ("R'G'B' float"), level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
gegl_buffer_sample (context->output, x2, y2, NULL, br,
babl_format ("R'G'B' float"),
gegl_buffer_sample_at_level (context->output, x2, y2, NULL, br,
babl_format ("R'G'B' float"), level,
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
ran = context->o->turbulence / (2.0 * recursion_depth);
......@@ -316,14 +317,14 @@ do_plasma (PlasmaContext *context,
if (x1 < x2 || y1 < y2)
{
/* Top left. */
do_plasma (context, x1, y1, xm, ym, plasma_depth - 1, recursion_depth + 1);
do_plasma (context, x1, y1, xm, ym, plasma_depth - 1, recursion_depth + 1, level);
/* Bottom left. */
do_plasma (context, x1, ym, xm, y2, plasma_depth - 1, recursion_depth + 1);
do_plasma (context, x1, ym, xm, y2, plasma_depth - 1, recursion_depth + 1, level);
/* Top right. */
do_plasma (context, xm, y1, x2, ym, plasma_depth - 1, recursion_depth + 1);
do_plasma (context, xm, y1, x2, ym, plasma_depth - 1, recursion_depth + 1, level);
/* Bottom right. */
return do_plasma (context, xm, ym, x2, y2,
plasma_depth - 1, recursion_depth + 1);
plasma_depth - 1, recursion_depth + 1, level);
}
return TRUE;
......@@ -360,13 +361,13 @@ process (GeglOperation *operation,
context->gr = g_rand_new_with_seed (context->o->seed);
do_plasma (context, result->x, result->y, x-1, y-1, -1, 0);
do_plasma (context, result->x, result->y, x-1, y-1, -1, 0, level);
/*
* Now we recurse through the images, going deeper each time
*/
depth = 1;
while (!do_plasma (context, result->x, result->y, x-1, y-1, depth, 0))
while (!do_plasma (context, result->x, result->y, x-1, y-1, depth, 0, level))
depth++;
gegl_buffer_sample_cleanup (context->output);
......
......@@ -323,8 +323,9 @@ process (GeglOperation *operation,
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglRectangle boundary = get_effective_area (operation);
const Babl *format = babl_format ("RGBA float");
GeglSampler *sampler = gegl_buffer_sampler_new (
input, format, GEGL_SAMPLER_NOHALO);
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (
input, format, GEGL_SAMPLER_NOHALO,
level);
gint x,y;
gfloat *src_buf, *dst_buf;
......
......@@ -91,9 +91,10 @@ process (GeglOperation *operation,
gint level)
{
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglSampler *sampler = gegl_buffer_sampler_new (input,
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (input,
babl_format ("RGBA float"),
o->sampler_type);
o->sampler_type,
level);
GeglBufferIterator *iter;
GeglAbyssPolicy abyss = o->tileable ? GEGL_ABYSS_LOOP : GEGL_ABYSS_NONE;
......
......@@ -71,7 +71,8 @@ static void stress (GeglBuffer *src,
gint radius,
gint samples,
gint iterations,
gdouble rgamma)
gdouble rgamma,
gint level)
{
const Babl *format = babl_format ("RGBA float");
......@@ -79,7 +80,7 @@ static void stress (GeglBuffer *src,
{
GeglBufferIterator *i = gegl_buffer_iterator_new (dst, dst_rect, 0, babl_format("RaGaBaA float"),
GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
GeglSampler *sampler = gegl_buffer_sampler_new (src, format, GEGL_SAMPLER_NEAREST);
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (src, format, GEGL_SAMPLER_NEAREST, level);
while (gegl_buffer_iterator_next (i))
{
......@@ -170,7 +171,7 @@ process (GeglOperation *operation,
o->radius,
o->samples,
o->iterations,
RGAMMA /*o->rgamma,*/);
RGAMMA /*o->rgamma,*/, level);
return TRUE;
}
......
......@@ -86,9 +86,10 @@ process (GeglOperation *operation,
gint level)
{
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglSampler *sampler = gegl_buffer_sampler_new (input,
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (input,
babl_format ("RGBA float"),
o->sampler_type);
o->sampler_type,
level);
GeglRectangle *in_extent = gegl_operation_source_get_bounding_box (operation, "input");
GeglBufferIterator *iter;
......
......@@ -144,7 +144,8 @@ apply_whirl_pinch (gdouble whirl,
GeglRectangle *in_boundary,
GeglBuffer *dst,
GeglRectangle *boundary,
const GeglRectangle *roi)
const GeglRectangle *roi,
gint level)
{
gfloat *dst_buf;
gint row, col;
......@@ -159,8 +160,8 @@ apply_whirl_pinch (gdouble whirl,
scale_x = 1.0;
scale_y = (gdouble) in_boundary->width / in_boundary->height;
sampler = gegl_buffer_sampler_new (src, babl_format ("RaGaBaA float"),
GEGL_SAMPLER_NOHALO);
sampler = gegl_buffer_sampler_new_at_level (src, babl_format ("RaGaBaA float"),
GEGL_SAMPLER_NOHALO, level);
for (row = 0; row < roi->height; row++) {
for (col = 0; col < roi->width; col++) {
......@@ -248,7 +249,8 @@ process (GeglOperation *operation,
&boundary,
output,
&boundary,
result);
result,
level);
return TRUE;
}
......
......@@ -557,9 +557,10 @@ gegl_transform_get_required_for_output (GeglOperation *op,
gegl_matrix3_is_identity (&inverse))
return requested_rect;
sampler = gegl_buffer_sampler_new (NULL,
sampler = gegl_buffer_sampler_new_at_level (NULL,
babl_format("RaGaBaA float"),
transform->sampler);
transform->sampler,
0); //XXX: need level?
context_rect = *gegl_sampler_get_context_rect (sampler);
g_object_unref (sampler);
......@@ -636,9 +637,10 @@ gegl_transform_get_invalidated_by_change (GeglOperation *op,
* allow for round off error (for "safety")?
*/
sampler = gegl_buffer_sampler_new (NULL,
sampler = gegl_buffer_sampler_new_at_level (NULL,
babl_format("RaGaBaA float"),
transform->sampler);
transform->sampler,
0); // XXX: need level?
context_rect = *gegl_sampler_get_context_rect (sampler);
g_object_unref (sampler);
......@@ -743,14 +745,16 @@ transform_affine (GeglOperation *operation,
GeglMatrix3 *matrix,
gint level)
{
//gint factor = 1 << level;
OpTransform *transform = (OpTransform *) operation;
const Babl *format = babl_format ("RaGaBaA float");
GeglMatrix3 inverse;
GeglMatrix2 inverse_jacobian;
gint dest_pixels;
GeglSampler *sampler = gegl_buffer_sampler_new (src,
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (src,
babl_format("RaGaBaA float"),
transform->sampler);
transform->sampler,
level);
GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
......@@ -959,9 +963,10 @@ transform_generic (GeglOperation *operation,
const GeglRectangle *dest_extent;
GeglMatrix3 inverse;
gint dest_pixels;
GeglSampler *sampler = gegl_buffer_sampler_new (src,
GeglSampler *sampler = gegl_buffer_sampler_new_at_level (src,
babl_format("RaGaBaA float"),
transform->sampler);
transform->sampler,
level);
GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
g_object_get (dest, "pixels", &dest_pixels, NULL);
......
......@@ -87,7 +87,7 @@ main (gint argc,
{
int j;
float px[4] = {0.2, 0.4, 0.1, 0.5};
GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
GEGL_SAMPLER_NEAREST);
for (j = 0; j < SAMPLES; j ++)
......
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