From 4c695c22bbb1f1fe8de4cc45e135037d50a86285 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Thu, 16 Oct 2003 22:03:20 +0000 Subject: [PATCH] some minor code cleanup. 2003-10-17 Sven Neumann * app/widgets/gimpdnd.c: some minor code cleanup. * libgimpcolor/gimpcolorspace.c: removed trailing whitespace. --- ChangeLog | 6 +++ app/widgets/gimpdnd.c | 89 ++++++++++++++----------------- libgimpcolor/gimpcolorspace.c | 98 ++++++++++++++++++----------------- 3 files changed, 96 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index d05c861dc3..ff8b594319 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-10-17 Sven Neumann + + * app/widgets/gimpdnd.c: some minor code cleanup. + + * libgimpcolor/gimpcolorspace.c: removed trailing whitespace. + 2003-10-16 Dave Neary * libgimpcolor/gimpcolorspace.c: Corrected mistake - two diff --git a/app/widgets/gimpdnd.c b/app/widgets/gimpdnd.c index 7ad469c6d3..4f581c9ca2 100644 --- a/app/widgets/gimpdnd.c +++ b/app/widgets/gimpdnd.c @@ -753,25 +753,25 @@ gimp_dnd_data_dest_remove (GimpDndType data_type, /************************/ static void -gimp_dnd_set_file_data (GtkWidget *widget, - GCallback set_file_func, - gpointer set_file_data, - guchar *vals, - gint format, - gint length) +gimp_dnd_set_file_data (GtkWidget *widget, + GCallback set_file_func, + gpointer set_file_data, + guchar *vals, + gint format, + gint length) { GList *files = NULL; gchar *buffer; if (format != 8) { - g_warning ("Received invalid file data\n"); + g_warning ("Received invalid file data!"); return; } buffer = (gchar *) vals; - g_print ("%s: raw buffer >>%s<<\n", G_GNUC_FUNCTION, buffer); + g_print ("gimp_dnd_set_file_data: raw buffer >>%s<<\n", buffer); { gchar name_buffer[1024]; @@ -781,7 +781,7 @@ gimp_dnd_set_file_data (GtkWidget *widget, gchar *name = name_buffer; gint len = 0; - while ((*buffer != 0) && (*buffer != '\n') && len < 1024) + while (len < sizeof (name_buffer) && *buffer && *buffer != '\n') { *name++ = *buffer++; len++; @@ -790,14 +790,10 @@ gimp_dnd_set_file_data (GtkWidget *widget, break; if (*(name - 1) == 0xd) /* gmc uses RETURN+NEWLINE as delimiter */ - *(name - 1) = '\0'; - else - *name = '\0'; + len--; - name = name_buffer; - - if (name && strlen (name) > 2) - files = g_list_append (files, g_strdup (name)); + if (len > 2) + files = g_list_append (files, g_strndup (name_buffer, len)); if (*buffer) buffer++; @@ -806,8 +802,7 @@ gimp_dnd_set_file_data (GtkWidget *widget, if (files) { - (* (GimpDndDropFileFunc) set_file_func) (widget, files, - set_file_data); + (* (GimpDndDropFileFunc) set_file_func) (widget, files, set_file_data); g_list_foreach (files, (GFunc) g_free, NULL); g_list_free (files); @@ -929,13 +924,14 @@ gimp_dnd_open_files (GtkWidget *widget, for (list = files; list; list = g_list_next (list)) { - const gchar *dnd_crap; + const gchar *dnd_crap = list->data; gchar *filename; gchar *uri = NULL; - dnd_crap = (const gchar *) list->data; + if (!dnd_crap) + continue; - g_print ("%s: trying to convert \"%s\" to an uri...\n", G_GNUC_FUNCTION, + g_print ("gimp_dnd_open_files: trying to convert \"%s\" to an uri...\n", dnd_crap); filename = g_filename_from_uri (dnd_crap, NULL, NULL); @@ -948,31 +944,30 @@ gimp_dnd_open_files (GtkWidget *widget, } else /* else to evil things... */ { - filename = (gchar *) dnd_crap; + const gchar *start = dnd_crap; if (! strncmp (dnd_crap, "file://", strlen ("file://"))) { - filename += strlen ("file://"); + start += strlen ("file://"); } else if (! strncmp (dnd_crap, "file:", strlen ("file:"))) { - filename += strlen ("file:"); + start += strlen ("file:"); } - if (filename != (gchar *) dnd_crap) + if (start != dnd_crap) { /* try if we got a "file:" uri in the local filename encoding */ - gchar *unescaped_filename; if (strstr (filename, "%")) { - unescaped_filename = gimp_unescape_uri_string (filename, -1, + unescaped_filename = gimp_unescape_uri_string (start, -1, "/", FALSE); } else { - unescaped_filename = g_strdup (filename); + unescaped_filename = g_strdup (start); } uri = g_filename_to_uri (unescaped_filename, NULL, NULL); @@ -988,27 +983,24 @@ gimp_dnd_open_files (GtkWidget *widget, } } - g_print ("%s: ...trying to open resulting uri \"%s\"\n", - G_GNUC_FUNCTION, uri); + g_print ("gimp_dnd_open_files: ...trying to open resulting uri \"%s\"\n", + uri); { GimpImage *gimage; GimpPDBStatusType status; GError *error = NULL; - gimage = file_open_with_display (the_gimp, uri, - &status, &error); + gimage = file_open_with_display (the_gimp, uri, &status, &error); if (! gimage && status != GIMP_PDB_CANCEL) { - gchar *filename; - - filename = file_utils_uri_to_utf8_filename (uri); + gchar *filename = file_utils_uri_to_utf8_filename (uri); g_message (_("Opening '%s' failed:\n\n%s"), filename, error->message); - g_clear_error (&error); + g_clear_error (&error); g_free (filename); } } @@ -1081,7 +1073,7 @@ gimp_dnd_set_color_data (GtkWidget *widget, if ((format != 16) || (length != 8)) { - g_warning ("Received invalid color data\n"); + g_warning ("Received invalid color data!"); return; } @@ -1413,12 +1405,11 @@ gimp_dnd_set_image_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("%s(): received invalid image ID data", G_GNUC_FUNCTION); + g_warning ("Received invalid image ID data!"); return; } id = (gchar *) vals; - ID = atoi (id); if (! ID) @@ -1475,7 +1466,7 @@ gimp_dnd_set_item_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid item ID data"); + g_warning ("Received invalid item ID data!"); return; } @@ -1544,7 +1535,7 @@ gimp_dnd_set_brush_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid brush data\n"); + g_warning ("Received invalid brush data!"); return; } @@ -1583,7 +1574,7 @@ gimp_dnd_set_pattern_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid pattern data\n"); + g_warning ("Received invalid pattern data!"); return; } @@ -1620,7 +1611,7 @@ gimp_dnd_set_gradient_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid gradient data\n"); + g_warning ("Received invalid gradient data!"); return; } @@ -1657,7 +1648,7 @@ gimp_dnd_set_palette_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid palette data\n"); + g_warning ("Received invalid palette data!"); return; } @@ -1694,7 +1685,7 @@ gimp_dnd_set_font_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid font data\n"); + g_warning ("Received invalid font data!"); return; } @@ -1730,7 +1721,7 @@ gimp_dnd_set_buffer_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid buffer data\n"); + g_warning ("Received invalid buffer data!"); return; } @@ -1763,7 +1754,7 @@ gimp_dnd_set_imagefile_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid buffer data\n"); + g_warning ("Received invalid buffer data!"); return; } @@ -1796,7 +1787,7 @@ gimp_dnd_set_template_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid buffer data\n"); + g_warning ("Received invalid buffer data!"); return; } @@ -1829,7 +1820,7 @@ gimp_dnd_set_tool_data (GtkWidget *widget, if ((format != 8) || (length < 1)) { - g_warning ("Received invalid tool data\n"); + g_warning ("Received invalid tool data!"); return; } diff --git a/libgimpcolor/gimpcolorspace.c b/libgimpcolor/gimpcolorspace.c index 50a1bdb4e4..8184232e50 100644 --- a/libgimpcolor/gimpcolorspace.c +++ b/libgimpcolor/gimpcolorspace.c @@ -46,9 +46,9 @@ * gimp_rgb_to_hsv: * @rgb: A color value in the RGB colorspace * @hsv: The value converted to the HSV colorspace - * - * Does a conversion from RGB to HSV (Hue, Saturation, - * Value) colorspace. + * + * Does a conversion from RGB to HSV (Hue, Saturation, + * Value) colorspace. **/ void gimp_rgb_to_hsv (const GimpRGB *rgb, @@ -102,7 +102,7 @@ gimp_rgb_to_hsv (const GimpRGB *rgb, * gimp_hsv_to_rgb: * @hsv: A color value in the HSV colorspace * @rgb: The returned RGB value. - * + * * Converts a color value from HSV to RGB colorspace **/ void @@ -181,8 +181,8 @@ gimp_hsv_to_rgb (const GimpHSV *hsv, * gimp_rgb_to_hsl: * @rgb: A color value in the RGB colorspace * @hsl: The value converted to HSL - * - * Convert an RGB color value to a HSL (Hue, Saturation, Lightness) color + * + * Convert an RGB color value to a HSL (Hue, Saturation, Lightness) color * value. **/ void @@ -265,9 +265,9 @@ gimp_hsl_value (gdouble n1, /** * gimp_hsl_to_rgb: - * @hsl: A color value in the HSL colorspace + * @hsl: A color value in the HSL colorspace * @rgb: The value converted to a value in the RGB colorspace - * + * * Convert a HSL color value to an RGB color value. **/ void @@ -306,10 +306,11 @@ gimp_hsl_to_rgb (const GimpHSL *hsl, /** * gimp_rgb_to_cmyk: - * @rgb: A value in the RGB colorspace - * @pullout: A scaling value (0-1) indicating how much black should be pulled out - * @cmyk: The input value naively converted to the CMYK colorspace - * + * @rgb: A value in the RGB colorspace + * @pullout: A scaling value (0-1) indicating how much black should be + * pulled out + * @cmyk: The input value naively converted to the CMYK colorspace + * * Does a naive conversion from RGB to CMYK colorspace. A simple * formula that doesn't take any color-profiles into account is used. * The amount of black pullout how can be controlled via the @pullout @@ -358,9 +359,9 @@ gimp_rgb_to_cmyk (const GimpRGB *rgb, * gimp_cmyk_to_rgb: * @cmyk: A color value in the CMYK colorspace * @rgb: The value converted to the RGB colorspace - * - * Does a simple transformation from the CMYK colorspace to the RGB - * colorspace, without taking color profiles into account. + * + * Does a simple transformation from the CMYK colorspace to the RGB + * colorspace, without taking color profiles into account. **/ void gimp_cmyk_to_rgb (const GimpCMYK *cmyk, @@ -395,11 +396,11 @@ gimp_cmyk_to_rgb (const GimpCMYK *cmyk, #define GIMP_RETURN_RGB(x, y, z) { rgb->r = x; rgb->g = y; rgb->b = z; return; } -/***************************************************************************** +/**************************************************************************** * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. * Pure red always maps to 6 in this implementation. Therefore UNDEFINED can * be defined as 0 in situations where only unsigned numbers are desired. - *****************************************************************************/ + ****************************************************************************/ /** * gimp_rgb_to_hwb: @@ -407,13 +408,13 @@ gimp_cmyk_to_rgb (const GimpCMYK *cmyk, * @hue: The hue value of the above color, in the range 0 to 6 * @whiteness: The whiteness value of the above color, in the range 0 to 1 * @blackness: The blackness value of the above color, in the range 0 to 1 - * + * * Theoretically, hue 0 (pure red) is identical to hue 6 in these transforms. * Pure red always maps to 6 in this implementation. Therefore UNDEFINED can * be defined as 0 in situations where only unsigned numbers are desired. - * - * RGB are each on [0, 1]. Whiteness and Blackness are returned in the - * range [0, 1] and H is returned in the range [0, 6]. If W == 1 - B, H is + * + * RGB are each on [0, 1]. Whiteness and Blackness are returned in the + * range [0, 1] and H is returned in the range [0, 6]. If W == 1 - B, H is * undefined. **/ void @@ -456,9 +457,9 @@ gimp_rgb_to_hwb (const GimpRGB *rgb, * @whiteness: A whiteness value, in the range 0 to 1 * @blackness: A blackness value, in the range 0 to 1 * @rgb: The above color converted to the RGB colorspace - * - * H is defined in the range [0, 6] or UNDEFINED, B and W are both in the - * range [0, 1]. The returned RGB values are all in the range [0, 1]. + * + * H is defined in the range [0, 6] or UNDEFINED, B and W are both in the + * range [0, 1]. The returned RGB values are all in the range [0, 1]. **/ void gimp_hwb_to_rgb (gdouble hue, @@ -518,15 +519,16 @@ gimp_hwb_to_rgb (gdouble hue, /** * gimp_rgb_to_hsv_int: - * @red: The red channel value, returns the Hue channel + * @red: The red channel value, returns the Hue channel * @green: The green channel value, returns the Saturation channel * @blue: The blue channel value, returns the Value channel - * - * The arguments are pointers to int representing channel values in the - * RGB colorspace, and the values pointed to are all in the range [0, 255]. * - * The function changes the arguments to point to the HSV value corresponding, - * with the returned values in the following + * The arguments are pointers to int representing channel values in + * the RGB colorspace, and the values pointed to are all in the range + * [0, 255]. + * + * The function changes the arguments to point to the HSV value + * corresponding, with the returned values in the following * ranges: H [0, 360], S [0, 255], V [0, 255]. **/ void @@ -553,7 +555,7 @@ gimp_rgb_to_hsv_int (gint *red, v = MAX (g, b); min = MIN (r, b); } - + delta = v - min; if (v == 0.0) @@ -585,14 +587,14 @@ gimp_rgb_to_hsv_int (gint *red, /** * gimp_hsv_to_rgb_int: - * @hue: The hue channel, returns the red channel + * @hue: The hue channel, returns the red channel * @saturation: The saturation channel, returns the green channel * @value: The value channel, returns the blue channel - * - * The arguments are pointers to int, with the values pointed to in the + * + * The arguments are pointers to int, with the values pointed to in the * following ranges: H [0, 360], S [0, 255], V [0, 255]. * - * The function changes the arguments to point to the RGB value + * The function changes the arguments to point to the RGB value * corresponding, with the returned values all in the range [0, 255]. **/ void @@ -615,7 +617,7 @@ gimp_hsv_to_rgb_int (gint *hue, h = *hue; s = *saturation / 255.0; v = *value / 255.0; - + if (h == 360) h_temp = 0; else @@ -671,14 +673,14 @@ gimp_hsv_to_rgb_int (gint *hue, /** * gimp_rgb_to_hsl_int: - * @red: Red channel, returns Hue channel + * @red: Red channel, returns Hue channel * @green: Green channel, returns Lightness channel * @blue: Blue channel, returns Saturation channel - * - * The arguments are pointers to int representing channel values in the + * + * The arguments are pointers to int representing channel values in the * RGB colorspace, and the values pointed to are all in the range [0, 255]. * - * The function changes the arguments to point to the corresponding HLS + * The function changes the arguments to point to the corresponding HLS * value with the values pointed to in the following ranges: H [0, 360], * L [0, 255], S [0, 255]. **/ @@ -748,10 +750,10 @@ gimp_rgb_to_hsl_int (gint *red, * @red: Red channel * @green: Green channel * @blue: Blue channel - * - * Calculates the lightness value of an RGB triplet with the formula + * + * Calculates the lightness value of an RGB triplet with the formula * L = (max(R, G, B) + min (R, G, B)) / 2 - * + * * Return value: Luminance vaue corresponding to the input RGB value **/ gint @@ -804,11 +806,11 @@ gimp_hsl_value_int (gdouble n1, * @hue: Hue channel, returns Red channel * @saturation: Saturation channel, returns Green channel * @lightness: Lightness channel, returns Blue channel - * - * The arguments are pointers to int, with the values pointed to in the + * + * The arguments are pointers to int, with the values pointed to in the * following ranges: H [0, 360], L [0, 255], S [0, 255]. * - * The function changes the arguments to point to the RGB value + * The function changes the arguments to point to the RGB value * corresponding, with the returned values all in the range [0, 255]. **/ void @@ -842,8 +844,8 @@ gimp_hsl_to_rgb_int (gint *hue, /* chromatic case */ *hue = gimp_hsl_value_int (m1, m2, h + 85); - *saturation = gimp_hsl_value_int (m1, m2, h); - *lightness = gimp_hsl_value_int (m1, m2, h - 85); + *saturation = gimp_hsl_value_int (m1, m2, h); + *lightness = gimp_hsl_value_int (m1, m2, h - 85); } }