void gegl_sampler_nearest_get ( GeglSampler* restrict self, const gdouble absolute_x, const gdouble absolute_y, GeglMatrix2 *scale, void* restrict output, GeglAbyssPolicy repeat_mode) { /* * The reason why floor of the absolute position gives the nearest * pixel (with ties resolved toward -infinity) is that the absolute * position is corner-based (origin at the top left corner of the * pixel labeled (0,0)) so that the center of the top left pixel is * located at (.5,.5) (instead of (0,0) as it would be if absolute * positions were center-based). */ const gint channels = 4; gfloat newval[channels]; const gfloat* restrict in_bptr = gegl_sampler_get_ptr (self, (gint) floor ((double) absolute_x), (gint) floor ((double) absolute_y), repeat_mode); newval[0] = *in_bptr++; newval[1] = *in_bptr++; newval[2] = *in_bptr++; newval[3] = *in_bptr; babl_process (self->fish, newval, output, 1); }
void gegl_sampler_cubic_get (GeglSampler *self, gdouble x, gdouble y, void *output) { GeglSamplerCubic *cubic = (GeglSamplerCubic*)(self); GeglRectangle context_rect; const gint offsets[16]={-4-64*4, 4, 4, 4, (64-3)*4, 4, 4, 4, (64-3)*4, 4, 4, 4, (64-3)*4, 4, 4, 4}; gfloat *sampler_bptr; gfloat factor; #ifdef HAS_G4FLOAT g4float newval4 = g4float_zero; gfloat *newval = &newval4; #else gfloat newval[4] = {0.0, 0.0, 0.0, 0.0}; #endif gint u,v; gint dx,dy; gint i; context_rect = self->context_rect; dx = (gint) x; dy = (gint) y; sampler_bptr = gegl_sampler_get_ptr (self, dx, dy); #ifdef HAS_G4FLOAT if (G_LIKELY (gegl_cpu_accel_get_support () & (GEGL_CPU_ACCEL_X86_SSE| GEGL_CPU_ACCEL_X8&_MMX))) { for (v=dy+context_rect.y, i=0; v < dy+context_rect.y+context_rect.height ; v++) for (u=dx+context_rect.x ; u < dx+context_rect.x+context_rect.width ; u++, i++) { sampler_bptr += offsets[i]; factor = cubicKernel (y - v, cubic->b, cubic->c) * cubicKernel (x - u, cubic->b, cubic->c); newval4 += g4float_mul(&sampler_bptr[0], factor); } } else #endif { for (v=dy+context_rect.y, i=0; v < dy+context_rect.y+context_rect.height ; v++) for (u=dx+context_rect.x ; u < dx+context_rect.x+context_rect.width ; u++, i++) { /*sampler_bptr = gegl_sampler_get_from_buffer (self, u, v);*/ sampler_bptr += offsets[i]; factor = cubicKernel (y - v, cubic->b, cubic->c) * cubicKernel (x - u, cubic->b, cubic->c); newval[0] += factor * sampler_bptr[0]; newval[1] += factor * sampler_bptr[1]; newval[2] += factor * sampler_bptr[2]; newval[3] += factor * sampler_bptr[3]; } } babl_process (self->fish, newval, output, 1); }
const gint ix = FAST_PSEUDO_FLOOR (absolute_x); const gint iy = FAST_PSEUDO_FLOOR (absolute_y); /* * x is the x-coordinate of the sampling point relative to the * position of the top left pixel center. Similarly for y. Range of * values: [0,1]. */ const gfloat x = absolute_x - ix; const gfloat y = absolute_y - iy; /* * Point the data tile pointer to the first channel of the top_left * pixel value: */ const gfloat* restrict in_bptr = gegl_sampler_get_ptr (self, ix, iy); /* * First bilinear weight: */ const gfloat x_times_y = x * y; /* * Load top row: */ const gfloat top_left_0 = *in_bptr++; const gfloat top_left_1 = *in_bptr++; const gfloat top_left_2 = *in_bptr++; const gfloat top_left_3 = *in_bptr++; const gfloat top_rite_0 = *in_bptr++; const gfloat top_rite_1 = *in_bptr++;