static int each_conv (Babl *babl, void *data) { double error, cost; if (BABL (babl->conversion.source)->class_type != BABL_FORMAT) return 0; error = babl_conversion_error (&babl->conversion); cost = babl_conversion_cost (&babl->conversion); if (error > legal_error ()) { fprintf (output_file, "<dt style='background-color: #fcc;'>%s</dt>", babl->instance.name); fprintf (output_file, "<dd style='background-color: #fcc;'>"); } else { fprintf (output_file, "<dt>%s</dt><dd>", babl->instance.name); } fprintf (output_file, "<em>error:</em> %f <em>cost:</em> %4.0f <em>processings:</em> %i <em>pixels:</em> %li", error, cost, babl->conversion.processings, babl->conversion.pixels); fprintf (output_file, "</dd>"); return 0; }
static void get_conversion_path (PathContext *pc, Babl *current_format, int current_length, int max_length) { if (current_length > max_length) { /* We have reached the maximum recursion * depth, let's bail out */ return; } else if ((current_length > 0) && (current_format == pc->to_format)) { /* We have found a candidate path, let's * see about it's properties */ double path_cost = 0.0; double ref_cost = 0.0; double path_error = 1.0; int i; for (i = 0; i < babl_list_size (pc->current_path); i++) { path_error *= (1.0 + babl_conversion_error ((BablConversion *) pc->current_path->items[i])); } if (path_error - 1.0 <= legal_error ()) /* check this before the next; which does a more accurate measurement of the error */ { FishPathInstrumentation fpi; memset (&fpi, 0, sizeof (fpi)); fpi.source = (Babl*) babl_list_get_first (pc->current_path)->conversion.source; fpi.destination = pc->to_format; get_path_instrumentation (&fpi, pc->current_path, &path_cost, &ref_cost, &path_error); if ((path_cost < ref_cost) && /* do not use paths that took longer to compute than reference */ (path_cost < pc->fish_path->fish_path.cost) && (path_error <= legal_error ())) { /* We have found the best path so far, * let's copy it into our new fish */ pc->fish_path->fish_path.cost = path_cost; pc->fish_path->fish.error = path_error; babl_list_copy (pc->current_path, pc->fish_path->fish_path.conversion_list); } destroy_path_instrumentation (&fpi); } } else { /* * Bummer, we have to search deeper... */ BablList *list; int i; list = current_format->format.from_list; if (list) { /* Mark the current format in conversion path as visited */ current_format->format.visited = 1; /* Iterate through unvisited formats from the current format ...*/ for (i = 0; i < babl_list_size (list); i++) { Babl *next_conversion = BABL (list->items[i]); Babl *next_format = BABL (next_conversion->conversion.destination); if (!next_format->format.visited) { /* next_format is not in the current path, we can pay a visit */ babl_list_insert_last (pc->current_path, next_conversion); get_conversion_path (pc, next_format, current_length + 1, max_length); babl_list_remove_last (pc->current_path); } } /* Remove the current format from current path */ current_format->format.visited = 0; } } }