/** * gegl_graph_prepare: * @path: The traversal path * * Prepare all nodes, initializing their output formats and have rects. */ void gegl_graph_prepare (GeglGraphTraversal *path) { GList *list_iter = NULL; for (list_iter = path->dfs_path; list_iter; list_iter = list_iter->next) { GeglNode *node = GEGL_NODE (list_iter->data); GeglOperation *operation = node->operation; g_mutex_lock (&node->mutex); gegl_operation_prepare (operation); node->have_rect = gegl_operation_get_bounding_box (operation); node->valid_have_rect = TRUE; if (node->cache) { gegl_buffer_set_extent (GEGL_BUFFER (node->cache), &node->have_rect); } g_mutex_unlock (&node->mutex); if (!g_hash_table_contains (path->contexts, node)) { GeglOperationContext *context = gegl_operation_context_new (node->operation); g_hash_table_insert (path->contexts, node, context); } } }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); WarpPrivate *priv = (WarpPrivate*) o->chant_data; gdouble dist; gdouble stamps; gdouble spacing = MAX (o->size * 0.01, 0.5); /*1% spacing for starters*/ GeglPathPoint prev, next, lerp; gulong i; GeglPathList *event; priv->buffer = gegl_buffer_dup (input); event = gegl_path_get_path (o->stroke); prev = *(event->d.point); while (event->next) { event = event->next; next = *(event->d.point); dist = gegl_path_point_dist (&next, &prev); stamps = dist / spacing; if (stamps < 1) { stamp (o, result, next.x, next.y); prev = next; } else { for (i = 0; i < stamps; i++) { gegl_path_point_lerp (&lerp, &prev, &next, (i * spacing) / dist); stamp (o, result, lerp.x, lerp.y); } prev = lerp; } } /* Affect the output buffer */ gegl_buffer_copy (priv->buffer, result, output, result); gegl_buffer_set_extent (output, gegl_buffer_get_extent (input)); g_object_unref (priv->buffer); /* prepare for the recomputing of the op */ priv->last_point_set = FALSE; return TRUE; }
static void tile_request_start(MyPaintTiledSurface *tiled_surface, MyPaintTileRequest *request) { MyPaintGeglTiledSurface *self = (MyPaintGeglTiledSurface *)tiled_surface; const int tile_size = tiled_surface->tile_size; GeglRectangle tile_bbox; gegl_rectangle_set(&tile_bbox, request->tx * tile_size, request->ty * tile_size, tile_size, tile_size); int read_write_flags; if (request->readonly) { read_write_flags = GEGL_BUFFER_READ; } else { read_write_flags = GEGL_BUFFER_READWRITE; // Extend the bounding box gegl_rectangle_bounding_box(&self->extent_rect, &self->extent_rect, &tile_bbox); gboolean success = gegl_buffer_set_extent(self->buffer, &self->extent_rect); g_assert(success); } if (buffer_is_native(self)) { GeglBufferIterator *iterator = gegl_buffer_iterator_new(self->buffer, &tile_bbox, 0, self->format, read_write_flags, GEGL_ABYSS_NONE); // Read out gboolean completed = gegl_buffer_iterator_next(iterator); g_assert(completed); if (iterator->length != tile_size*tile_size) { g_critical("Unable to get tile aligned access to GeglBuffer"); request->buffer = NULL; } else { request->buffer = (uint16_t *)(iterator->data[0]); } // So we can finish the iterator in tile_request_end() request->context = (void *)iterator; } else { // Extract a linear rectangular chunk of appropriate BablFormat, // potentially triggering copying and color conversions request->buffer = alloc_for_format(self->format, tile_size*tile_size); gegl_buffer_get(self->buffer, &tile_bbox, 1, self->format, request->buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); g_assert(request->buffer); } }
TEST () { GeglBuffer *buffer; GeglRectangle orig_extent = {0, 0, 20, 20}; GeglRectangle new_extent = {0, 0, 50, 50}; test_start (); buffer = gegl_buffer_new(&orig_extent, babl_format ("Y float")); gegl_buffer_set_extent(buffer, &new_extent); fill (buffer, 0.5); print_buffer (buffer); g_object_unref (buffer); test_end (); }
gint main (gint argc, gchar **argv) { GeglRectangle terrain_rect; if (argc < 2) usage(); gegl_init (&argc, &argv); parse_args (argc, argv); gegl_decode = gegl_node_new (); store = gegl_node_new_child (gegl_decode, "operation", "gegl:buffer-sink", "buffer", &video_frame, NULL); load = gegl_node_new_child (gegl_decode, "operation", "gegl:ff-load", "frame", 0, "path", video_path, NULL); gegl_node_link_many (load, store, NULL); decode_frame_no (0); /* we issue a processing/decoding of a frame - to get metadata */ { gegl_node_get (load, "frame-rate", &frame_rate, NULL); total_frames = 0; gegl_node_get (load, "frames", &total_frames, NULL); if (frame_end == 0) frame_end = total_frames; } if (horizontal) terrain_rect = (GeglRectangle){0, 0, frame_end - frame_start + 1, 1024}; else terrain_rect = (GeglRectangle){0, 0, 1024, frame_end - frame_start + 1}; if (input_analysis_path && g_file_test (input_analysis_path, G_FILE_TEST_IS_REGULAR)) { GeglNode *load_graph = gegl_node_new (); GeglNode *load = gegl_node_new_child (load_graph, "operation", "gegl:load", "path", input_analysis_path, NULL); GeglNode *store = gegl_node_new_child (load_graph, "operation", "gegl:buffer-sink", "buffer", &terrain, NULL); gegl_node_link_many (load, store, NULL); gegl_node_process (store); g_object_unref (load_graph); frame_end = frame_start + gegl_buffer_get_extent (terrain)->height; /* the last frame aavilavle for analysis is the last one loaded rom cache,.. perhaps with some timeout */ } else { terrain = gegl_buffer_new (&terrain_rect, babl_format ("RGBA u8")); { gint frame; gint max_buf_pos = 0; for (frame = frame_start; frame <= frame_end; frame++) { FrameInfo info = {{0}}; uint8_t buffer[4096] = {0,}; int buffer_pos = 0; GeglRectangle terrain_row; char *p = format; GString *word = g_string_new (""); if (show_progress) { double percent_full = 100.0 * (frame-frame_start) / (frame_end-frame_start); double percent_time = time_out?100.0 * babl_ticks()/1000.0/1000.0 / time_out:0.0; fprintf (stdout, "\r%2.1f%% %i/%i (%i)", percent_full>percent_time?percent_full:percent_time, frame-frame_start, frame_end-frame_start, frame); fflush (stdout); } if (horizontal) terrain_row = (GeglRectangle){frame-frame_start, 0, 1, 1024}; else terrain_row = (GeglRectangle){0, frame-frame_start, 1024, 1}; decode_frame_no (frame); //for (int i=0;i<(signed)sizeof(buffer);i++)buffer[i]=0; while (*p == ' ') p++; for (p= format;p==format || p[-1]!='\0';p++) { if (*p != '\0' && *p != ' ') { g_string_append_c (word, *p); } else { if (!strcmp (word->str, "histogram")) { record_pix_stats (video_frame, previous_video_frame, &(info.rgb_hist[0]), &(info.rgb_square_diff)[0]); for (int i = 0; i < NEGL_RGB_HIST_SLOTS; i++) { buffer[buffer_pos] = info.rgb_hist[i]; buffer_pos++; } for (int i = 0; i < 3; i++) { buffer[buffer_pos] = info.rgb_square_diff[i]; buffer_pos++; } } else if (!strcmp (word->str, "mid-row")) { int samples = NEGL_RGB_HEIGHT; if (p[1] >= '0' && p[1] <= '9') { samples = g_strtod (&p[1], &p); } buffer_pos += extract_mid_row (video_frame, &(buffer)[buffer_pos], samples); } else if (!strcmp (word->str, "mid-col")) { int samples = NEGL_RGB_HEIGHT; if (p[1] >= '0' && p[1] <= '9') { samples = g_strtod (&p[1], &p); } buffer_pos += extract_mid_col (video_frame, &(buffer)[buffer_pos], samples); } else if (!strcmp (word->str, "thumb")) { int samples = NEGL_RGB_THEIGHT; int samples2; if (p[1] >= '0' && p[1] <= '9') { samples = g_strtod (&p[1], &p); } if (horizontal) samples2 = samples * gegl_buffer_get_width (video_frame)/gegl_buffer_get_height(video_frame); else samples2 = samples * gegl_buffer_get_height (video_frame)/gegl_buffer_get_width(video_frame); buffer_pos += extract_thumb (video_frame, &(buffer)[buffer_pos], samples, samples2); } else if (!strcmp (word->str, "audio")) { int dups = 1; GeglAudioFragment *audio = NULL; if (p[1] >= '0' && p[1] <= '9') { dups = g_strtod (&p[1], &p); } gegl_node_get (load, "audio", &audio, NULL); if (audio) { extract_audio_energy (audio, &buffer[buffer_pos], dups); g_object_unref (audio); } buffer_pos+=3 * dups; } g_string_assign (word, ""); } } max_buf_pos = buffer_pos; g_string_free (word, TRUE); gegl_buffer_set (terrain, &terrain_row, 0, babl_format("RGB u8"), buffer, GEGL_AUTO_ROWSTRIDE); if (time_out > 1.0 && babl_ticks()/1000.0/1000.0 > time_out) { frame_end = frame; if (horizontal) terrain_rect.width = frame_end - frame_start + 1; else terrain_rect.height = frame_end - frame_start + 1; // gegl_buffer_set_extent (terrain, &terrain_rect); } if (horizontal) terrain_rect.height = max_buf_pos/3; else terrain_rect.width = max_buf_pos/3; gegl_buffer_set_extent (terrain, &terrain_rect); } if (show_progress) { fprintf (stdout, "\n"); fflush (stdout); } } if (output_analysis_path) { GeglNode *save_graph = gegl_node_new (); GeglNode *readbuf = gegl_node_new_child (save_graph, "operation", "gegl:buffer-source", "buffer", terrain, NULL); GeglNode *save = gegl_node_new_child (save_graph, "operation", "gegl:png-save", "path", output_analysis_path, NULL); gegl_node_link_many (readbuf, save, NULL); gegl_node_process (save); g_object_unref (save_graph); } } if (thumb_path) { GeglNode *save_graph = gegl_node_new (); find_best_thumb (); if (frame_thumb != 0) decode_frame_no (frame_thumb-1); decode_frame_no (frame_thumb); { GeglNode *readbuf = gegl_node_new_child (save_graph, "operation", "gegl:buffer-source", "buffer", video_frame, NULL); GeglNode *save = gegl_node_new_child (save_graph, "operation", "gegl:png-save", "path", thumb_path, NULL); gegl_node_link_many (readbuf, save, NULL); gegl_node_process (save); g_object_unref (save_graph); } } if (video_frame) g_object_unref (video_frame); video_frame = NULL; if (previous_video_frame) g_object_unref (previous_video_frame); previous_video_frame = NULL; if (terrain) g_object_unref (terrain); terrain = NULL; g_object_unref (gegl_decode); gegl_exit (); return 0; }
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; }