static BablPalette * default_palette (void) { static BablPalette pal; static int inited = 0; babl_mutex_lock (babl_format_mutex); if (inited) { babl_mutex_unlock (babl_format_mutex); return &pal; } init_ceil_sqrt_u8 (); memset (&pal, 0, sizeof (pal)); pal.count = 16; pal.format = babl_format ("R'G'B'A u8"); /* dynamically generated, so the default palette can not be fully static. */ pal.data = defpal_data; pal.data_double = defpal_double; pal.data_u8 = defpal_data; pal.radii = defpal_radii; babl_process (babl_fish (pal.format, babl_format ("RGBA double")), pal.data, pal.data_double, pal.count); babl_palette_init_radii (&pal); babl_palette_reset_hash (&pal); inited = 1; babl_mutex_unlock (babl_format_mutex); return &pal; }
Babl * babl_fish_path (const Babl *source, const Babl *destination) { Babl *babl = NULL; char name[BABL_MAX_NAME_LEN]; create_name (name, source, destination, 1); babl = babl_db_exist_by_name (babl_fish_db (), name); if (babl) { /* There is an instance already registered by the required name, * returning the preexistent one instead. */ return babl; } babl = babl_calloc (1, sizeof (BablFishPath) + strlen (name) + 1); babl_set_destructor (babl, babl_fish_path_destroy); babl->class_type = BABL_FISH_PATH; babl->instance.id = babl_fish_get_id (source, destination); babl->instance.name = ((char *) babl) + sizeof (BablFishPath); strcpy (babl->instance.name, name); babl->fish.source = source; babl->fish.destination = destination; babl->fish.processings = 0; babl->fish.pixels = 0; babl->fish.error = BABL_MAX_COST_VALUE; babl->fish_path.cost = BABL_MAX_COST_VALUE; babl->fish_path.loss = BABL_MAX_COST_VALUE; babl->fish_path.conversion_list = babl_list_init_with_size (BABL_HARD_MAX_PATH_LENGTH); { PathContext pc; pc.current_path = babl_list_init_with_size (BABL_HARD_MAX_PATH_LENGTH); pc.fish_path = babl; pc.to_format = (Babl *) destination; if (babl_in_fish_path <= 0) babl_mutex_lock (babl_format_mutex); /* we hold a global lock whilerunning get_conversion_path since * it depends on keeping the various format.visited members in * a consistent state, this code path is not performance critical * since created fishes are cached. */ babl_in_fish_path++; get_conversion_path (&pc, (Babl *) source, 0, max_path_length ()); babl_in_fish_path--; if (babl_in_fish_path <= 0) babl_mutex_unlock (babl_format_mutex); babl_free (pc.current_path); } if (babl_list_size (babl->fish_path.conversion_list) == 0) { babl_free (babl); return NULL; } /* Since there is not an already registered instance by the required * name, inserting newly created class into database. */ babl_db_insert (babl_fish_db (), babl); return babl; }