$NetBSD: patch-ad,v 1.2 2005/07/04 19:57:01 drochner Exp $

--- app/cms.c.orig	2005-05-24 20:51:25.000000000 +0200
+++ app/cms.c
@@ -208,7 +208,12 @@ erase_alpha_from_4th_color (CMSTransform
  * called from app_procs.c:app_init()
  */
 void cms_init()
-{   profile_cache = g_hash_table_new(g_str_hash, g_str_equal);
+{
+    GList *remove_settings = NULL;
+    GList *update_settings = NULL;
+    cmsHPROFILE test = NULL;
+
+    profile_cache = g_hash_table_new(g_str_hash, g_str_equal);
     transform_cache = g_hash_table_new(g_str_hash, g_str_equal);         
     profile_info_buffer = g_new(CMSProfileInfo, 1);
     profile_info_buffer->manufacturer = NULL;
@@ -222,9 +227,6 @@ void cms_init()
     /* suppress lcms errors while checking */
     cmsErrorAction(LCMS_ERROR_IGNORE);     
 
-    GList *remove_settings = NULL;
-    GList *update_settings = NULL;
-    cmsHPROFILE test = NULL;
 
     /* 1. image profile */
     if (cms_default_image_profile_name != NULL)
@@ -525,11 +527,12 @@ cms_read_icc_profile_dir(gchar *path, ic
     while ((entry = readdir (dir)))
     {   char *file_name = entry->d_name;
         cmsHPROFILE profile;
+	GString *file_path;
 	if ((strcmp (file_name, "..") == 0) || (strcmp (file_name, ".") == 0)) 
 	{   continue;
 	}
 
-	GString *file_path = g_string_new(NULL);
+	file_path = g_string_new(NULL);
 	g_string_sprintf (file_path, "%s/%s", path, file_name);
 
 	/* Open the file and try to read it using the lcms library
@@ -566,6 +569,7 @@ cms_read_standard_profile_dirs(icProfile
     const char *home = GetDirHome();
     char *directories = g_strdup(cms_profile_path);
     GString *file_path = g_string_new(NULL);
+    GSList *sub_list;
 
     /* process path by path, paths are separated by : */
     char *remaining_directories = directories;    
@@ -580,7 +584,7 @@ cms_read_standard_profile_dirs(icProfile
         {   path = strdup(token);
 	} 
 
-	GSList *sub_list = cms_read_icc_profile_dir(path, class);
+	sub_list = cms_read_icc_profile_dir(path, class);
 	return_list = g_slist_concat(return_list, sub_list);
 
 	g_free(path);
@@ -729,6 +733,7 @@ cms_load_profile_to_mem (char* filename,
 CMSProfile *
 cms_get_profile_from_file(char *file_name)
 {   CMSProfile *return_value;
+    ProfileCacheEntry *cache_entry;
     size_t size_order = 128;
     char *mem = 0;
     const char *keyname = 0; 
@@ -743,7 +748,7 @@ cms_get_profile_from_file(char *file_nam
     keyname = cms_get_profile_keyname (profile, mem);
  
     /* check hash table for profile */ 
-    ProfileCacheEntry *cache_entry = g_hash_table_lookup(profile_cache, 
+    cache_entry = g_hash_table_lookup(profile_cache, 
 							 (gpointer) cms_get_profile_keyname(profile,mem));
     if (cache_entry != NULL) 
     {   cache_entry->ref_count ++;
@@ -783,7 +788,8 @@ cms_get_profile_from_file(char *file_nam
 CMSProfile *
 cms_get_profile_from_mem(void *mem_pointer, DWORD size)
 {   CMSProfile *return_value;
-    
+    ProfileCacheEntry *cache_entry;
+
     /* get profile information */ 
     cmsHPROFILE profile = cmsOpenProfileFromMem (mem_pointer, size);
     if (profile == NULL)
@@ -792,7 +798,7 @@ cms_get_profile_from_mem(void *mem_point
     }   
 
     /* check hash table for profile */ 
-    ProfileCacheEntry *cache_entry = g_hash_table_lookup(profile_cache, 
+    cache_entry = g_hash_table_lookup(profile_cache, 
 							 (gpointer) cms_get_profile_keyname(profile,mem_pointer));
     if (cache_entry != NULL) 
     {   cache_entry->ref_count ++;
@@ -852,6 +858,7 @@ cms_get_profile_data(CMSProfile *profile
 CMSProfile *
 cms_get_lab_profile(LPcmsCIExyY white_point) 
 {   CMSProfile *return_value;
+    ProfileCacheEntry *cache_entry;
 
     GString *hash_key = g_string_new(NULL); 
     if (white_point) 
@@ -861,7 +868,7 @@ cms_get_lab_profile(LPcmsCIExyY white_po
     {   g_string_sprintf(hash_key, "###LAB###");
     }
 
-    ProfileCacheEntry *cache_entry = g_hash_table_lookup(profile_cache, (gpointer) hash_key);
+    cache_entry = g_hash_table_lookup(profile_cache, (gpointer) hash_key);
     if (cache_entry != NULL) 
     {   cache_entry->ref_count ++;
         return_value = cache_entry->profile;
@@ -1034,12 +1041,13 @@ cms_return_profile(CMSProfile *profile)
 {   /* search the cache for the profile 
      * decreate ref_counter + possibly close profile 
      */  
+    ProfileCacheEntry *entry;
     if (profile == NULL)
     {   g_warning("cms_return_profile: profile is NULL");
         return FALSE;
     } 
 
-    ProfileCacheEntry *entry = g_hash_table_lookup(profile_cache, (gpointer)profile->cache_key);
+    entry = g_hash_table_lookup(profile_cache, (gpointer)profile->cache_key);
     if (entry == NULL)
     {   g_warning("cms_return_profile: profile not found in cache");
         return FALSE;
@@ -1072,7 +1080,18 @@ cms_get_transform(GSList *profiles,
 {   /* turn profiles into an array as needed by lcms + 
        check all profiles are registered with the profile cache + 
        create hash key to check transform cache */
+
+    int i;
+    GString *hash_key;
+    CMSProfile *current_profile;
+    GSList *iterator;
+    TransformCacheEntry *cache_entry;
+    cmsHTRANSFORM transform;
+    cmsHPROFILE devicelink;
+    char *file_name;
+
     int num_profiles = g_slist_length(profiles);
+    cmsHPROFILE profile_array[num_profiles];
     if (num_profiles == 0)
     {   g_warning("cms_get_transform: profile list is empty, cannot create transfrom");
         return NULL;
@@ -1092,12 +1111,9 @@ cms_get_transform(GSList *profiles,
         return NULL;
     }
 
-    cmsHPROFILE profile_array[num_profiles];
-    GString *hash_key = g_string_new(NULL);
+    hash_key = g_string_new(NULL);
 
-    int i;
-    CMSProfile *current_profile;
-    GSList *iterator = profiles;
+    iterator = profiles;
     for (i=0; ((i<num_profiles) && (iterator !=NULL)); i++) 
     {   current_profile = (CMSProfile *)iterator->data;
         if (g_hash_table_lookup(profile_cache, (gpointer)current_profile->cache_key) == NULL) 
@@ -1114,7 +1130,7 @@ cms_get_transform(GSList *profiles,
                                            lcms_intent, lcms_flags);
 
     /* now check the cache */
-    TransformCacheEntry *cache_entry = g_hash_table_lookup(transform_cache, (gpointer) hash_key->str);
+    cache_entry = g_hash_table_lookup(transform_cache, (gpointer) hash_key->str);
 
     /* if it was in the disc cache */
     if (cache_entry != NULL) 
@@ -1143,7 +1159,6 @@ cms_get_transform(GSList *profiles,
     }
 
     /* if no cache hit, create transform */
-    cmsHTRANSFORM transform;
         transform = cmsCreateMultiprofileTransform  (profile_array,
 						     num_profiles,
 						     lcms_input_format,
@@ -1157,8 +1172,8 @@ cms_get_transform(GSList *profiles,
     }							     
 
     /* save it to disk */
-    cmsHPROFILE devicelink = cmsTransform2DeviceLink(transform,0);
-    char *file_name = file_temp_name("icc");
+    devicelink = cmsTransform2DeviceLink(transform,0);
+    file_name = file_temp_name("icc");
     _cmsSaveProfile(devicelink, file_name);
     cmsCloseProfile(devicelink);
 
@@ -1282,6 +1297,12 @@ cms_set_display_profile(CMSProfile *prof
 void 
 cms_transform_area(CMSTransform *transform, PixelArea *src_area, PixelArea *dest_area) 
 {   TransformFunc transform_func;
+    PixelRow src_row_buffer, dest_row_buffer;
+    guint h;
+    void *src_data, *dest_data;
+    guint num_pixels;
+    void *pag;
+    
     Tag src_tag = pixelarea_tag(src_area); 
     Tag dest_tag = pixelarea_tag(dest_area); 
     if (tag_precision(src_tag) != tag_precision(dest_tag)) 
@@ -1309,12 +1330,6 @@ cms_transform_area(CMSTransform *transfo
     }
 
 
-    PixelRow src_row_buffer, dest_row_buffer;
-    guint h;
-    void *src_data, *dest_data;
-    guint num_pixels;
-    void *pag;
-    
     for (pag = pixelarea_register (1, src_area, dest_area);
 	 pag != NULL;
 	 pag = pixelarea_process (pag))
@@ -1385,6 +1400,8 @@ void
 cms_transform_float(CMSTransform *transform, void *src_data, void *dest_data, int num_pixels) 
 {   /* need to convert data to double for lcms's convenience */
     int i;
+    float *src_fbuffer, *dest_fbuffer;
+    double *dbuffer;
     if (!transform || !transform->handle)
         g_warning ("%s:%d %s() transform not allocated\n",
                    __FILE__,__LINE__,__func__);
@@ -1392,9 +1409,9 @@ cms_transform_float(CMSTransform *transf
         g_warning ("%s:%d %s() array not allocated\n",
                    __FILE__,__LINE__,__func__);
 
-    float *src_fbuffer = (float *)src_data;
-    float *dest_fbuffer = (float *)dest_data;
-    double *dbuffer = malloc(sizeof(double) * num_pixels * 4); 
+    src_fbuffer = (float *)src_data;
+    dest_fbuffer = (float *)dest_data;
+    dbuffer = malloc(sizeof(double) * num_pixels * 4); 
     for (i=0; i < num_pixels * 4; i++) 
     {   dbuffer[i]=(double)src_fbuffer[i];
     }
@@ -1463,10 +1480,14 @@ static GtkWidget *cms_profile_menu_new(G
 {   GtkWidget *menu;
     GtkWidget *menuitem;
     GtkWidget *optionmenu;
+
+    gchar *current_filename;
+    CMSProfile *current_profile;
+    CMSProfileInfo *current_profile_info;
        
-    menu = gtk_menu_new (); 
     GSList *profile_file_names = cms_read_standard_profile_dirs(CMS_ANY_PROFILECLASS);      
     GSList *iterator = profile_file_names;
+    menu = gtk_menu_new (); 
 
     if (can_select_none)
     {   menuitem = gtk_menu_item_new_with_label("[none]");
@@ -1474,9 +1495,6 @@ static GtkWidget *cms_profile_menu_new(G
 	gtk_object_set_data(GTK_OBJECT(menuitem), "value", NULL);      
     }
 
-    gchar *current_filename;
-    CMSProfile *current_profile;
-    CMSProfileInfo *current_profile_info;      
     while (iterator != NULL)
     {   current_filename = iterator->data;
         current_profile = cms_get_profile_from_file(current_filename);
@@ -1506,8 +1524,8 @@ static GtkWidget *cms_intent_menu_new(Gt
     GtkWidget *menuitem = NULL;
     GtkWidget *optionmenu = NULL;
       
-    menu = gtk_menu_new ();	 
     guint8 *value = NULL;
+    menu = gtk_menu_new ();	 
 
     menuitem = gtk_menu_item_new_with_label ("Perceptual");
     gtk_menu_append (GTK_MENU (menu), menuitem);
@@ -1685,6 +1703,8 @@ cms_assign_dialog(GImage *image)
     GtkWidget *label = NULL; 
     GtkWidget *vbox = NULL;
     GtkWidget *alignment = NULL;
+    CMSProfile *current_profile;
+    GString *profile_string;
 
     CMSAssignDialogData *data=g_new(CMSAssignDialogData,1); 
     data->image = image;
@@ -1700,8 +1720,8 @@ cms_assign_dialog(GImage *image)
     table = gtk_table_new(3, 1, FALSE);
     gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
     
-    CMSProfile *current_profile = gimage_get_cms_profile(image);
-    GString *profile_string = g_string_new(NULL);
+    current_profile = gimage_get_cms_profile(image);
+    profile_string = g_string_new(NULL);
     
     if (current_profile == NULL)
     {   g_string_sprintf (profile_string, "[The currently assigned profile is: [none]]");
@@ -1792,6 +1812,7 @@ cms_open_assign_dialog(GImage *image)
     GSList *radiogroup = NULL;
     GtkWidget *vbox = NULL;
     GtkWidget *alignment = NULL;
+    GString *profile_string;
 
     CMSOpenAssignDialogData *data=g_new(CMSOpenAssignDialogData,1); 
     data->image = image;
@@ -1821,7 +1842,7 @@ cms_open_assign_dialog(GImage *image)
 						  
     data->profile_menu = cms_profile_menu_new(GTK_TABLE(table), 1, 0, TRUE);
 
-    GString *profile_string = g_string_new(NULL);    
+    profile_string = g_string_new(NULL);    
     if (cms_default_image_profile_name == NULL)
     {   g_string_sprintf (profile_string, "The default image profile: [none]");
     }
@@ -1888,9 +1909,10 @@ cms_open_assign_dialog_ok_callback(GtkWi
     
     /* update cms_open_action (global preference variable) */
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->always_default_check)))
-    {   cms_open_action = CMS_ASSIGN_DEFAULT;
+    {
         GList *update_settings = NULL;
         GList *remove_settings = NULL;
+	cms_open_action = CMS_ASSIGN_DEFAULT;
 	update_settings = g_list_append(update_settings, "cms-open-action");
 	save_gimprc(&update_settings, &remove_settings); 
 	g_list_free(update_settings);
@@ -1939,6 +1961,7 @@ cms_convert_on_open_prompt(GImage *image
     GtkWidget *table;
     GtkWidget *vbox;
     GtkWidget *alignment;
+    gboolean return_value;
 
     CMSConvertOnOpenPromptData *data = g_new(CMSConvertOnOpenPromptData, 1);
 
@@ -2010,7 +2033,7 @@ cms_convert_on_open_prompt(GImage *image
     data->event_loop = g_main_new(FALSE);    
     g_main_run(data->event_loop);
 
-    gboolean return_value = data->return_value;
+    return_value = data->return_value;
     g_main_destroy(data->event_loop);
     g_free(data);
 
@@ -2023,9 +2046,9 @@ cms_convert_on_open_prompt_yes_callback 
 {   data->return_value = TRUE;  
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->auto_convert_check)))
     {   /* cms_auto_convert is global preference variable */
-        cms_mismatch_action = CMS_MISMATCH_AUTO_CONVERT;
         GList *update_settings = NULL;
         GList *remove_settings = NULL;
+        cms_mismatch_action = CMS_MISMATCH_AUTO_CONVERT;
 	update_settings = g_list_append(update_settings, "cms-mismatch-action");
 	save_gimprc(&update_settings, &remove_settings); 
 	g_list_free(update_settings);
