gimp/app/core/gimpgradient.c

1181 lines
30 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
an evil temp_hack which lets GimpContext managing the active display 2001-08-14 Michael Natterer <mitch@gimp.org> * app/gdisplay.h: an evil temp_hack which lets GimpContext managing the active display withoug including "gdisplay.h". Will go away as soon ad context properties are registered dynamically. * app/module_db.c: cleaned up the object code in preparation of moving it to core/. * app/path.c: connect to GimpImage's * app/core/gimpobject.[ch]: derive it from GObject, not from GtkObject any more (yeah :-) * app/core/*.c: #include <glib-object.h> instead of <gtk/gtk.h>, removed some remaining GtkObject-isms. (left in a few #include <gtk/gtk.h> where bigger changes are needed to get rid of the UI dependency). * app/core/core-types.h: #include <gdk-pixbuf/gdk-pixbuf.h> here temporarily. * app/core/gimp.c (gimp_create_display): unref the image after creating it's first display. * app/core/gimpbrush.[ch]: disabled the parts of the code which depend on GimpPaintTool. * app/core/gimpbrushgenerated.c * app/core/gimpbrushpipe.c: changed accordingly. * app/core/gimpcontext.[ch]: evil hack (see above) to manage the active display without including "gdisplay.h" * app/core/gimpimage-mask.[ch]: pass a context to gimage_mask_stroke() and get the current tool's PDB string from there. * app/core/gimpedit.c: changed accordingly. * app/core/gimpimage.c: use gimp_image_update() instead of gdisplays_update_full(). * app/gui/color-area.c * app/gui/colormap-dialog.c * app/gui/dialogs-constructors.c * app/gui/edit-commands.c * app/gui/image-commands.c * app/gui/toolbox.c: changed accordingly (don't use Gtk methods on GObjects). * app/gui/menus.c: fix some const warnings by explicit casting. * app/tools/*.[ch]: ported all tools to GObject, some minor cleanup while i was on it. * app/widgets/gimpdialogfactory.[ch]: ported to GObject. * app/widgets/gimplayerlistview.h: added FOO_GET_CLASS() macro. * tools/pdbgen/app.pl: added a "widgets_eek" hack like "tools_eek" which inserts #include "widgets/widgets-types.h" before ordinary includes. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/edit.pdb * app/pdb/brush_select_cmds.c * app/pdb/edit_cmds.c: changed according to the stuff above.
2001-08-14 22:53:55 +08:00
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
new directory app/base/ 2001-05-15 Michael Natterer <mitch@gimp.org> * configure.in: new directory app/base/ * app/Makefile.am * app/boundary.[ch] * app/brush_scale.[ch] * app/gimpchecks.h * app/gimplut.[ch] * app/pixel_processor.[ch] * app/pixel_region.[ch] * app/pixel_surround.[ch] * app/temp_buf.[ch] * app/tile.[ch] * app/tile_cache.[ch] * app/tile_manager.[ch] * app/tile_manager_pvt.h * app/tile_pvt.h * app/tile_swap.[ch]: moved to base/ * app/base/Makefile.am * app/base/base-types.h * app/base/*: new directory for the sub-object pixel maniplation and storage stuff. Does not include Gtk+ or anything outside base/. Did some cleanup in all files. * app/appenums.h * app/apptypes.h * app/core/gimpimage.h: removed types which are now in base/base-types.h. * app/base/base-config.[ch] * app/gimprc.[ch]: put the config variables for base/ to their own file so base/ doesn not have to include gimprc.h (does not yet work, i.e. the variables are un-configurable right now) * app/main.c: set a log handler for "Gimp-Base". * app/paint-funcs/Makefile.am * app/paint-funcs/paint-funcs.[ch]: removed the color hash which maps RGB to color indices because it's a totally standalone system which has nothing to do with the paint-funcs and introduced a GimpImage dependency. paint-funcs/ should be considered on the same sub-object (glib-only) level as base/, only in a different directory. * app/core/Makefile.am * app/core/gimpimage-colorhash.[ch]: put the color hash here. * app/gimage.c: don't invalidate the color hash here... * app/core/gimpimage.c: ... but in the colormap_changed() default inplementation. Initialize the hash in class_init(). * tools/pdbgen/Makefile.am: scan app/base/base-types.h for enums. * tools/pdbgen/enums.pl: regenerated. * app/[lots] * app/core/[of] * app/gui/[files] * app/pdb/[all] * app/tools/[over] * app/widgets/[the] * tools/pdbgen/pdb/[place]: changed #includes accordingly. And use base_config->value instead of the stuff from gimprc.h.
2001-05-15 19:25:25 +08:00
#include "base/temp-buf.h"
#include "gimpimage.h"
#include "gimpgradient.h"
#include "libgimp/gimpintl.h"
#define EPSILON 1e-10
static void gimp_gradient_class_init (GimpGradientClass *klass);
static void gimp_gradient_init (GimpGradient *gradient);
static void gimp_gradient_finalize (GObject *object);
static gsize gimp_gradient_get_memsize (GimpObject *object);
static TempBuf * gimp_gradient_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
static void gimp_gradient_dirty (GimpData *data);
static gboolean gimp_gradient_save (GimpData *data,
GError **error);
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
static gchar * gimp_gradient_get_extension (GimpData *data);
static GimpData * gimp_gradient_duplicate (GimpData *data,
gboolean stingy_memory_use);
static gdouble gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos);
static gdouble gimp_gradient_calc_curved_factor (gdouble middle,
gdouble pos);
static gdouble gimp_gradient_calc_sine_factor (gdouble middle,
gdouble pos);
static gdouble gimp_gradient_calc_sphere_increasing_factor (gdouble middle,
gdouble pos);
static gdouble gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
gdouble pos);
static GimpDataClass *parent_class = NULL;
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
GType
gimp_gradient_get_type (void)
{
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
static GType gradient_type = 0;
if (! gradient_type)
{
static const GTypeInfo gradient_info =
{
sizeof (GimpGradientClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_gradient_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpGradient),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_gradient_init,
};
gradient_type = g_type_register_static (GIMP_TYPE_DATA,
"GimpGradient",
&gradient_info, 0);
}
return gradient_type;
}
static void
gimp_gradient_class_init (GimpGradientClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GimpViewableClass *viewable_class;
GimpDataClass *data_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
data_class = GIMP_DATA_CLASS (klass);
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) 2001-07-24 Michael Natterer <mitch@gimp.org> Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning) * configure.in: require glib/gtk+ >= 1.3.7, commented out the gtkxmhtml stuff. From now on, you will need glib, pango, atk and gtk+ HEAD from CVS to hack or use GIMP HEAD. Beware, it crashes randomly :) * app/core/Makefile.am * app/core/gimpmarshal.list: new file plus rules to generate gimpmarshal.[ch] from it. * app/core/* * app/tools/* * app/widgets/* * libgimpwidgets/*: started to use the glib object system. All core/ objects are still gtk objects however. All signals are created using g_signal_new(). There are many gtk+ artefacts left. Finally, we will _not_ use the gtk_signal_foo() wrappers and friends any more. * app/colormaps.c * app/devices.[ch] * app/disp_callbacks.c * app/errorconsole.c * app/file-save.[ch] * app/interface.c * app/module_db.c * app/nav_window.c * app/ops_buttons.c * app/scroll.c * app/user_install.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/brushes-commands.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/file-commands.c * app/gui/file-dialog-utils.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.[ch] * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/gradients-commands.c * app/gui/image-commands.c * app/gui/info-dialog.[ch] * app/gui/layer-select.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/patterns-commands.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.[ch] * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * libgimp/gimpbrushmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimp/gimpui.c * libgimpbase/gimpenv.c: tons and tons of changes like "const gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete and currently disables), lots of s/gtk_signal/g_signal/, removal/replacement of deprecated stuff, s/GtkSignalFunc/GCallback/ and lots of small changes and fixes while I was on it, zillions of warnings left... * modules/Makefile.am: disabled the water color selector temporarily (XInput issues). * plug-ins/Makefile.am * plug-ins/common/.cvsignore * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl: simply excluded all plug-ins which did not build (including Script-Fu). They are trivial to fix.
2001-07-25 05:27:11 +08:00
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_gradient_finalize;
gimp_object_class->get_memsize = gimp_gradient_get_memsize;
viewable_class->get_new_preview = gimp_gradient_get_new_preview;
data_class->dirty = gimp_gradient_dirty;
data_class->save = gimp_gradient_save;
data_class->get_extension = gimp_gradient_get_extension;
data_class->duplicate = gimp_gradient_duplicate;
}
static void
gimp_gradient_init (GimpGradient *gradient)
{
gradient->segments = NULL;
gradient->last_visited = NULL;
}
static void
gimp_gradient_finalize (GObject *object)
{
GimpGradient *gradient;
gradient = GIMP_GRADIENT (object);
if (gradient->segments)
{
gimp_gradient_segments_free (gradient->segments);
gradient->segments = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gsize
gimp_gradient_get_memsize (GimpObject *object)
{
GimpGradient *gradient;
GimpGradientSegment *segment;
gsize memsize = 0;
gradient = GIMP_GRADIENT (object);
for (segment = gradient->segments; segment; segment = segment->next)
{
memsize += sizeof (GimpGradientSegment);
}
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
}
static TempBuf *
gimp_gradient_get_new_preview (GimpViewable *viewable,
gint width,
gint height)
{
GimpGradient *gradient;
TempBuf *temp_buf;
guchar *buf;
guchar *p0, *p1;
guchar *even, *odd;
gint x, y;
gdouble dx, cur_x;
GimpRGB color;
gdouble c0, c1;
gradient = GIMP_GRADIENT (viewable);
dx = 1.0 / (width - 1);
cur_x = 0.0;
p0 = even = g_malloc (width * 3);
p1 = odd = g_malloc (width * 3);
/* Create lines to fill the image */
for (x = 0; x < width; x++)
{
gimp_gradient_get_color_at (gradient, cur_x, &color);
if ((x / GIMP_CHECK_SIZE_SM) & 1)
{
c0 = GIMP_CHECK_LIGHT;
c1 = GIMP_CHECK_DARK;
}
else
{
c0 = GIMP_CHECK_DARK;
c1 = GIMP_CHECK_LIGHT;
}
*p0++ = (c0 + (color.r - c0) * color.a) * 255.0;
*p0++ = (c0 + (color.g - c0) * color.a) * 255.0;
*p0++ = (c0 + (color.b - c0) * color.a) * 255.0;
*p1++ = (c1 + (color.r - c1) * color.a) * 255.0;
*p1++ = (c1 + (color.g - c1) * color.a) * 255.0;
*p1++ = (c1 + (color.b - c1) * color.a) * 255.0;
cur_x += dx;
}
temp_buf = temp_buf_new (width, height,
3,
0, 0,
NULL);
buf = temp_buf_data (temp_buf);
for (y = 0; y < height; y++)
{
if ((y / GIMP_CHECK_SIZE_SM) & 1)
{
memcpy (buf + (width * y * 3), odd, width * 3);
}
else
{
memcpy (buf + (width * y * 3), even, width * 3);
}
}
g_free (even);
g_free (odd);
return temp_buf;
}
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
static GimpData *
gimp_gradient_duplicate (GimpData *data,
gboolean stingy_memory_use)
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
{
GimpGradient *gradient;
GimpGradientSegment *head, *prev, *cur, *orig;
gradient = GIMP_GRADIENT (g_object_new (GIMP_TYPE_GRADIENT, NULL));
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
gimp_data_dirty (GIMP_DATA (gradient));
prev = NULL;
orig = GIMP_GRADIENT (data)->segments;
head = NULL;
while (orig)
{
cur = gimp_gradient_segment_new ();
*cur = *orig; /* Copy everything */
cur->prev = prev;
cur->next = NULL;
if (prev)
prev->next = cur;
else
head = cur; /* Remember head */
prev = cur;
orig = orig->next;
}
gradient->segments = head;
return GIMP_DATA (gradient);
}
GimpData *
gimp_gradient_new (const gchar *name,
gboolean stingy_memory_use)
{
GimpGradient *gradient;
g_return_val_if_fail (name != NULL, NULL);
gradient = GIMP_GRADIENT (g_object_new (GIMP_TYPE_GRADIENT, NULL));
gimp_object_set_name (GIMP_OBJECT (gradient), name);
gradient->segments = gimp_gradient_segment_new ();
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
return GIMP_DATA (gradient);
}
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
GimpData *
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
gimp_gradient_get_standard (void)
{
static GimpGradient *standard_gradient = NULL;
if (! standard_gradient)
{
standard_gradient = GIMP_GRADIENT (gimp_gradient_new ("Standard", FALSE));
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
g_object_ref (standard_gradient);
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
}
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
return GIMP_DATA (standard_gradient);
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
}
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
GimpData *
gimp_gradient_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpGradient *gradient;
GimpGradientSegment *seg;
GimpGradientSegment *prev;
gint num_segments;
gint i;
gint type, color;
FILE *file;
gchar line[1024];
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
file = fopen (filename, "rb");
if (!file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for reading: %s"),
filename, g_strerror (errno));
return NULL;
}
fgets (line, 1024, file);
if (strcmp (line, "GIMP Gradient\n") != 0)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal Parse Error: '%s' is not a GIMP Gradient file"),
filename);
fclose (file);
return NULL;
}
gradient = GIMP_GRADIENT (g_object_new (GIMP_TYPE_GRADIENT, NULL));
gimp_data_set_filename (GIMP_DATA (gradient), filename);
fgets (line, 1024, file);
if (! strncmp (line, "Name: ", strlen ("Name: ")))
{
if (g_utf8_validate (line, -1, NULL))
{
gimp_object_set_name (GIMP_OBJECT (gradient),
g_strstrip (&line[strlen ("Name: ")]));
}
else
{
g_message (_("Invalid UTF-8 string in gradient file '%s'."),
filename);
gimp_object_set_name (GIMP_OBJECT (gradient), _("Unnamed"));
}
fgets (line, 1024, file);
}
else /* old gradient format */
{
added -DG_DISABLE_DEPRECATED and -DGDK_DISABLE_COMPAT_H. 2001-08-29 Michael Natterer <mitch@gimp.org> * configure.in: added -DG_DISABLE_DEPRECATED and -DGDK_DISABLE_COMPAT_H. * app/batch.c * app/file-utils.c * app/gdisplay.c * app/gdisplay_ops.c * app/gimprc.[ch] * app/module_db.c * app/nav_window.c * app/undo_history.c * app/core/gimpgradient.c * app/core/gimpimagefile.c * app/core/gimppalette.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/error-console-dialog.c * app/gui/file-commands.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/info-window.c * app/gui/menus.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c * app/widgets/gimpdatafactoryview.c * libgimp/gimpmenu.c * plug-ins/common/bz2.c * plug-ins/common/compose.c * plug-ins/common/csource.c * plug-ins/common/decompose.c * plug-ins/common/gz.c * plug-ins/common/uniteditor.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/rcm/rcm_dialog.c * plug-ins/script-fu/interp_slib.c * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-scripts.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gimprc.pdb * app/pdb/fileops_cmds.c * app/pdb/gimprc_cmds.c: removed deprecated stuff like g_basename(), g_dirname(), g_strup() and friends. Added some "const gchar *" declarations while I was on it. Added some G_N_ELEMENTS() macros instead of declaring a useless variable for the number of items. * app/widgets/gtkhwrapbox.[ch] * app/widgets/gtkvwrapbox.[ch] * app/widgets/gtkwrapbox.[ch]: replaced with the latest versions from GLE, ported by the master himself. * app/gui/toolbox.c: changed accordingly. * app/plug_in.c * libgimp/gimp.c * libgimpbase/gimpwire.[ch]: use evil hacks to get binary mode from the new GIOChannel implementation (upstream bugreport already posted).
2001-08-30 01:48:28 +08:00
gchar *basename;
basename = g_path_get_basename (filename);
gimp_object_set_name (GIMP_OBJECT (gradient), basename);
g_free (basename);
}
num_segments = atoi (line);
if (num_segments < 1)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Fatal parsing error:\nGradient file '%s' is corrupt."),
filename);
g_object_unref (gradient);
fclose (file);
return NULL;
}
prev = NULL;
for (i = 0; i < num_segments; i++)
{
gchar *end;
seg = gimp_gradient_segment_new ();
seg->prev = prev;
if (prev)
prev->next = seg;
else
gradient->segments = seg;
fgets (line, 1024, file);
seg->left = g_ascii_strtod (line, &end);
if (end && errno != ERANGE)
seg->middle = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->right = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->left_color.r = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->left_color.g = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->left_color.b = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->left_color.a = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->right_color.r = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->right_color.g = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->right_color.b = g_ascii_strtod (end, &end);
if (end && errno != ERANGE)
seg->right_color.a = g_ascii_strtod (end, &end);
if (errno != ERANGE &&
sscanf (end, "%d %d", &type, &color) == 2)
{
seg->type = (GimpGradientSegmentType) type;
seg->color = (GimpGradientSegmentColor) color;
}
else
{
g_message (_("Corrupt segment %d in gradient file '%s'."),
i, filename);
}
prev = seg;
}
fclose (file);
Made a GimpContainer out of the palette list: 2001-02-11 Michael Natterer <mitch@gimp.org> Made a GimpContainer out of the palette list: * app/Makefile.am * app/palettes.[ch]: new files for the global palette list. * app/gimpgradientpreview.[ch] * app/gimppalettepreview.[ch]: new widgets. * app/gimppalette.[ch]: derive it from GimpData to get all the preview etc. stuff. * app/datafiles.[ch]: new function datafiles_check_extension(), added a "loader_data" parameter to datafiles_read_directories() and pass it to the loader function. * app/gimpcontext.[ch]: added the palette (not really used yet except by the test dialogs). * app/gimpdatalist.[ch]: new function gimp_data_list_save_and_clear() which does everything needed for patterns_free(), brushes_free() ... * app/gimpdnd.c: added palette DND. * app/app_procs.c * app/brushes.c * app/color_notebook.h * app/commands.c * app/convert.c * app/gimpbrush.h * app/gimpbrushpipe.h * app/gimpgradient.c * app/gimppattern.h * app/gimppreview.c * app/gradients.c * app/module_db.c * app/palette.[ch] * app/paletteP.h * app/palette_import.c * app/palette_select.[ch] * app/patterns.c * app/plug_in.c * app/pdb/convert_cmds.c * app/pdb/palette_cmds.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/palette.pdb: lotsa stuff: changed due to the above API changes, #define the file extensions in the GimpData subclasses' header files instead of hardcoding them in several places, ... * data/palettes/*: The same file format change as for the gradient files: - Save the palette name in a parsable form (as part of the file format, not in a comment. - Removed unserscores from the palette names. - Added an extension (Gimp PaLettes are ".gpl" files now ;-)
2001-02-12 00:14:25 +08:00
GIMP_DATA (gradient)->dirty = FALSE;
added a note about apptype.h and about not including headers in headers. 2001-02-14 Michael Natterer <mitch@gimp.org> * HACKING: added a note about apptype.h and about not including headers in headers. * app/apptypes.h: added GimpTool and BitmapCursor. * app/cursorutil.h * app/devices.h * app/draw_core.h * app/tools/color_picker.h * app/tools/tool.h * app/tools/tool_options.h * app/gimpcontext.h: removed includes of "tools/tool.h" * app/gimprc.[ch]: indentadion cleanup, added "module_db_load_inhibit". * app/module_db.c: removed the above variable here. * app/gimpdata.[ch]: added a vitrual "duplicate" method. * app/gimpbrush.[ch] * app/gimpbrushgenerated.[ch] * app/gimpbrushpipe.[ch] * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch]: all "load", "new" and "get_standard" functions return a GimpData pointer now. * app/gimpdatafactory.[ch]: made some stuff const. * app/gimpdatafactoryview.c: activate the "duplicate" button and set the initial button sensitivity correctly. * app/brush_select.c * app/gradient_select.c * app/pattern_select.c: use the new GimpDataFactoryView. * libgimp/Makefile.am: grouped the file to sort out what _may_ go to subdirs or separate libs. * libgimp/gimpenv.[ch]: added many "const". * app/app_procs.c * app/brush_edit.c * app/gimpcontext.c * app/gimpdnd.c * app/gradient_editor.c * app/palette.c * app/palette_import.c * app/user_install.c: many related changes. * libgimpmath/gimpmathtypes.h * libgimpmath/gimpvector.[ch]: minor cleanups. * plug-ins/script-fu/script-fu.c: gimp_data_directory() is const now.
2001-02-14 22:57:14 +08:00
return GIMP_DATA (gradient);
}
static void
gimp_gradient_dirty (GimpData *data)
{
GimpGradient *gradient;
gradient = GIMP_GRADIENT (data);
gradient->last_visited = NULL;
if (GIMP_DATA_CLASS (parent_class)->dirty)
GIMP_DATA_CLASS (parent_class)->dirty (data);
}
static gboolean
gimp_gradient_save (GimpData *data,
GError **error)
{
GimpGradient *gradient;
GimpGradientSegment *seg;
gint num_segments;
FILE *file;
gradient = GIMP_GRADIENT (data);
file = fopen (data->filename, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
data->filename, g_strerror (errno));
return FALSE;
}
/* File format is:
*
* GIMP Gradient
* Name: name
* number_of_segments
* left middle right r0 g0 b0 a0 r1 g1 b1 a1 type coloring
* left middle right r0 g0 b0 a0 r1 g1 b1 a1 type coloring
* ...
*/
fprintf (file, "GIMP Gradient\n");
fprintf (file, "Name: %s\n", GIMP_OBJECT (gradient)->name);
/* Count number of segments */
num_segments = 0;
seg = gradient->segments;
while (seg)
{
num_segments++;
seg = seg->next;
}
/* Write rest of file */
fprintf (file, "%d\n", num_segments);
for (seg = gradient->segments; seg; seg = seg->next)
{
gchar buf[11][G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_formatd (buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left);
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->middle);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right);
g_ascii_formatd (buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.r);
g_ascii_formatd (buf[4], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.g);
g_ascii_formatd (buf[5], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.b);
g_ascii_formatd (buf[6], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->left_color.a);
g_ascii_formatd (buf[7], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.r);
g_ascii_formatd (buf[8], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.g);
g_ascii_formatd (buf[9], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.b);
g_ascii_formatd (buf[10], G_ASCII_DTOSTR_BUF_SIZE, "%f", seg->right_color.a);
fprintf (file, "%s %s %s %s %s %s %s %s %s %s %s %d %d\n",
buf[0], buf[1], buf[2], buf[3], buf[4],
buf[5], buf[6], buf[7], buf[8], buf[9], buf[10],
(gint) seg->type,
(gint) seg->color);
}
fclose (file);
return TRUE;
}
gimprc.in user_install user_install.bat app/gimprc.[ch] removed the 2001-02-13 Michael Natterer <mitch@gimp.org> * gimprc.in * user_install * user_install.bat * app/gimprc.[ch] * app/preferences_dialog.c: removed the "brush_vbr_path" variable, because all data types will be editable and saveable soon. * app/Makefile.am * app/apptypes.h * app/gimpdatafactory.[ch]: new object which holds a data list and knows how to create, edit, duplicate etc. the items in it. Will completely replace the brushes.[ch], patterns.[ch], ... files soon. * po/POTFILES.in * app/gimpdatacontainerview.[ch]: removed. * app/gimpdatafactoryview.[ch]: added. A view on the GimpDataFactory with a GUI for creating, editing, deleting etc. items (mostly unimplemented). * app/context_manager.[ch]: replaced the global data lists by global data factories. * app/brush_select.c * app/brushes.[ch] * app/commands.c * app/convert.c * app/devices.c * app/gimpbrush.[ch] * app/gimpbrushgenerated.c * app/gimpcontext.c * app/gimpdata.[ch] * app/gimpdatalist.[ch] * app/gimpdnd.c * app/gimpgradient.[ch] * app/gimppalette.[ch] * app/gimppattern.[ch] * app/gradient_editor.c * app/gradient_select.c * app/gradients.[ch] * app/indicator_area.c * app/palette.c * app/palette_import.c * app/palette_select.c * app/palettes.[ch] * app/pattern_select.c * app/patterns.[ch] * app/pdb/brush_select_cmds.c * app/pdb/brushes_cmds.c * app/pdb/convert_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/pattern_select_cmds.c * app/pdb/patterns_cmds.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly.
2001-02-14 03:53:07 +08:00
static gchar *
gimp_gradient_get_extension (GimpData *data)
{
return GIMP_GRADIENT_FILE_EXTENSION;
}
gboolean
gimp_gradient_save_as_pov (GimpGradient *gradient,
const gchar *filename,
GError **error)
{
FILE *file;
GimpGradientSegment *seg;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
gchar color_buf[4][G_ASCII_DTOSTR_BUF_SIZE];
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
file = fopen (filename, "wb");
if (! file)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
_("Could not open '%s' for writing: %s"),
filename, g_strerror (errno));
return FALSE;
}
else
{
fprintf (file, "/* color_map file created by the GIMP */\n");
fprintf (file, "/* http://www.gimp.org/ */\n");
fprintf (file, "color_map {\n");
for (seg = gradient->segments; seg; seg = seg->next)
{
/* Left */
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->left);
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->left_color.r);
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->left_color.g);
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->left_color.b);
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - seg->left_color.a);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
/* Middle */
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->middle);
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
(seg->left_color.r + seg->right_color.r) / 2.0);
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
(seg->left_color.g + seg->right_color.g) / 2.0);
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
(seg->left_color.b + seg->right_color.b) / 2.0);
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - (seg->left_color.a + seg->right_color.a) / 2.0);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
/* Right */
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->right);
g_ascii_formatd (color_buf[0], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->right_color.r);
g_ascii_formatd (color_buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->right_color.g);
g_ascii_formatd (color_buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f",
seg->right_color.b);
g_ascii_formatd (color_buf[3], G_ASCII_DTOSTR_BUF_SIZE, "%f",
1.0 - seg->right_color.a);
fprintf (file, "\t[%s color rgbt <%s, %s, %s, %s>]\n",
buf,
color_buf[0], color_buf[1], color_buf[2], color_buf[3]);
}
fprintf (file, "} /* color_map */\n");
fclose (file);
}
return TRUE;
}
void
gimp_gradient_get_color_at (GimpGradient *gradient,
gdouble pos,
GimpRGB *color)
{
gdouble factor = 0.0;
GimpGradientSegment *seg;
gdouble seg_len;
gdouble middle;
GimpRGB rgb;
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (color != NULL);
/* if there is no gradient return a totally transparent black */
if (gradient == NULL)
{
gimp_rgba_set (color, 0.0, 0.0, 0.0, 0.0);
return;
}
if (pos < 0.0)
pos = 0.0;
else if (pos > 1.0)
pos = 1.0;
seg = gimp_gradient_get_segment_at (gradient, pos);
seg_len = seg->right - seg->left;
if (seg_len < EPSILON)
{
middle = 0.5;
pos = 0.5;
}
else
{
middle = (seg->middle - seg->left) / seg_len;
pos = (pos - seg->left) / seg_len;
}
switch (seg->type)
{
case GIMP_GRAD_LINEAR:
factor = gimp_gradient_calc_linear_factor (middle, pos);
break;
case GIMP_GRAD_CURVED:
factor = gimp_gradient_calc_curved_factor (middle, pos);
break;
case GIMP_GRAD_SINE:
factor = gimp_gradient_calc_sine_factor (middle, pos);
break;
case GIMP_GRAD_SPHERE_INCREASING:
factor = gimp_gradient_calc_sphere_increasing_factor (middle, pos);
break;
case GIMP_GRAD_SPHERE_DECREASING:
factor = gimp_gradient_calc_sphere_decreasing_factor (middle, pos);
break;
default:
g_warning ("%s: Unknown gradient type %d.",
G_GNUC_PRETTY_FUNCTION, seg->type);
break;
}
/* Calculate color components */
rgb.a =
seg->left_color.a + (seg->right_color.a - seg->left_color.a) * factor;
if (seg->color == GIMP_GRAD_RGB)
{
rgb.r =
seg->left_color.r + (seg->right_color.r - seg->left_color.r) * factor;
rgb.g =
seg->left_color.g + (seg->right_color.g - seg->left_color.g) * factor;
rgb.b =
seg->left_color.b + (seg->right_color.b - seg->left_color.b) * factor;
}
else
{
GimpHSV left_hsv;
GimpHSV right_hsv;
gimp_rgb_to_hsv (&seg->left_color, &left_hsv);
gimp_rgb_to_hsv (&seg->right_color, &right_hsv);
left_hsv.s = left_hsv.s + (right_hsv.s - left_hsv.s) * factor;
left_hsv.v = left_hsv.v + (right_hsv.v - left_hsv.v) * factor;
switch (seg->color)
{
case GIMP_GRAD_HSV_CCW:
if (left_hsv.h < right_hsv.h)
{
left_hsv.h += (right_hsv.h - left_hsv.h) * factor;
}
else
{
left_hsv.h += (1.0 - (left_hsv.h - right_hsv.h)) * factor;
if (left_hsv.h > 1.0)
left_hsv.h -= 1.0;
}
break;
case GIMP_GRAD_HSV_CW:
if (right_hsv.h < left_hsv.h)
{
left_hsv.h -= (left_hsv.h - right_hsv.h) * factor;
}
else
{
left_hsv.h -= (1.0 - (right_hsv.h - left_hsv.h)) * factor;
if (left_hsv.h < 0.0)
left_hsv.h += 1.0;
}
break;
default:
g_warning ("%s(): Unknown coloring mode %d",
G_GNUC_PRETTY_FUNCTION, (gint) seg->color);
break;
}
gimp_hsv_to_rgb (&left_hsv, &rgb);
}
*color = rgb;
}
GimpGradientSegment *
gimp_gradient_get_segment_at (GimpGradient *gradient,
gdouble pos)
{
GimpGradientSegment *seg;
g_return_val_if_fail (GIMP_IS_GRADIENT (gradient), NULL);
/* handle FP imprecision at the edges of the gradient */
pos = CLAMP (pos, 0.0, 1.0);
if (gradient->last_visited)
seg = gradient->last_visited;
else
seg = gradient->segments;
while (seg)
{
if (pos >= seg->left)
{
if (pos <= seg->right)
{
gradient->last_visited = seg; /* for speed */
return seg;
}
else
{
seg = seg->next;
}
}
else
{
seg = seg->prev;
}
}
/* Oops: we should have found a segment, but we didn't */
g_warning ("%s(): no matching segment for position %0.15f",
G_GNUC_PRETTY_FUNCTION, pos);
return NULL;
}
static gdouble
gimp_gradient_calc_linear_factor (gdouble middle,
gdouble pos)
{
if (pos <= middle)
{
if (middle < EPSILON)
return 0.0;
else
return 0.5 * pos / middle;
}
else
{
pos -= middle;
middle = 1.0 - middle;
if (middle < EPSILON)
return 1.0;
else
return 0.5 + 0.5 * pos / middle;
}
}
static gdouble
gimp_gradient_calc_curved_factor (gdouble middle,
gdouble pos)
{
if (middle < EPSILON)
middle = EPSILON;
return pow(pos, log (0.5) / log (middle));
}
static gdouble
gimp_gradient_calc_sine_factor (gdouble middle,
gdouble pos)
{
pos = gimp_gradient_calc_linear_factor (middle, pos);
return (sin ((-G_PI / 2.0) + G_PI * pos) + 1.0) / 2.0;
}
static gdouble
gimp_gradient_calc_sphere_increasing_factor (gdouble middle,
gdouble pos)
{
pos = gimp_gradient_calc_linear_factor (middle, pos) - 1.0;
return sqrt (1.0 - pos * pos); /* Works for convex increasing and concave decreasing */
}
static gdouble
gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
gdouble pos)
{
pos = gimp_gradient_calc_linear_factor (middle, pos);
return 1.0 - sqrt(1.0 - pos * pos); /* Works for convex decreasing and concave increasing */
}
/* gradient segment functions */
GimpGradientSegment *
gimp_gradient_segment_new (void)
{
GimpGradientSegment *seg;
seg = g_new (GimpGradientSegment, 1);
seg->left = 0.0;
seg->middle = 0.5;
seg->right = 1.0;
gimp_rgba_set (&seg->left_color, 0.0, 0.0, 0.0, 1.0);
gimp_rgba_set (&seg->right_color, 1.0, 1.0, 1.0, 1.0);
seg->type = GIMP_GRAD_LINEAR;
seg->color = GIMP_GRAD_RGB;
seg->prev = seg->next = NULL;
return seg;
}
void
gimp_gradient_segment_free (GimpGradientSegment *seg)
{
g_return_if_fail (seg != NULL);
g_free (seg);
}
void
gimp_gradient_segments_free (GimpGradientSegment *seg)
{
GimpGradientSegment *tmp;
g_return_if_fail (seg != NULL);
while (seg)
{
tmp = seg->next;
gimp_gradient_segment_free (seg);
seg = tmp;
}
}
GimpGradientSegment *
gimp_gradient_segment_get_last (GimpGradientSegment *seg)
{
if (!seg)
return NULL;
while (seg->next)
seg = seg->next;
return seg;
}
GimpGradientSegment *
gimp_gradient_segment_get_first (GimpGradientSegment *seg)
{
if (!seg)
return NULL;
while (seg->prev)
seg = seg->prev;
return seg;
}
void
gimp_gradient_segment_split_midpoint (GimpGradient *gradient,
GimpGradientSegment *lseg,
GimpGradientSegment **newl,
GimpGradientSegment **newr)
{
GimpRGB color;
GimpGradientSegment *newseg;
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (lseg != NULL);
g_return_if_fail (newl != NULL);
g_return_if_fail (newr != NULL);
/* Get color at original segment's midpoint */
gimp_gradient_get_color_at (gradient, lseg->middle, &color);
/* Create a new segment and insert it in the list */
newseg = gimp_gradient_segment_new ();
newseg->prev = lseg;
newseg->next = lseg->next;
lseg->next = newseg;
if (newseg->next)
newseg->next->prev = newseg;
/* Set coordinates of new segment */
newseg->left = lseg->middle;
newseg->right = lseg->right;
newseg->middle = (newseg->left + newseg->right) / 2.0;
/* Set coordinates of original segment */
lseg->right = newseg->left;
lseg->middle = (lseg->left + lseg->right) / 2.0;
/* Set colors of both segments */
newseg->right_color = lseg->right_color;
lseg->right_color.r = newseg->left_color.r = color.r;
lseg->right_color.g = newseg->left_color.g = color.g;
lseg->right_color.b = newseg->left_color.b = color.b;
lseg->right_color.a = newseg->left_color.a = color.a;
/* Set parameters of new segment */
newseg->type = lseg->type;
newseg->color = lseg->color;
/* Done */
*newl = lseg;
*newr = newseg;
}
void
gimp_gradient_segment_split_uniform (GimpGradient *gradient,
GimpGradientSegment *lseg,
gint parts,
GimpGradientSegment **newl,
GimpGradientSegment **newr)
{
GimpGradientSegment *seg, *prev, *tmp;
gdouble seg_len;
gint i;
g_return_if_fail (GIMP_IS_GRADIENT (gradient));
g_return_if_fail (lseg != NULL);
g_return_if_fail (newl != NULL);
g_return_if_fail (newr != NULL);
seg_len = (lseg->right - lseg->left) / parts; /* Length of divisions */
seg = NULL;
prev = NULL;
tmp = NULL;
for (i = 0; i < parts; i++)
{
seg = gimp_gradient_segment_new ();
if (i == 0)
tmp = seg; /* Remember first segment */
seg->left = lseg->left + i * seg_len;
seg->right = lseg->left + (i + 1) * seg_len;
seg->middle = (seg->left + seg->right) / 2.0;
gimp_gradient_get_color_at (gradient, seg->left, &seg->left_color);
gimp_gradient_get_color_at (gradient, seg->right, &seg->right_color);
seg->type = lseg->type;
seg->color = lseg->color;
seg->prev = prev;
seg->next = NULL;
if (prev)
prev->next = seg;
prev = seg;
}
/* Fix edges */
tmp->left_color = lseg->left_color;
seg->right_color = lseg->right_color;
tmp->left = lseg->left;
seg->right = lseg->right; /* To squish accumulative error */
/* Link in list */
tmp->prev = lseg->prev;
seg->next = lseg->next;
if (lseg->prev)
lseg->prev->next = tmp;
else
gradient->segments = tmp; /* We are on leftmost segment */
if (lseg->next)
lseg->next->prev = seg;
gradient->last_visited = NULL; /* Force re-search */
/* Done */
*newl = tmp;
*newr = seg;
/* Delete old segment */
gimp_gradient_segment_free (lseg);
}
void
gimp_gradient_segments_compress_range (GimpGradientSegment *range_l,
GimpGradientSegment *range_r,
gdouble new_l,
gdouble new_r)
{
gdouble orig_l, orig_r;
gdouble scale;
GimpGradientSegment *seg, *aseg;
g_return_if_fail (range_l != NULL);
g_return_if_fail (range_r != NULL);
orig_l = range_l->left;
orig_r = range_r->right;
scale = (new_r - new_l) / (orig_r - orig_l);
seg = range_l;
do
{
seg->left = new_l + (seg->left - orig_l) * scale;
seg->middle = new_l + (seg->middle - orig_l) * scale;
seg->right = new_l + (seg->right - orig_l) * scale;
/* Next */
aseg = seg;
seg = seg->next;
}
while (aseg != range_r);
}
void
gimp_gradient_segments_blend_endpoints (GimpGradientSegment *lseg,
GimpGradientSegment *rseg,
GimpRGB *rgb1,
GimpRGB *rgb2,
gboolean blend_colors,
gboolean blend_opacity)
{
GimpRGB d;
gdouble left, len;
GimpGradientSegment *seg;
GimpGradientSegment *aseg;
g_return_if_fail (lseg != NULL);
g_return_if_fail (rseg != NULL);
d.r = rgb2->r - rgb1->r;
d.g = rgb2->g - rgb1->g;
d.b = rgb2->b - rgb1->b;
d.a = rgb2->a - rgb1->a;
left = lseg->left;
len = rseg->right - left;
seg = lseg;
do
{
if (blend_colors)
{
seg->left_color.r = rgb1->r + (seg->left - left) / len * d.r;
seg->left_color.g = rgb1->g + (seg->left - left) / len * d.g;
seg->left_color.b = rgb1->b + (seg->left - left) / len * d.b;
seg->right_color.r = rgb1->r + (seg->right - left) / len * d.r;
seg->right_color.g = rgb1->g + (seg->right - left) / len * d.g;
seg->right_color.b = rgb1->b + (seg->right - left) / len * d.b;
}
if (blend_opacity)
{
seg->left_color.a = rgb1->a + (seg->left - left) / len * d.a;
seg->right_color.a = rgb1->a + (seg->right - left) / len * d.a;
}
aseg = seg;
seg = seg->next;
}
while (aseg != rseg);
}