static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglRectangle boundary; const Babl *format; gfloat *dst_buf; gint y; boundary = gegl_operation_get_bounding_box (operation); format = babl_format ("RGBA float"); dst_buf = g_new0 (gfloat, result->width * result->height * 4); for (y = result->y; y < result->y + result->height; y++) fractaltrace (input, &boundary, dst_buf, result, o, y, o->fractal, format); gegl_buffer_set (output, result, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE); g_free (dst_buf); gegl_buffer_sample_cleanup (input); return TRUE; }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglProperties *o = GEGL_PROPERTIES (operation); GeglRectangle boundary; const Babl *format; GeglSampler *sampler; gfloat *dst_buf; gint y; boundary = gegl_operation_get_bounding_box (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_CUBIC, level); for (y = result->y; y < result->y + result->height; y++) 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); gegl_buffer_sample_cleanup (input); return TRUE; }
static void gegl_buffer_dispose (GObject *object) { GeglBuffer *buffer = GEGL_BUFFER (object); GeglTileHandler *handler = GEGL_TILE_HANDLER (object); gegl_buffer_sample_cleanup (buffer); if (gegl_cl_is_accelerated ()) gegl_buffer_cl_cache_invalidate (GEGL_BUFFER (object), NULL); if (handler->source && GEGL_IS_TILE_STORAGE (handler->source)) { GeglTileBackend *backend = gegl_buffer_backend (buffer); /* only flush non-internal backends,. */ if (!(GEGL_IS_TILE_BACKEND_FILE (backend) || GEGL_IS_TILE_BACKEND_RAM (backend) || GEGL_IS_TILE_BACKEND_TILE_DIR (backend))) gegl_buffer_flush (buffer); gegl_tile_source_reinit (GEGL_TILE_SOURCE (handler->source)); #if 0 g_object_unref (handler->source); handler->source = NULL; /* this might be a dangerous way of marking that we have already voided */ #endif } _gegl_buffer_drop_hot_tile (buffer); G_OBJECT_CLASS (parent_class)->dispose (object); }
static void apply_whirl_pinch (gdouble whirl, gdouble pinch, gdouble radius, gdouble cen_x, gdouble cen_y, Babl *format, GeglBuffer *src, GeglRectangle *in_boundary, GeglBuffer *dst, GeglRectangle *boundary, const GeglRectangle *roi) { gfloat *dst_buf; gint row, col; gdouble scale_x, scale_y; gdouble cx, cy; /* Get buffer in which to place dst pixels. */ dst_buf = g_new0 (gfloat, roi->width * roi->height * 4); whirl = whirl * G_PI / 180; scale_x = 1.0; scale_y = roi->width / (gdouble) roi->height; 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); } /* for */ } /* for */ gegl_buffer_sample_cleanup (src); /* Store dst pixels. */ gegl_buffer_set (dst, roi, format, dst_buf, GEGL_AUTO_ROWSTRIDE); gegl_buffer_flush(dst); g_free (dst_buf); }
/* Apply the actual transform */ static void apply_spread (gint x_amount, gint y_amount, gint img_width, gint img_height, const Babl *format, GeglBuffer *src, GeglBuffer *dst, const GeglRectangle *roi) { gfloat *dst_buf; gint x1, y1; // Noise image gdouble x, y; // Source Image GRand *gr = g_rand_new (); /* Get buffer in which to place dst pixels. */ dst_buf = g_new0 (gfloat, roi->width * roi->height * 4); for (y1 = 0; y1 < roi->height; y1++) { for (x1 = 0; x1 < roi->width; x1++) { 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, NULL, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE); else /* Else just copy it */ gegl_buffer_sample (src, x1, y1, NULL, &dst_buf[(y1 * roi->width + x1) * 4], format, GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE); } /* for */ } /* for */ gegl_buffer_sample_cleanup (src); /* Store dst pixels. */ gegl_buffer_set (dst, roi, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE); gegl_buffer_flush(dst); g_free (dst_buf); g_rand_free (gr); }
static gboolean process (GeglOperation *operation, GeglBuffer *output, const GeglRectangle *result, gint level) { PlasmaContext *context; gint depth; gint x, y; context = g_new (PlasmaContext, 1); context->o = GEGL_CHANT_PROPERTIES (operation); context->output = output; context->buffer = g_malloc (TILE_SIZE * TILE_SIZE * 3 * sizeof (gfloat)); context->using_buffer = FALSE; /* * The first time only puts seed pixels (corners, center of edges, * center of image) */ x = result->x + result->width; y = result->y + result->height; context->gr = g_rand_new_with_seed (context->o->seed); do_plasma (context, result->x, result->y, x-1, y-1, -1, 0); /* * 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)) depth++; gegl_buffer_sample_cleanup (context->output); g_rand_free (context->gr); g_free (context->buffer); g_free (context); return TRUE; }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglChantO *o; GeglRectangle boundary; const Babl *format; FractalType fractal_type; gfloat *dst_buf; gint y; o = GEGL_CHANT_PROPERTIES (operation); boundary = gegl_operation_get_bounding_box (operation); fractal_type = FRACTAL_TYPE_MANDELBROT; if (!strcmp (o->fractal, "mandelbrot")) fractal_type = FRACTAL_TYPE_MANDELBROT; else if (!strcmp(o->fractal, "julia")) fractal_type = FRACTAL_TYPE_JULIA; format = babl_format ("RGBA float"); dst_buf = g_new0 (gfloat, result->width * result->height * 4); for (y = result->y; y < result->y + result->height; y++) fractaltrace (input, &boundary, dst_buf, result, o, y, fractal_type, format); gegl_buffer_set (output, result, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE); g_free (dst_buf); gegl_buffer_sample_cleanup (input); return TRUE; }