static void init_path_instrumentation (FishPathInstrumentation *fpi, Babl *fmt_source, Babl *fmt_destination) { long ticks_start = 0; long ticks_end = 0; if (!fpi->fmt_rgba_double) { fpi->fmt_rgba_double = babl_format_new ( babl_model ("RGBA"), babl_type ("double"), babl_component ("R"), babl_component ("G"), babl_component ("B"), babl_component ("A"), NULL); } if (!fpi->test) fpi->test = test_create (); // <- test_create utiliza var static dentro de la función fpi->fish_rgba_to_source = babl_fish_reference (fpi->fmt_rgba_double, fmt_source); fpi->fish_reference = babl_fish_reference (fmt_source, fmt_destination); fpi->fish_destination_to_rgba = babl_fish_reference (fmt_destination, fpi->fmt_rgba_double); fpi->source = babl_calloc (NUM_TEST_PIXELS, fmt_source->format.bytes_per_pixel); fpi->destination = babl_calloc (NUM_TEST_PIXELS, fmt_destination->format.bytes_per_pixel); fpi->ref_destination = babl_calloc (NUM_TEST_PIXELS, fmt_destination->format.bytes_per_pixel); fpi->destination_rgba_double = babl_calloc (NUM_TEST_PIXELS, fpi->fmt_rgba_double->format.bytes_per_pixel); fpi->ref_destination_rgba_double = babl_calloc (NUM_TEST_PIXELS, fpi->fmt_rgba_double->format.bytes_per_pixel); /* create sourcebuffer from testbuffer in the correct format */ babl_process (fpi->fish_rgba_to_source, fpi->test, fpi->source, NUM_TEST_PIXELS); /* calculate the reference buffer of how it should be */ ticks_start = babl_ticks (); babl_process (fpi->fish_reference, fpi->source, fpi->ref_destination, NUM_TEST_PIXELS); ticks_end = babl_ticks (); fpi->reference_cost = babl_process_cost (ticks_start, ticks_end); /* transform the reference destination buffer to RGBA */ babl_process (fpi->fish_destination_to_rgba, fpi->ref_destination, fpi->ref_destination_rgba_double, NUM_TEST_PIXELS); }
gint main (gint argc, gchar **argv) { long ticks; test_start (); gegl_init (&argc, &argv); gegl_exit (); ticks = babl_ticks ()-ticks_start; g_print ("@ %s: %.2f seconds\n", "init", (ticks / 1000000.0)); return 0; }
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; }
long gegl_ticks (void) { return babl_ticks (); }
static void get_path_instrumentation (FishPathInstrumentation *fpi, BablList *path, double *path_cost, double *ref_cost, double *path_error) { long ticks_start = 0; long ticks_end = 0; Babl *babl_source = fpi->source; Babl *babl_destination = fpi->destination; int source_bpp = 0; int dest_bpp = 0; switch (babl_source->instance.class_type) { case BABL_FORMAT: source_bpp = babl_source->format.bytes_per_pixel; break; case BABL_TYPE: source_bpp = babl_source->type.bits / 8; break; default: babl_log ("=eeek{%i}\n", babl_source->instance.class_type - BABL_MAGIC); } switch (babl_destination->instance.class_type) { case BABL_FORMAT: dest_bpp = babl_destination->format.bytes_per_pixel; break; case BABL_TYPE: dest_bpp = babl_destination->type.bits / 8; break; default: babl_log ("-eeek{%i}\n", babl_destination->instance.class_type - BABL_MAGIC); } if (!fpi->init_instrumentation_done) { /* this initialization can be done only once since the * source and destination formats do not change during * the search */ init_path_instrumentation (fpi, babl_source, babl_destination); fpi->init_instrumentation_done = 1; } /* calculate this path's view of what the result should be */ ticks_start = babl_ticks (); process_conversion_path (path, fpi->source, source_bpp, fpi->destination, dest_bpp, NUM_TEST_PIXELS); ticks_end = babl_ticks (); *path_cost = babl_process_cost (ticks_start, ticks_end); /* transform the reference and the actual destination buffers to RGBA * for comparison with each other */ babl_process (fpi->fish_destination_to_rgba, fpi->destination, fpi->destination_rgba_double, NUM_TEST_PIXELS); *path_error = babl_rel_avg_error (fpi->destination_rgba_double, fpi->ref_destination_rgba_double, NUM_TEST_PIXELS * 4); #if 0 fpi->fish_rgba_to_source->fish.processings--; fpi->fish_reference->fish.processings--; fpi->fish_destination_to_rgba->fish.processings -= 2; fpi->fish_rgba_to_source->fish.pixels -= NUM_TEST_PIXELS; fpi->fish_reference->fish.pixels -= NUM_TEST_PIXELS; fpi->fish_destination_to_rgba->fish.pixels -= 2 * NUM_TEST_PIXELS; #endif *ref_cost = fpi->reference_cost; }