int main(int argc, char **argv) { GeglTile *tile; GeglBuffer *buf_a, *buf_b, *buf_small_lin, *buf_big_lin; gpointer shared_data = NULL; gboolean result = TRUE; gpointer scratch_data; GeglRectangle buffer_rect = *GEGL_RECTANGLE(0, 0, 128, 128); gegl_init (&argc, &argv); buf_a = gegl_buffer_new (&buffer_rect, babl_format("RGBA u8")); buf_b = gegl_buffer_new (&buffer_rect, babl_format("RGBA u8")); buf_small_lin = gegl_buffer_linear_new (&buffer_rect, babl_format("RGBA float")); buf_big_lin = gegl_buffer_linear_new (GEGL_RECTANGLE(0, 0, 1024, 1024), babl_format("RGBA float")); tile = gegl_tile_source_get_tile (GEGL_TILE_SOURCE (buf_a), 0, 0, 0); shared_data = gegl_tile_get_data(tile); gegl_tile_unref (tile); if (!assert_is_empty (buf_a, 0, 0, shared_data)) result = FALSE; if (!assert_is_empty (buf_b, 0, 1, shared_data)) result = FALSE; if (!assert_is_empty (buf_a, 0, 0, shared_data)) result = FALSE; if (!assert_is_empty (buf_b, 0, 1, shared_data)) result = FALSE; if (!assert_is_empty (buf_small_lin, 0, 0, shared_data)) result = FALSE; if (!assert_is_unshared (buf_big_lin, 0, 0, shared_data)) result = FALSE; scratch_data = gegl_malloc(4 * buffer_rect.width * buffer_rect.height); gegl_buffer_get (buf_a, &buffer_rect, 1.0, babl_format("RGBA u8"), scratch_data, 0, GEGL_ABYSS_NONE); gegl_buffer_get (buf_b, &buffer_rect, 1.0, babl_format("RGBA u8"), scratch_data, 0, GEGL_ABYSS_NONE); gegl_buffer_get (buf_small_lin, &buffer_rect, 1.0, babl_format("RGBA u8"), scratch_data, 0, GEGL_ABYSS_NONE); gegl_buffer_get (buf_big_lin, &buffer_rect, 1.0, babl_format("RGBA u8"), scratch_data, 0, GEGL_ABYSS_NONE); gegl_free (scratch_data); g_object_unref(buf_a); g_object_unref(buf_b); g_object_unref(buf_small_lin); g_object_unref(buf_big_lin); gegl_exit(); if (result) return SUCCESS; return FAILURE; }
TEST () { GeglBuffer *buffer; GeglRectangle extent = {0,0,40,20}; GeglRectangle roi = {1,1,30,10}; test_start(); buffer = gegl_buffer_linear_new (&extent, babl_format ("Y float")); fill_rect (buffer, &roi, 0.5); roi.y+=3; roi.x+=20; { gint rowstride; gfloat *buf; gint x, y, i; buf = (gpointer)gegl_buffer_linear_open (buffer, &extent, &rowstride, NULL); g_assert (buf); i=0; for (y=0;y<extent.height;y++) for (x=0;x<extent.width;x++) { buf[i++]= ((x+y)*1.0) / extent.width; } gegl_buffer_linear_close (buffer, buf); } fill_rect (buffer, &roi, 0.2); print_buffer (buffer); g_object_unref (buffer); test_end (); }
TEST () { GeglBuffer *buffer; GeglRectangle extent = {0,0,40,20}; GeglRectangle roi = {1,1,30,10}; test_start(); g_print ("foo!\n"); buffer = gegl_buffer_linear_new (&extent, babl_format ("Y float")); fill_rect (buffer, &roi, 0.5); roi.y+=3; roi.x+=20; fill_rect (buffer, &roi, 0.2); print_buffer (buffer); g_object_unref (buffer); test_end (); }
GeglBuffer * gegl_operation_context_get_target (GeglOperationContext *context, const gchar *padname) { GeglBuffer *output; const GeglRectangle *result; const Babl *format; GeglNode *node; GeglOperation *operation; static gint linear_buffers = -1; #if 0 g_return_val_if_fail (GEGL_IS_OPERATION_CONTEXT (context), NULL); #endif if (linear_buffers == -1) linear_buffers = g_getenv ("GEGL_LINEAR_BUFFERS")?1:0; operation = context->operation; node = operation->node; /* <ick */ format = gegl_operation_get_format (operation, padname); if (format == NULL) { g_warning ("no format for %s presuming RGBA float\n", gegl_node_get_debug_name (node)); format = gegl_babl_rgba_linear_float (); } g_assert (format != NULL); g_assert (!strcmp (padname, "output")); result = &context->result_rect; if (result->width == 0 || result->height == 0) { if (linear_buffers) output = gegl_buffer_linear_new (GEGL_RECTANGLE(0, 0, 0, 0), format); else output = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 0, 0), format); } else if (node->dont_cache == FALSE && ! GEGL_OPERATION_CLASS (G_OBJECT_GET_CLASS (operation))->no_cache) { GeglBuffer *cache; cache = GEGL_BUFFER (gegl_node_get_cache (node)); /* Only use the cache if the result is within the cache * extent. This is certainly not optimal. My gut feeling is that * the current caching mechanism needs to be redesigned */ if (gegl_rectangle_contains (gegl_buffer_get_extent (cache), result)) { output = g_object_ref (cache); } else { if (linear_buffers) output = gegl_buffer_linear_new (result, format); else output = gegl_buffer_new (result, format); } } else { if (linear_buffers) output = gegl_buffer_linear_new (result, format); else output = gegl_buffer_new (result, format); } gegl_operation_context_take_object (context, padname, G_OBJECT (output)); return output; }