Commit 776b3a61 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

removed. new object derived from GimpObject. Just used as a container at

2001-01-21  Michael Natterer  <mitch@gimp.org>

	* app/palette_entries.h: removed.
	* app/gimppalette.[ch]: new object derived from GimpObject. Just
	used as a container at the moment (no signals or stuff used).

	* app/palette.[ch]: changed almost every line except in the
	import_dialog part.

	* app/Makefile.am
	* app/apptypes.h
	* app/convert.[ch]
	* app/gimpdnd.h
	* app/paletteP.h
	* app/palette_select.[ch]
	* app/convert_cmds.c
	* tools/pdbgen/pdb/convert.pdb: changed accordingly.

	* app/gimpdrawable.c: set klass->removed to NULL.
parent f96d3776
2001-01-21 Michael Natterer <mitch@gimp.org>
* app/palette_entries.h: removed.
* app/gimppalette.[ch]: new object derived from GimpObject. Just
used as a container at the moment (no signals or stuff used).
* app/palette.[ch]: changed almost every line except in the
import_dialog part.
* app/Makefile.am
* app/apptypes.h
* app/convert.[ch]
* app/gimpdnd.h
* app/paletteP.h
* app/palette_select.[ch]
* app/convert_cmds.c
* tools/pdbgen/pdb/convert.pdb: changed accordingly.
* app/gimpdrawable.c: set klass->removed to NULL.
2001-01-21 Michael Natterer <mitch@gimp.org>
* app/color_notebook.[ch]: added a "title" parameter to the
......
......@@ -191,6 +191,8 @@ gimp_SOURCES = \
gimplist.h \
gimplut.c \
gimplut.h \
gimppalette.c \
gimppalette.h \
gimpparasite.c \
gimpparasite.h \
gimpprogress.c \
......@@ -284,7 +286,6 @@ gimp_SOURCES = \
ops_buttons.c \
ops_buttons.h \
palette.c \
palette_entries.h \
palette.h \
palette_cmds.c \
palette_select.c \
......
......@@ -63,6 +63,8 @@ typedef struct _GimpBrushList GimpBrushList;
typedef struct _GimpBrushGenerated GimpBrushGenerated;
typedef struct _GimpBrushPipe GimpBrushPipe;
typedef struct _GimpPalette GimpPalette;
/* widgets */
......@@ -108,9 +110,6 @@ typedef struct _InfoDialog InfoDialog;
typedef struct _PaintCore PaintCore;
typedef struct _PaletteEntries PaletteEntries;
typedef struct _PaletteEntry PaletteEntry;
typedef struct _Path Path;
typedef struct _PathPoint PathPoint;
typedef struct _PathList PathList;
......
......@@ -110,7 +110,7 @@
#include "levels.h"
#include "undo.h"
#include "palette.h"
#include "palette_entries.h"
#include "gimppalette.h"
#include "palette_select.h"
#include "pixel_region.h"
#include "posterize.h"
......@@ -443,7 +443,7 @@ static GtkWidget *build_palette_button (void);
static gboolean UserHasWebPal = FALSE;
PaletteEntries *theCustomPalette = NULL;
GimpPalette *theCustomPalette = NULL;
/* Defaults */
......@@ -795,49 +795,50 @@ convert_to_indexed (GimpImage *gimage)
static GtkWidget *
build_palette_button (void)
{
GSList *list;
PaletteEntries *entries;
PaletteEntries *theWebPalette = NULL;
int i, default_palette;
GSList *list;
GimpPalette *palette;
GimpPalette *theWebPalette = NULL;
gint i;
gint default_palette;
UserHasWebPal = FALSE;
if (!palette_entries_list)
if (!palettes_list)
{
palettes_init (FALSE);
}
list = palette_entries_list;
list = palettes_list;
if (!list)
{
return NULL;
}
for (i = 0, list = palette_entries_list, default_palette = -1;
for (i = 0, list = palettes_list, default_palette = -1;
list;
i++, list = g_slist_next (list))
{
entries = (PaletteEntries *) list->data;
palette = (GimpPalette *) list->data;
/* Preferentially, the initial default is 'Web' if available */
if (theWebPalette == NULL &&
g_strcasecmp (entries->name, "Web") == 0)
g_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
{
theWebPalette = entries;
theWebPalette = palette;
UserHasWebPal = TRUE;
}
/* We can't dither to > 256 colors */
if (entries->n_colors <= 256)
if (palette->n_colors <= 256)
{
if (theCustomPalette == entries)
if (theCustomPalette == palette)
{
default_palette = i;
}
}
}
/* default to first one with <= 256 colors
(only used if 'web' palette not available) */
if (default_palette == -1)
......@@ -849,15 +850,15 @@ build_palette_button (void)
}
else
{
for (i = 0, list = palette_entries_list;
for (i = 0, list = palettes_list;
list && default_palette == -1;
i++, list = g_slist_next (list))
{
entries = (PaletteEntries *) list->data;
if (entries->n_colors <= 256)
palette = (GimpPalette *) list->data;
if (palette->n_colors <= 256)
{
theCustomPalette = entries;
theCustomPalette = palette;
default_palette = i;
}
}
......@@ -867,7 +868,7 @@ build_palette_button (void)
if (default_palette == -1)
return NULL;
else
return gtk_button_new_with_label (theCustomPalette->name);
return gtk_button_new_with_label (GIMP_OBJECT (theCustomPalette)->name);
}
......@@ -970,22 +971,24 @@ indexed_palette_select_row_callback (GtkCList *clist,
gpointer data)
{
IndexedDialog *dialog = (IndexedDialog *)data;
PaletteEntries *p_entries;
GimpPalette *palette;
palette = (GimpPalette *) gtk_clist_get_row_data (clist, row);
p_entries = (PaletteEntries *) gtk_clist_get_row_data (clist, row);
if (p_entries)
if (palette)
{
if (p_entries->n_colors <= 256)
if (palette->n_colors <= 256)
{
theCustomPalette = p_entries;
gtk_label_set_text (GTK_LABEL (GTK_BIN(dialog->custom_palette_button)->child),
theCustomPalette->name);
theCustomPalette = palette;
gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child),
GIMP_OBJECT (theCustomPalette)->name);
}
else
{
gtk_clist_unselect_row (clist, row, column);
}
}
return FALSE;
}
......@@ -998,8 +1001,9 @@ indexed_custom_palette_button_callback (GtkWidget *widget,
if (dialog->palette_select == NULL)
{
dialog->palette_select = palette_select_new (_("Select Custom Palette"),
theCustomPalette->name);
dialog->palette_select =
palette_select_new (_("Select Custom Palette"),
GIMP_OBJECT (theCustomPalette)->name);
gtk_signal_connect (GTK_OBJECT (dialog->palette_select->shell), "destroy",
GTK_SIGNAL_FUNC (indexed_palette_select_destroy_callback),
......@@ -2960,19 +2964,19 @@ webpal_pass1 (QuantizeObj *quantobj)
static void
custompal_pass1 (QuantizeObj *quantobj)
{
gint i;
GSList *list;
PaletteEntry *entry;
guchar r, g, b;
gint i;
GList *list;
GimpPaletteEntry *entry;
guchar r, g, b;
/* fprintf(stderr, "custompal_pass1: using (theCustomPalette %s) from (file %s)\n",
theCustomPalette->name, theCustomPalette->filename); */
for (i=0,list=theCustomPalette->colors;
for (i = 0, list = theCustomPalette->colors;
list;
i++,list=g_slist_next(list))
i++, list = g_list_next (list))
{
entry = (PaletteEntry *) list->data;
entry = (GimpPaletteEntry *) list->data;
gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
......
......@@ -43,21 +43,22 @@ typedef enum
#define MAXNUMCOLORS 256
/* convert functions */
void convert_to_rgb (GimpImage *gimage);
void convert_to_grayscale (GimpImage *gimage);
void convert_to_indexed (GimpImage *gimage);
void convert_to_rgb (GimpImage *gimage);
void convert_to_grayscale (GimpImage *gimage);
void convert_to_indexed (GimpImage *gimage);
void convert_image (GimpImage *gimage,
GimpImageBaseType ,
gint num_cols,
ConvertDitherType ,
gint alpha_dither,
gint remdups,
ConvertPaletteType );
void convert_image (GimpImage *gimage,
GimpImageBaseType ,
gint num_cols,
ConvertDitherType ,
gint alpha_dither,
gint remdups,
ConvertPaletteType );
extern PaletteEntries *theCustomPalette;
extern GimpPalette *theCustomPalette;
#endif /* __CONVERT_H__ */
......@@ -29,8 +29,8 @@
#include "convert.h"
#include "gimpimage.h"
#include "gimppalette.h"
#include "palette.h"
#include "palette_entries.h"
static ProcRecord convert_rgb_proc;
static ProcRecord convert_grayscale_proc;
......@@ -164,9 +164,9 @@ convert_indexed_invoker (Argument *args)
{
if ((success = (gimp_image_base_type (gimage) != INDEXED)))
{
PaletteEntries *entries;
PaletteEntries *the_palette = NULL;
GSList *list;
GimpPalette *palette;
GimpPalette *the_palette = NULL;
GSList *list;
switch (dither_type)
{
......@@ -193,15 +193,16 @@ convert_indexed_invoker (Argument *args)
break;
case CUSTOM_PALETTE:
if (!palette_entries_list)
if (! palettes_list)
palettes_init (FALSE);
for (list = palette_entries_list; list; list = list->next)
for (list = palettes_list; list; list = list->next)
{
entries = (PaletteEntries *) list->data;
if (!strcmp (palette_name, entries->name))
palette = (GimpPalette *) list->data;
if (!strcmp (palette_name, GIMP_OBJECT (palette)->name))
{
the_palette = entries;
the_palette = palette;
break;
}
}
......
......@@ -131,6 +131,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
gimp_object_class->name_changed = gimp_drawable_name_changed;
klass->removed = NULL;
klass->invalidate_preview = NULL;
}
......
......@@ -110,7 +110,7 @@
#include "levels.h"
#include "undo.h"
#include "palette.h"
#include "palette_entries.h"
#include "gimppalette.h"
#include "palette_select.h"
#include "pixel_region.h"
#include "posterize.h"
......@@ -443,7 +443,7 @@ static GtkWidget *build_palette_button (void);
static gboolean UserHasWebPal = FALSE;
PaletteEntries *theCustomPalette = NULL;
GimpPalette *theCustomPalette = NULL;
/* Defaults */
......@@ -795,49 +795,50 @@ convert_to_indexed (GimpImage *gimage)
static GtkWidget *
build_palette_button (void)
{
GSList *list;
PaletteEntries *entries;
PaletteEntries *theWebPalette = NULL;
int i, default_palette;
GSList *list;
GimpPalette *palette;
GimpPalette *theWebPalette = NULL;
gint i;
gint default_palette;
UserHasWebPal = FALSE;
if (!palette_entries_list)
if (!palettes_list)
{
palettes_init (FALSE);
}
list = palette_entries_list;
list = palettes_list;
if (!list)
{
return NULL;
}
for (i = 0, list = palette_entries_list, default_palette = -1;
for (i = 0, list = palettes_list, default_palette = -1;
list;
i++, list = g_slist_next (list))
{
entries = (PaletteEntries *) list->data;
palette = (GimpPalette *) list->data;
/* Preferentially, the initial default is 'Web' if available */
if (theWebPalette == NULL &&
g_strcasecmp (entries->name, "Web") == 0)
g_strcasecmp (GIMP_OBJECT (palette)->name, "Web") == 0)
{
theWebPalette = entries;
theWebPalette = palette;
UserHasWebPal = TRUE;
}
/* We can't dither to > 256 colors */
if (entries->n_colors <= 256)
if (palette->n_colors <= 256)
{
if (theCustomPalette == entries)
if (theCustomPalette == palette)
{
default_palette = i;
}
}
}
/* default to first one with <= 256 colors
(only used if 'web' palette not available) */
if (default_palette == -1)
......@@ -849,15 +850,15 @@ build_palette_button (void)
}
else
{
for (i = 0, list = palette_entries_list;
for (i = 0, list = palettes_list;
list && default_palette == -1;
i++, list = g_slist_next (list))
{
entries = (PaletteEntries *) list->data;
if (entries->n_colors <= 256)
palette = (GimpPalette *) list->data;
if (palette->n_colors <= 256)
{
theCustomPalette = entries;
theCustomPalette = palette;
default_palette = i;
}
}
......@@ -867,7 +868,7 @@ build_palette_button (void)
if (default_palette == -1)
return NULL;
else
return gtk_button_new_with_label (theCustomPalette->name);
return gtk_button_new_with_label (GIMP_OBJECT (theCustomPalette)->name);
}
......@@ -970,22 +971,24 @@ indexed_palette_select_row_callback (GtkCList *clist,
gpointer data)
{
IndexedDialog *dialog = (IndexedDialog *)data;
PaletteEntries *p_entries;
GimpPalette *palette;
palette = (GimpPalette *) gtk_clist_get_row_data (clist, row);
p_entries = (PaletteEntries *) gtk_clist_get_row_data (clist, row);
if (p_entries)
if (palette)
{
if (p_entries->n_colors <= 256)
if (palette->n_colors <= 256)
{
theCustomPalette = p_entries;
gtk_label_set_text (GTK_LABEL (GTK_BIN(dialog->custom_palette_button)->child),
theCustomPalette->name);
theCustomPalette = palette;
gtk_label_set_text (GTK_LABEL (GTK_BIN (dialog->custom_palette_button)->child),
GIMP_OBJECT (theCustomPalette)->name);
}
else
{
gtk_clist_unselect_row (clist, row, column);
}
}
return FALSE;
}
......@@ -998,8 +1001,9 @@ indexed_custom_palette_button_callback (GtkWidget *widget,
if (dialog->palette_select == NULL)
{
dialog->palette_select = palette_select_new (_("Select Custom Palette"),
theCustomPalette->name);
dialog->palette_select =
palette_select_new (_("Select Custom Palette"),
GIMP_OBJECT (theCustomPalette)->name);
gtk_signal_connect (GTK_OBJECT (dialog->palette_select->shell), "destroy",
GTK_SIGNAL_FUNC (indexed_palette_select_destroy_callback),
......@@ -2960,19 +2964,19 @@ webpal_pass1 (QuantizeObj *quantobj)
static void
custompal_pass1 (QuantizeObj *quantobj)
{
gint i;
GSList *list;
PaletteEntry *entry;
guchar r, g, b;
gint i;
GList *list;
GimpPaletteEntry *entry;
guchar r, g, b;
/* fprintf(stderr, "custompal_pass1: using (theCustomPalette %s) from (file %s)\n",
theCustomPalette->name, theCustomPalette->filename); */
for (i=0,list=theCustomPalette->colors;
for (i = 0, list = theCustomPalette->colors;
list;
i++,list=g_slist_next(list))
i++, list = g_list_next (list))
{
entry = (PaletteEntry *) list->data;
entry = (GimpPaletteEntry *) list->data;
gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
......
......@@ -43,21 +43,22 @@ typedef enum
#define MAXNUMCOLORS 256
/* convert functions */
void convert_to_rgb (GimpImage *gimage);
void convert_to_grayscale (GimpImage *gimage);
void convert_to_indexed (GimpImage *gimage);
void convert_to_rgb (GimpImage *gimage);
void convert_to_grayscale (GimpImage *gimage);
void convert_to_indexed (GimpImage *gimage);
void convert_image (GimpImage *gimage,
GimpImageBaseType ,
gint num_cols,
ConvertDitherType ,
gint alpha_dither,
gint remdups,
ConvertPaletteType );
void convert_image (GimpImage *gimage,
GimpImageBaseType ,
gint num_cols,
ConvertDitherType ,
gint alpha_dither,
gint remdups,
ConvertPaletteType );
extern PaletteEntries *theCustomPalette;
extern GimpPalette *theCustomPalette;
#endif /* __CONVERT_H__ */
/* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include "apptypes.h"
#include "gimppalette.h"
#include "gimprc.h"
#include "palette_select.h"
#include "libgimp/gimpenv.h"
#include "libgimp/gimpintl.h"
enum
{
CHANGED,
LAST_SIGNAL
};
/* local function prototypes */
static void gimp_palette_class_init (GimpPaletteClass *klass);
static void gimp_palette_init (GimpPalette *palette);
static void gimp_palette_destroy (GtkObject *object);
static void gimp_palette_entry_free (GimpPaletteEntry *entry);
/* private variables */
static guint gimp_palette_signals[LAST_SIGNAL] = { 0 };
static GimpObjectClass *parent_class = NULL;
GtkType
gimp_palette_get_type (void)
{
static GtkType palette_type = 0;
if (! palette_type)
{
GtkTypeInfo palette_info =
{
"GimpPalette",
sizeof (GimpPalette),
sizeof (GimpPaletteClass),
(GtkClassInitFunc) gimp_palette_class_init,
(GtkObjectInitFunc) gimp_palette_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
palette_type = gtk_type_unique (GIMP_TYPE_OBJECT, &palette_info);
}
return palette_type;
}
static void
gimp_palette_class_init (GimpPaletteClass *klass)
{
GtkObjectClass *object_class;
GimpObjectClass *gimp_object_class;
object_class = (GtkObjectClass *) klass;
gimp_object_class = (GimpObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_OBJECT);
gimp_palette_signals[CHANGED] =
gtk_signal_new ("changed",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpPaletteClass,
changed),
gtk_signal_default_marshaller,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, gimp_palette_signals,
LAST_SIGNAL);
object_class->destroy = gimp_palette_destroy;
klass->changed = NULL;
}
static void
gimp_palette_init (GimpPalette *palette)
{
palette->filename = NULL;
palette->colors = NULL;
palette->n_colors = 0;
palette->changed = TRUE;
palette->pixmap = NULL;
}
static void
gimp_palette_destroy (GtkObject *object)
{
GimpPalette *palette;
GimpPaletteEntry *entry;
GList *list;
g_return_if_fail (GIMP_IS_PALETTE (object));
palette = GIMP_PALETTE (object);
for (list = palette->colors; list; list = g_list_next (list))
{
entry = (GimpPaletteEntry *) list->data;
gimp_palette_entry_free (entry);
}
g_list_free (palette->colors);
g_free (palette->filename);
if (palette->pixmap)
gdk_pixmap_unref (palette->pixmap);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
GimpPalette *
gimp_palette_new (const gchar *name)
{
GimpPalette *palette = NULL;
GList *pal_path;
gchar *pal_dir;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (*name != '\0', NULL);
if (!name || !palette_path)
return NULL;
pal_path = gimp_path_parse (palette_path, 16, TRUE, NULL);
pal_dir = gimp_path_get_user_writable_dir (pal_path);
gimp_path_free (pal_path);
palette = GIMP_PALETTE (gtk_object_new (GIMP_TYPE_PALETTE,
"name", name,
NULL));
if (pal_dir)
{
palette->filename = g_strdup_printf ("%s%s", pal_dir, name);
g_free (pal_dir);
}
return palette;
}
GimpPalette *
gimp_palette_new_from_file (const gchar *filename)
{
GimpPalette *palette;
gchar str[512];
gchar *tok;
FILE *fp;
gint r, g, b;
GimpRGB color;
gint linenum;