int main(int argc, char *argv[]) { GeglRectangle expected_infinite_plane = gegl_rectangle_infinite_plane (); GeglRectangle infinite_plane = { INFINITE_PLANE }; int result = SUCCESS; int i = 0; /* Make sure our representation of an infinite plane GeglRectangle * is correct */ if (! gegl_rectangle_equal (&infinite_plane, &expected_infinite_plane)) { result = FAILURE; g_printerr("This test case and GEGL does not represent an infinite plane\n" "GeglRectangle in the same way, update this test case. Aborting.\n"); goto abort; } for (i = 0; i < G_N_ELEMENTS (tests); i++) { GeglRectangle result_rect; gboolean return_value; /* gegl_rectangle_bounding_box() */ gegl_rectangle_bounding_box (&result_rect, &tests[i].rect1, &tests[i].rect2); if (! gegl_rectangle_equal (&result_rect, &tests[i].bounding_box_result)) { result = FAILURE; g_printerr("The gegl_rectangle_bounding_box() test #%d failed. Aborting.\n", i + 1); goto abort; } /* gegl_rectangle_intersect() */ return_value = gegl_rectangle_intersect (&result_rect, &tests[i].rect1, &tests[i].rect2); if (! gegl_rectangle_equal (&result_rect, &tests[i].intersect_result) || return_value != tests[i].intersect_return_value) { result = FAILURE; g_printerr("The gegl_rectangle_intersect() test #%d failed. Aborting.\n", i + 1); goto abort; } /* gegl_rectangle_contains() */ return_value = gegl_rectangle_contains (&tests[i].rect1, &tests[i].rect2); if (return_value != tests[i].contains_return_value) { result = FAILURE; g_printerr("The gegl_rectangle_contains() test #%d failed. Aborting.\n", i + 1); goto abort; } } abort: return result; }
static gboolean test_opacity_common (const Babl *in_format, const Babl *out_format) { /* Validate that gegl:opacity produces out_format when given in_format */ gboolean result = TRUE; GeglNode *ptn, *src, *opacity, *sink; GeglBuffer *src_buffer; GeglBuffer *sink_buffer = NULL; src_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 10, 10), in_format); ptn = gegl_node_new (); src = gegl_node_new_child (ptn, "operation", "gegl:buffer-source", "buffer", src_buffer, NULL); opacity = gegl_node_new_child (ptn, "operation", "gegl:opacity", "value", 0.5, NULL); sink = gegl_node_new_child (ptn, "operation", "gegl:buffer-sink", "buffer", &sink_buffer, "format", NULL, NULL); gegl_node_link_many (src, opacity, sink, NULL); gegl_node_blit_buffer (sink, NULL, NULL, 0, GEGL_ABYSS_NONE); if (out_format != gegl_buffer_get_format (sink_buffer)) { printf ("Got %s expected %s\n", babl_get_name (gegl_buffer_get_format (sink_buffer)), babl_get_name (out_format)); result = FALSE; } if (!gegl_rectangle_equal (gegl_buffer_get_extent (src_buffer), gegl_buffer_get_extent (sink_buffer))) result = FALSE; g_object_unref (ptn); g_object_unref (src_buffer); g_object_unref (sink_buffer); return result; }
static void photos_operation_insta_hefe_prepare (GeglOperation *operation) { PhotosOperationInstaHefe *self = PHOTOS_OPERATION_INSTA_HEFE (operation); GeglRectangle bbox; bbox = gegl_node_get_bounding_box (self->input); if (!gegl_rectangle_equal (&self->bbox, &bbox)) { self->bbox = bbox; photos_operation_insta_hefe_setup (self); } }
void gimp_applicator_set_crop (GimpApplicator *applicator, const GeglRectangle *rect) { g_return_if_fail (GIMP_IS_APPLICATOR (applicator)); if (applicator->crop_enabled != (rect != NULL) || (rect && ! gegl_rectangle_equal (&applicator->crop_rect, rect))) { if (rect) { if (! applicator->crop_enabled) { gegl_node_set (applicator->crop_node, "operation", "gimp:compose-crop", "x", rect->x, "y", rect->y, "width", rect->width, "height", rect->height, NULL); gegl_node_connect_to (applicator->input_node, "output", applicator->crop_node, "aux"); } else { gegl_node_set (applicator->crop_node, "x", rect->x, "y", rect->y, "width", rect->width, "height", rect->height, NULL); } applicator->crop_enabled = TRUE; applicator->crop_rect = *rect; } else { gegl_node_disconnect (applicator->crop_node, "aux"); gegl_node_set (applicator->crop_node, "operation", "gegl:nop", NULL); applicator->crop_enabled = FALSE; } } }
cl_mem gegl_buffer_cl_cache_get (GeglBuffer *buffer, const GeglRectangle *roi) { GList *elem; for (elem=cache_entries; elem; elem=elem->next) { CacheEntry *e = elem->data; if (e->valid && e->buffer == buffer && gegl_rectangle_equal (&e->roi, roi)) { e->used ++; return e->tex; } } return NULL; }
static gboolean test_buffer_sink_001 (void) { /* Validate that gegl:buffer-sink doesn't modify the format of its input */ gboolean result = TRUE; GeglNode *ptn, *src, *sink; GeglBuffer *src_buffer; GeglBuffer *sink_buffer = NULL; src_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, 10, 10), babl_format ("RGB u8")); ptn = gegl_node_new (); src = gegl_node_new_child (ptn, "operation", "gegl:buffer-source", "buffer", src_buffer, NULL); sink = gegl_node_new_child (ptn, "operation", "gegl:buffer-sink", "buffer", &sink_buffer, "format", NULL, NULL); gegl_node_link_many (src, sink, NULL); gegl_node_blit_buffer (sink, NULL, NULL, 0, GEGL_ABYSS_NONE); if (gegl_buffer_get_format (src_buffer) != gegl_buffer_get_format (sink_buffer)) result = FALSE; if (!gegl_rectangle_equal (gegl_buffer_get_extent (src_buffer), gegl_buffer_get_extent (sink_buffer))) result = FALSE; g_object_unref (ptn); g_object_unref (src_buffer); g_object_unref (sink_buffer); return result; }
static gboolean gimp_channel_combine_start (GimpChannel *mask, GimpChannelOps op, const GeglRectangle *rect, gboolean full_extent, gboolean full_value, GimpChannelCombineData *data) { GeglBuffer *buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)); GeglRectangle extent; gboolean intersects; extent.x = 0; extent.y = 0; extent.width = gimp_item_get_width (GIMP_ITEM (mask)); extent.height = gimp_item_get_height (GIMP_ITEM (mask)); intersects = gegl_rectangle_intersect (&data->rect, rect, &extent); data->bounds_known = mask->bounds_known; data->empty = mask->empty; data->bounds.x = mask->x1; data->bounds.y = mask->y1; data->bounds.width = mask->x2 - mask->x1; data->bounds.height = mask->y2 - mask->y1; gegl_buffer_freeze_changed (buffer); /* Determine new boundary */ switch (op) { case GIMP_CHANNEL_OP_REPLACE: gimp_channel_combine_clear (mask, NULL); if (! intersects) { data->bounds_known = TRUE; data->empty = TRUE; return FALSE; } data->bounds_known = FALSE; if (full_extent) { data->bounds_known = TRUE; data->empty = FALSE; data->bounds = data->rect; } break; case GIMP_CHANNEL_OP_ADD: if (! intersects) return FALSE; data->bounds_known = FALSE; if (full_extent && (mask->bounds_known || gegl_rectangle_equal (&data->rect, &extent))) { data->bounds_known = TRUE; data->empty = FALSE; if (mask->bounds_known && ! mask->empty) { gegl_rectangle_bounding_box (&data->bounds, &data->bounds, &data->rect); } else { data->bounds = data->rect; } } break; case GIMP_CHANNEL_OP_SUBTRACT: if (intersects && mask->bounds_known) { if (mask->empty) { intersects = FALSE; } else { intersects = gegl_rectangle_intersect (&data->rect, &data->rect, &data->bounds); } } if (! intersects) return FALSE; if (full_value && gegl_rectangle_contains (&data->rect, mask->bounds_known ? &data->bounds : &extent)) { gimp_channel_combine_clear (mask, NULL); data->bounds_known = TRUE; data->empty = TRUE; return FALSE; } data->bounds_known = FALSE; gegl_buffer_set_abyss (buffer, &data->rect); break; case GIMP_CHANNEL_OP_INTERSECT: if (intersects && mask->bounds_known) { if (mask->empty) { intersects = FALSE; } else { intersects = gegl_rectangle_intersect (&data->rect, &data->rect, &data->bounds); } } if (! intersects) { gimp_channel_combine_clear (mask, NULL); data->bounds_known = TRUE; data->empty = TRUE; return FALSE; } if (full_value && mask->bounds_known && gegl_rectangle_contains (&data->rect, &data->bounds)) { return FALSE; } data->bounds_known = FALSE; gimp_channel_combine_clear_complement (mask, &data->rect); gegl_buffer_set_abyss (buffer, &data->rect); break; } return TRUE; }
static gboolean test_buffer_change_extent (void) { gboolean result = TRUE; gchar *tmpdir = NULL; gchar *buf_a_path = NULL; GeglBuffer *buf_a = NULL; const Babl *format = babl_format ("R'G'B'A u8"); GeglRectangle roi = {0, 0, 128, 128}; GeglRectangle roi2 = {0, 0, 64, 64}; tmpdir = g_dir_make_tmp ("test-backend-file-XXXXXX", NULL); g_return_val_if_fail (tmpdir, FALSE); buf_a_path = g_build_filename (tmpdir, "buf_a.gegl", NULL); buf_a = g_object_new (GEGL_TYPE_BUFFER, "format", format, "path", buf_a_path, "x", roi.x, "y", roi.y, "width", roi.width, "height", roi.height, NULL); gegl_buffer_flush (buf_a); g_object_unref (buf_a); buf_a = g_object_new (GEGL_TYPE_BUFFER, "format", babl_format ("RGBA u16"), "path", buf_a_path, NULL); if (!gegl_rectangle_equal (gegl_buffer_get_extent (buf_a), &roi)) { printf ("Extent does not match:\n"); gegl_rectangle_dump (gegl_buffer_get_extent (buf_a)); gegl_rectangle_dump (&roi); result = FALSE; } gegl_buffer_set_extent (buf_a, &roi2); gegl_buffer_flush (buf_a); g_object_unref (buf_a); buf_a = g_object_new (GEGL_TYPE_BUFFER, "format", babl_format ("RGBA u16"), "path", buf_a_path, NULL); if (!gegl_rectangle_equal (gegl_buffer_get_extent (buf_a), &roi2)) { printf ("Extent does not match:\n"); gegl_rectangle_dump (gegl_buffer_get_extent (buf_a)); gegl_rectangle_dump (&roi2); result = FALSE; } g_object_unref (buf_a); g_unlink (buf_a_path); g_remove (tmpdir); g_free (tmpdir); g_free (buf_a_path); return result; }
static gboolean test_buffer_same_path (void) { gboolean result = TRUE; gchar *tmpdir = NULL; gchar *buf_a_path = NULL; GeglBuffer *buf_a = NULL; const Babl *format = babl_format ("R'G'B'A u8"); GeglRectangle roi = {0, 0, 128, 128}; tmpdir = g_dir_make_tmp ("test-backend-file-XXXXXX", NULL); g_return_val_if_fail (tmpdir, FALSE); buf_a_path = g_build_filename (tmpdir, "buf_a.gegl", NULL); buf_a = g_object_new (GEGL_TYPE_BUFFER, "format", format, "path", buf_a_path, "x", roi.x, "y", roi.y, "width", roi.width, "height", roi.height, NULL); gegl_buffer_flush (buf_a); g_object_unref (buf_a); buf_a = g_object_new (GEGL_TYPE_BUFFER, /* FIXME: Currently the buffer must always have a format specified */ "format", babl_format ("RGBA u16"), "path", buf_a_path, NULL); if (!GEGL_IS_BUFFER (buf_a)) { printf ("Failed to load file:%s\n", buf_a_path); result = FALSE; } if (!gegl_rectangle_equal (gegl_buffer_get_extent (buf_a), &roi)) { printf ("Extent does not match:\n"); gegl_rectangle_dump (gegl_buffer_get_extent (buf_a)); gegl_rectangle_dump (&roi); result = FALSE; } if (gegl_buffer_get_format (buf_a) != format) { printf ("Formats do not match:\n%s\n%s\n", babl_get_name (gegl_buffer_get_format (buf_a)), babl_get_name (format)); result = FALSE; } g_object_unref (buf_a); g_unlink (buf_a_path); g_remove (tmpdir); g_free (tmpdir); g_free (buf_a_path); return result; }