Commit 2683c3f2 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

fixed some brokenness caused by my last "cleanup". Should work as before

2005-09-24  Michael Natterer  <mitch@gimp.org>

	* plug-ins/common/compose.c: fixed some brokenness caused by my
	last "cleanup". Should work as before now.

	* plug-ins/common/decompose.c: cleaned up GUI and code.
parent f94f48f1
2005-09-24 Michael Natterer <mitch@gimp.org>
* plug-ins/common/compose.c: fixed some brokenness caused by my
last "cleanup". Should work as before now.
* plug-ins/common/decompose.c: cleaned up GUI and code.
2005-09-24 DindinX <dindinx@gimp.org>
* app/widgets/widgets-enums.h: Moved the GimpZoomType enum from
......
......@@ -168,7 +168,8 @@ typedef struct
const gchar *channel_name[MAX_COMPOSE_IMAGES];
const gchar *channel_icon[MAX_COMPOSE_IMAGES];
const gchar *filename; /* Name of new image */
/* Compose functon */
/* Compose functon */
void (* compose_fun) (guchar **src,
gint *incr_src,
gint numpix,
......@@ -190,6 +191,7 @@ static COMPOSE_DSC compose_dsc[] =
GIMP_STOCK_CHANNEL_BLUE,
NULL },
"rgb-compose", compose_rgb },
{ N_("RGBA"), 4,
{ N_("_Red:"),
N_("_Green:"),
......@@ -200,20 +202,23 @@ static COMPOSE_DSC compose_dsc[] =
GIMP_STOCK_CHANNEL_BLUE,
GIMP_STOCK_CHANNEL_ALPHA },
"rgba-compose", compose_rgba },
{ N_("HSV"), 3,
{ N_("HSV"), 3,
{ N_("_Hue:"),
N_("_Saturation:"),
N_("_Value:"),
NULL },
{ NULL, NULL, NULL, NULL },
"hsv-compose", compose_hsv },
{ N_("CMY"), 3,
{ N_("CMY"), 3,
{ N_("_Cyan:"),
N_("_Magenta:"),
N_("_Yellow:"),
NULL },
{ NULL, NULL, NULL, NULL },
"cmy-compose", compose_cmy },
{ N_("CMYK"), 4,
{ N_("_Cyan:"),
N_("_Magenta:"),
......@@ -221,6 +226,7 @@ static COMPOSE_DSC compose_dsc[] =
N_("_Black:") },
{ NULL, NULL, NULL, NULL },
"cmyk-compose", compose_cmyk },
{ N_("LAB"), 3,
{ "_L:",
"_A:",
......@@ -228,28 +234,32 @@ static COMPOSE_DSC compose_dsc[] =
NULL },
{ NULL, NULL, NULL, NULL },
"lab-compose", compose_lab },
{ "YCbCr ITU R470", 3,
{ "YCbCr_ITU_R470", 3,
{ N_("_Luma y470:"),
N_("_Blueness cb470:"),
N_("_Redness cr470:"),
NULL },
{ NULL, NULL, NULL, NULL },
"ycbcr470-compose", compose_ycbcr470 },
{ "YCbCr ITU R709", 3,
{ "YCbCr_ITU_R709", 3,
{ N_("_Luma y709:"),
N_("_Blueness cb709:"),
N_("_Redness cr709:"),
NULL },
{ NULL, NULL, NULL, NULL },
"ycbcr709-compose", compose_ycbcr709 },
{ "YCbCr ITU R470 256", 3,
{ "YCbCr_ITU_R470_256", 3,
{ N_("_Luma y470f:"),
N_("_Blueness cb470f:"),
N_("_Redness cr470f:"),
NULL },
{ NULL, NULL, NULL, NULL },
"ycbcr470F-compose", compose_ycbcr470f },
{ "YCbCr ITU R709 256", 3,
{ "YCbCr_ITU_R709_256", 3,
{ N_("_Luma y709f:"),
N_("_Blueness cb709f:"),
N_("_Redness cr709f:"),
......@@ -280,7 +290,7 @@ typedef struct
ComposeInput selected[MAX_COMPOSE_IMAGES]; /* Image Ids or mask values from menus */
gint compose_type; /* Compose type */
gint compose_idx; /* Compose type */
} ComposeInterface;
GimpPlugInInfo PLUG_IN_INFO =
......@@ -546,11 +556,13 @@ run (const gchar *name,
status = GIMP_PDB_CALLING_ERROR;
break;
}
composevals.inputs[i].is_ID = FALSE;
composevals.inputs[i].is_ID = FALSE;
composevals.inputs[i].comp.val = param[7 + i].data.d_int8;
}
else
composevals.inputs[i].is_ID = TRUE;
{
composevals.inputs[i].is_ID = TRUE;
}
}
}
break;
......@@ -677,8 +689,8 @@ compose (const gchar *compose_type,
return -1;
}
if ((width != (gint)gimp_drawable_width (inputs[j].comp.ID)) ||
(height != (gint)gimp_drawable_height (inputs[j].comp.ID)))
if ((width != gimp_drawable_width (inputs[j].comp.ID)) ||
(height != gimp_drawable_height (inputs[j].comp.ID)))
{
g_message (_("Drawables have different size"));
return -1;
......@@ -695,7 +707,7 @@ compose (const gchar *compose_type,
}
else /* Compose by image ID */
{
width = gimp_image_width (inputs[first_ID].comp.ID);
width = gimp_image_width (inputs[first_ID].comp.ID);
height = gimp_image_height (inputs[first_ID].comp.ID);
for (j = first_ID + 1; j < num_images; j++)
......@@ -784,7 +796,6 @@ compose (const gchar *compose_type,
drawable_dst->height,
FALSE, FALSE);
image_ID_dst = gimp_drawable_get_image (layer_ID_dst);
}
else
{
......@@ -1377,22 +1388,19 @@ compose_dialog (const gchar *compose_type,
gint32 *layer_list;
gint nlayers;
gint j;
gint compose_idx;
gboolean run;
/* Check default compose type */
composeint.compose_type = 0;
composeint.compose_idx = 0;
for (j = 0; j < G_N_ELEMENTS (compose_dsc); j++)
{
if (g_ascii_strcasecmp (compose_type, compose_dsc[j].compose_type) == 0)
{
composeint.compose_type = j;
composeint.compose_idx = j;
break;
}
}
compose_idx = composeint.compose_type;
/* Save original image width/height */
composeint.width = gimp_drawable_width (drawable_ID);
composeint.height = gimp_drawable_height (drawable_ID);
......@@ -1439,7 +1447,7 @@ compose_dialog (const gchar *compose_type,
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
label = gtk_label_new_with_mnemonic (_("Color _Model:"));
label = gtk_label_new_with_mnemonic (_("Color _model:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
......@@ -1450,12 +1458,18 @@ compose_dialog (const gchar *compose_type,
combo = gimp_int_combo_box_new (NULL, 0);
for (j = 0; j < G_N_ELEMENTS (compose_dsc); j++)
{
gchar *label = g_strdup (gettext (compose_dsc[j].compose_type));
gchar *l;
for (l = label; *l; l++)
if (*l == '-' || *l == '_')
*l = ' ';
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (combo),
GIMP_INT_STORE_LABEL,
gettext (compose_dsc[j].compose_type),
GIMP_INT_STORE_VALUE,
j,
GIMP_INT_STORE_LABEL, label,
GIMP_INT_STORE_VALUE, j,
-1);
g_free (label);
}
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
gtk_widget_show (combo);
......@@ -1504,7 +1518,7 @@ compose_dialog (const gchar *compose_type,
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
if (nlayers >= compose_dsc[compose_idx].num_images)
if (nlayers >= compose_dsc[composeint.compose_idx].num_images)
composeint.selected[j].comp.ID = layer_list[nlayers - (j + 1)];
else
composeint.selected[j].comp.ID = drawable_ID;
......@@ -1557,7 +1571,7 @@ compose_dialog (const gchar *compose_type,
/* Calls the combo callback and sets icons, labels and sensitivity */
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
composeint.compose_type,
composeint.compose_idx,
G_CALLBACK (type_combo_callback),
NULL);
......@@ -1581,7 +1595,8 @@ compose_dialog (const gchar *compose_type,
composevals.inputs[j].comp.val = composeint.selected[j].comp.val;
}
strcpy (composevals.compose_type, compose_dsc[compose_idx].compose_type);
strcpy (composevals.compose_type,
compose_dsc[composeint.compose_idx].compose_type);
}
return run;
......@@ -1613,7 +1628,7 @@ check_response (GtkWidget *dialog,
gint nb = 0;
gboolean has_image = FALSE;
nb = compose_dsc[composeint.compose_type].num_images;
nb = compose_dsc[composeint.compose_idx].num_images;
for (i = 0; i < nb; i++)
{
......@@ -1687,14 +1702,14 @@ static void
type_combo_callback (GimpIntComboBox *combo,
gpointer data)
{
if (gimp_int_combo_box_get_active (combo, &composeint.compose_type))
if (gimp_int_combo_box_get_active (combo, &composeint.compose_idx))
{
const gchar *text;
gboolean combo4;
gboolean scale4;
gint compose_idx, j;
compose_idx = composeint.compose_type;
compose_idx = composeint.compose_idx;
for (j = 0; j < MAX_COMPOSE_IMAGES; j++)
{
......
......@@ -108,80 +108,94 @@ static void extract_ycbcr709f(guchar *src, gint bpp, gint numpix, guchar **dst);
static gboolean decompose_dialog (void);
/* LAB colorspace constants */
static const gdouble Xn = 0.951;
static const gdouble Yn = 1.0;
static const gdouble Zn = 1.089;
/* Maximum number of new images generated by an extraction */
/* Maximum number of images/layers generated by an extraction */
#define MAX_EXTRACT_IMAGES 4
/* Description of an extraction */
typedef struct
{
gchar *type; /* What to extract */
gint dialog; /* Dialog-Flag. Set it to 1 if you want to appear */
/* this extract function within the dialog */
gint num_images; /* Number of images to create */
gchar *channel_name[MAX_EXTRACT_IMAGES]; /* Names of channels to extract */
/* Function that performs the extraction */
void (*extract_fun) (guchar *src, int bpp, gint numpix, guchar **dst);
gchar *type; /* What to extract */
gboolean dialog; /* Dialog-Flag. Set it to TRUE if you want to appear
* this extract function within the dialog */
gint num_images; /* Number of images to create */
/* Names of channels to extract */
gchar *channel_name[MAX_EXTRACT_IMAGES];
/* Function that performs the extraction */
void (* extract_fun) (guchar *src,
int bpp,
gint numpix,
guchar **dst);
} EXTRACT;
static EXTRACT extract[] =
{
{ N_("RGB"), TRUE, 3, { N_("red"),
N_("green"),
N_("blue") }, extract_rgb },
{ N_("Red"), FALSE, 1, { N_("red") }, extract_red },
N_("green"),
N_("blue") }, extract_rgb },
{ N_("Red"), FALSE, 1, { N_("red") }, extract_red },
{ N_("Green"), FALSE, 1, { N_("green") }, extract_green },
{ N_("Blue"), FALSE, 1, { N_("blue") }, extract_blue },
{ N_("RGBA"), TRUE, 4, { N_("red"),
N_("green"),
N_("blue"),
N_("alpha") }, extract_rgba },
{ N_("Blue"), FALSE, 1, { N_("blue") }, extract_blue },
N_("green"),
N_("blue"),
N_("alpha") }, extract_rgba },
{ N_("HSV"), TRUE, 3, { N_("hue"),
N_("saturation"),
N_("value") }, extract_hsv },
{ N_("Hue"), FALSE, 1, { N_("hue") }, extract_hue },
N_("saturation"),
N_("value") }, extract_hsv },
{ N_("Hue"), FALSE, 1, { N_("hue") }, extract_hue },
{ N_("Saturation"), FALSE, 1, { N_("saturation") }, extract_sat },
{ N_("Value"), FALSE, 1, { N_("value") }, extract_val },
{ N_("Value"), FALSE, 1, { N_("value") }, extract_val },
{ N_("CMY"), TRUE, 3, { N_("cyan"),
N_("magenta"),
N_("yellow") }, extract_cmy },
{ N_("Cyan"), FALSE, 1, { N_("cyan") }, extract_cyan },
N_("magenta"),
N_("yellow") }, extract_cmy },
{ N_("Cyan"), FALSE, 1, { N_("cyan") }, extract_cyan },
{ N_("Magenta"), FALSE, 1, { N_("magenta") }, extract_magenta },
{ N_("Yellow"), FALSE, 1, { N_("yellow") }, extract_yellow },
{ N_("CMYK"), TRUE, 4, { N_("cyan_k"),
N_("magenta_k"),
N_("yellow_k"),
N_("black") }, extract_cmyk },
{ N_("Cyan_K"), FALSE, 1, { N_("cyan_k") }, extract_cyank },
{ N_("Magenta_K"), FALSE, 1, { N_("magenta_k") }, extract_magentak },
{ N_("Yellow_K"), FALSE, 1, { N_("yellow_k") }, extract_yellowk },
{ N_("Yellow"), FALSE, 1, { N_("yellow") }, extract_yellow },
{ N_("CMYK"), TRUE, 4, { N_("cyan-k"),
N_("magenta-k"),
N_("yellow-k"),
N_("black") }, extract_cmyk },
{ N_("Cyan_K"), FALSE, 1, { N_("cyan-k") }, extract_cyank },
{ N_("Magenta_K"), FALSE, 1, { N_("magenta-k") }, extract_magentak },
{ N_("Yellow_K"), FALSE, 1, { N_("yellow-k") }, extract_yellowk },
{ N_("Alpha"), TRUE, 1, { N_("alpha") }, extract_alpha },
{ N_("LAB"), TRUE, 3, { "L",
"A",
"B" }, extract_lab },
{ "YCbCr_ITU_R470",
TRUE, 3, { N_("luma_y470"),
N_("blueness_cb470"),
N_("redness_cr470") }, extract_ycbcr470 },
{ "YCbCr_ITU_R709",
TRUE, 3, { N_("luma_y709"),
N_("blueness_cb709"),
N_("redness_cr709") }, extract_ycbcr709 },
{ "YCbCr_ITU_R470_256",
TRUE, 3, { N_("luma_y470f"),
N_("blueness_cb470f"),
N_("redness_cr470f") }, extract_ycbcr470f },
{ "YCbCr_ITU_R709_256",
TRUE, 3, { N_("luma_y709f"),
N_("blueness_cb709f"),
N_("redness_cr709f") }, extract_ycbcr709f },
{ "YCbCr_ITU_R470", TRUE, 3, { N_("luma-y470"),
N_("blueness-cb470"),
N_("redness-cr470") }, extract_ycbcr470 },
{ "YCbCr_ITU_R709", TRUE, 3, { N_("luma-y709"),
N_("blueness-cb709"),
N_("redness-cr709") }, extract_ycbcr709 },
{ "YCbCr ITU R470 256", TRUE, 3, { N_("luma-y470f"),
N_("blueness-cb470f"),
N_("redness-cr470f") }, extract_ycbcr470f },
{ "YCbCr ITU R709 256", TRUE, 3, { N_("luma-y709f"),
N_("blueness-cb709f"),
N_("redness-cr709f") }, extract_ycbcr709f }
};
......@@ -191,11 +205,6 @@ typedef struct
gboolean as_layers;
} DecoVals;
typedef struct
{
gint extract_flag[G_N_ELEMENTS (extract)];
} DecoInterface;
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -210,11 +219,6 @@ static DecoVals decovals =
TRUE /* Decompose to Layers */
};
static DecoInterface decoint =
{
{ 0 } /* extract flags */
};
static GimpRunMode run_mode;
......@@ -263,7 +267,7 @@ run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[MAX_EXTRACT_IMAGES+1];
static GimpParam values[MAX_EXTRACT_IMAGES + 1];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 num_images;
gint32 image_ID_extract[MAX_EXTRACT_IMAGES];
......@@ -332,6 +336,7 @@ run (const gchar *name,
g_message ("Can only work on RGB images.");
status = GIMP_PDB_CALLING_ERROR;
}
if (status == GIMP_PDB_SUCCESS)
{
gimp_progress_init (_("Decomposing..."));
......@@ -350,9 +355,12 @@ run (const gchar *name,
{
/* create decompose-data parasite */
GString *data = g_string_new ("");
g_string_printf (data, "source=%d type=%s ", layer, decovals.extract_type);
g_string_printf (data, "source=%d type=%s ",
layer, decovals.extract_type);
for (j = 0; j < num_layers; j++)
g_string_append_printf (data, "%d ", layer_ID_extract[j]);
g_string_append_printf (data, "%d ", layer_ID_extract[j]);
for (j = 0; j < num_images; j++)
{
......@@ -367,7 +375,6 @@ run (const gchar *name,
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_display_new (image_ID_extract[j]);
}
/* Store data */
......@@ -392,7 +399,7 @@ decompose (gint32 image_ID,
gint32 *nlayers,
gint32 *layer_ID_dst)
{
const gchar *layername;
const gchar *layername;
gint i, j, extract_idx, scan_lines;
gint height, width, tile_height, num_layers;
gchar *filename;
......@@ -430,7 +437,7 @@ decompose (gint32 image_ID,
return -1;
}
width = drawable_src->width;
width = drawable_src->width;
height = drawable_src->height;
tile_height = gimp_tile_height ();
......@@ -1055,6 +1062,10 @@ extract_lab (guchar *src,
gdouble sixteenth = 16.0 / 116.0;
/* LAB colorspace constants */
#define LAB_Xn 0.951
#define LAB_Yn 1.0
#define LAB_Zn 1.089
while (count-- > 0)
{
......@@ -1066,19 +1077,19 @@ extract_lab (guchar *src,
y = 0.222 * red + 0.707 * green + 0.071 * blue;
z = 0.020 * red + 0.130 * green + 0.939 * blue;
if (( ty = y/Yn ) > 0.008856)
if ((ty = y / LAB_Yn) > 0.008856)
{
l = 116.0 * cbrt( ty ) - 16.0;
fty = cbrt( ty );
l = 116.0 * cbrt (ty) - 16.0;
fty = cbrt (ty);
}
else
{
l = 903.3 * ty;
fty = 7.78*ty + sixteenth;
l = 903.3 * ty;
fty = 7.78 * ty + sixteenth;
}
ftx = ((tx = x/Xn) > 0.008856) ? cbrt (tx) : 7.78 * tx + sixteenth;
ftz = ((tz = z/Zn) > 0.008856) ? cbrt (tz) : 7.78 * tz + sixteenth;
ftx = ((tx = x / LAB_Xn) > 0.008856) ? cbrt (tx) : 7.78 * tx + sixteenth;
ftz = ((tz = z / LAB_Zn) > 0.008856) ? cbrt (tz) : 7.78 * tz + sixteenth;
*l_dst++ = (guchar) CLAMP (l * 2.5599, 0., 256.);
*a_dst++ = (guchar) CLAMP (128.0 + (ftx - fty) * 635, 0., 256.);
......@@ -1181,9 +1192,9 @@ extract_ycbcr470f (guchar *src,
static void
extract_ycbcr709f (guchar *src,
gint bpp,
gint numpix,
guchar **dst)
gint bpp,
gint numpix,
guchar **dst)
{
register guchar *rgb_src = src;
register guchar *y_dst = dst[0];
......@@ -1213,97 +1224,119 @@ extract_ycbcr709f (guchar *src,
static gboolean
decompose_dialog (void)
{
GtkWidget *dlg;
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *toggle;
GtkWidget *frame;
GtkWidget *vbox;
GSList *group;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *combo;
GtkWidget *toggle;
gint j;
gint extract_idx;
gboolean run;
extract_idx = 0;
for (j = 0; j < G_N_ELEMENTS (extract); j++)
{
if (extract[j].dialog &&
g_ascii_strcasecmp (decovals.extract_type, extract[j].type) == 0)
{
extract_idx = j;
break;
}
}
gimp_ui_init (PLUG_IN_BINARY, FALSE);
dlg = gimp_dialog_new (_("Decompose"), PLUG_IN_BINARY,
NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC,
dialog = gimp_dialog_new (_("Decompose"), PLUG_IN_BINARY,
NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gimp_window_set_transient (GTK_WINDOW (dlg));
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gimp_window_set_transient (GTK_WINDOW (dialog));
main_vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_vbox,
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
TRUE, TRUE, 0);
gtk_widget_show (main_vbox);
/* parameter settings */
frame = gimp_frame_new (_("Extract Channels"));
gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 2);
vbox = gtk_vbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
group = NULL;
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new_with_mnemonic (_("Color _model:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);