2003-12-03 10:36:04 +08:00
|
|
|
/****************************************************************************
|
2007-06-06 16:44:52 +08:00
|
|
|
* This is a plugin for GIMP v 2.0 or later.
|
2003-12-03 10:36:04 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Martin Guldahl <mguldahl@xmission.com>
|
|
|
|
* Based on GTK code from:
|
2003-12-03 19:29:40 +08:00
|
|
|
* homomorphic (Copyright (C) 2001 Valter Marcus Hilden)
|
2003-12-03 10:36:04 +08:00
|
|
|
* rand-noted (Copyright (C) 1998 Miles O'Neal)
|
|
|
|
* nlfilt (Copyright (C) 1997 Eric L. Hernes)
|
|
|
|
* pagecurl (Copyright (C) 1996 Federico Mena Quintero)
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-12-03 10:36:04 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-12-03 10:36:04 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-12-03 10:36:04 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
#include <errno.h>
|
2003-12-03 10:36:04 +08:00
|
|
|
#include <string.h>
|
2003-12-03 19:29:40 +08:00
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
#include <glib/gstdio.h>
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-colors-channel-mixer"
|
2008-03-24 23:29:55 +08:00
|
|
|
#define PLUG_IN_BINARY "channel-mixer"
|
2006-06-12 21:00:54 +08:00
|
|
|
#define CM_LINE_SIZE 1024
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CM_RED_CHANNEL,
|
|
|
|
CM_GREEN_CHANNEL,
|
|
|
|
CM_BLUE_CHANNEL
|
|
|
|
} CmModeType;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2005-10-14 20:26:38 +08:00
|
|
|
gdouble red_gain;
|
|
|
|
gdouble green_gain;
|
|
|
|
gdouble blue_gain;
|
2003-12-03 10:36:04 +08:00
|
|
|
} CmChannelType;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CmChannelType red;
|
|
|
|
CmChannelType green;
|
|
|
|
CmChannelType blue;
|
|
|
|
CmChannelType black;
|
|
|
|
|
2005-10-14 20:26:38 +08:00
|
|
|
gboolean monochrome;
|
|
|
|
gboolean preserve_luminosity;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
CmModeType output_channel;
|
2004-10-05 01:05:52 +08:00
|
|
|
gboolean preview;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
GtkAdjustment *red_data;
|
|
|
|
GtkAdjustment *green_data;
|
|
|
|
GtkAdjustment *blue_data;
|
|
|
|
|
2004-04-20 20:21:17 +08:00
|
|
|
GtkWidget *combo;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
CmModeType old_output_channel;
|
|
|
|
|
|
|
|
GtkWidget *monochrome_toggle;
|
|
|
|
GtkWidget *preserve_luminosity_toggle;
|
|
|
|
} CmParamsType;
|
|
|
|
|
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-10-14 20:26:38 +08:00
|
|
|
static void cm_set_defaults (CmParamsType *mix);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
static void channel_mixer (CmParamsType *mix,
|
|
|
|
GimpDrawable *drawable);
|
|
|
|
static gboolean cm_dialog (CmParamsType *mix,
|
|
|
|
GimpDrawable *drawable);
|
2005-10-14 20:26:38 +08:00
|
|
|
|
|
|
|
static void cm_red_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_green_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_blue_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_monochrome_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_preserve_luminosity_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_load_file_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_load_file_response_callback (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_save_file_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_save_file_response_callback (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_reset_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
static void cm_combo_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix);
|
|
|
|
|
|
|
|
static gdouble cm_calculate_norm (CmParamsType *mix,
|
|
|
|
CmChannelType *ch);
|
|
|
|
|
|
|
|
static inline guchar cm_mix_pixel (CmChannelType *ch,
|
|
|
|
guchar r,
|
|
|
|
guchar g,
|
|
|
|
guchar b,
|
|
|
|
gdouble norm);
|
|
|
|
|
|
|
|
static void cm_preview (CmParamsType *mix,
|
|
|
|
GimpPreview *preview);
|
|
|
|
static void cm_set_adjusters (CmParamsType *mix);
|
|
|
|
static void cm_update_ui (CmParamsType *mix);
|
|
|
|
|
|
|
|
static void cm_save_file (CmParamsType *mix,
|
|
|
|
FILE *fp);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run /* run_proc */
|
|
|
|
};
|
|
|
|
|
2005-01-14 09:46:56 +08:00
|
|
|
static GtkWidget *preview;
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
|
|
|
query (void)
|
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef args[] =
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-08-14 02:29:14 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
|
2009-04-12 00:57:42 +08:00
|
|
|
{ GIMP_PDB_INT32, "monochrome", "Monochrome { TRUE, FALSE }" },
|
2005-08-14 02:29:14 +08:00
|
|
|
{ GIMP_PDB_FLOAT, "rr-gain", "Set the red gain for the red channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "rg-gain", "Set the green gain for the red channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "rb-gain", "Set the blue gain for the red channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "gr-gain", "Set the red gain for the green channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "gg-gain", "Set the green gain for the green channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "gb-gain", "Set the blue gain for the green channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "br-gain", "Set the red gain for the blue channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "bg-gain", "Set the green gain for the blue channel" },
|
|
|
|
{ GIMP_PDB_FLOAT, "bb-gain", "Set the blue gain for the blue channel" }
|
2003-12-03 10:36:04 +08:00
|
|
|
};
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-17 17:29:48 +08:00
|
|
|
N_("Alter colors by mixing RGB Channels"),
|
2003-12-03 10:36:04 +08:00
|
|
|
"This plug-in mixes the RGB channels.",
|
|
|
|
"Martin Guldahl <mguldahl@xmission.com>",
|
|
|
|
"Martin Guldahl <mguldahl@xmission.com>",
|
|
|
|
"2002",
|
2004-11-08 00:11:29 +08:00
|
|
|
N_("Channel Mi_xer..."),
|
2003-12-03 10:36:04 +08:00
|
|
|
"RGB*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 08:30:24 +08:00
|
|
|
|
2005-10-29 05:51:41 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Components");
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
|
|
|
{
|
|
|
|
static GimpParam values[1];
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
GimpRunMode run_mode;
|
2006-06-12 21:00:54 +08:00
|
|
|
CmParamsType mix;
|
2003-12-03 10:36:04 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
|
|
|
|
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
|
|
|
|
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id))
|
|
|
|
{
|
2005-01-14 09:46:56 +08:00
|
|
|
cm_set_defaults (&mix);
|
|
|
|
mix.preview = TRUE;
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
if (! cm_dialog (&mix, drawable))
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
2005-10-14 20:26:38 +08:00
|
|
|
mix.monochrome = param[3].data.d_int32;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-10-14 20:26:38 +08:00
|
|
|
if (mix.monochrome)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
mix.black.red_gain = param[4].data.d_float;
|
|
|
|
mix.black.green_gain = param[5].data.d_float;
|
|
|
|
mix.black.blue_gain = param[6].data.d_float;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mix.red.red_gain = param[4].data.d_float;
|
|
|
|
mix.red.green_gain = param[5].data.d_float;
|
|
|
|
mix.red.blue_gain = param[6].data.d_float;
|
2006-06-12 21:00:54 +08:00
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
mix.green.red_gain = param[7].data.d_float;
|
|
|
|
mix.green.green_gain = param[8].data.d_float;
|
|
|
|
mix.green.blue_gain = param[9].data.d_float;
|
2006-06-12 21:00:54 +08:00
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
mix.blue.red_gain = param[10].data.d_float;
|
|
|
|
mix.blue.green_gain = param[11].data.d_float;
|
|
|
|
mix.blue.blue_gain = param[12].data.d_float;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_get_data (PLUG_IN_PROC, &mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
/* printf("Channel Mixer:: Mode:%d r %f g %f b %f\n ",
|
|
|
|
param[3].data.d_int32, mix.black.red_gain,
|
|
|
|
mix.black.green_gain, mix.black.blue_gain); */
|
|
|
|
|
2005-09-30 16:16:10 +08:00
|
|
|
gimp_progress_init (_("Channel Mixer"));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
channel_mixer (&mix, drawable);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
gimp_displays_flush ();
|
|
|
|
|
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_set_data (PLUG_IN_PROC, &mix, sizeof (CmParamsType));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
}
|
|
|
|
|
2005-01-14 09:46:56 +08:00
|
|
|
static void
|
|
|
|
cm_set_defaults (CmParamsType *mix)
|
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
const CmParamsType defaults =
|
2005-08-14 02:29:14 +08:00
|
|
|
{
|
2005-01-14 09:46:56 +08:00
|
|
|
{ 1.0, 0.0, 0.0 },
|
|
|
|
{ 0.0, 1.0, 0.0 },
|
|
|
|
{ 0.0, 0.0, 1.0 },
|
|
|
|
{ 1.0, 0.0, 0.0 },
|
|
|
|
FALSE,
|
|
|
|
FALSE,
|
|
|
|
CM_RED_CHANNEL
|
|
|
|
};
|
|
|
|
|
|
|
|
memcpy (mix, &defaults, G_STRUCT_OFFSET (CmParamsType, preview));
|
|
|
|
}
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
static gdouble
|
|
|
|
cm_calculate_norm (CmParamsType *mix,
|
|
|
|
CmChannelType *ch)
|
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
gdouble sum = ch->red_gain + ch->green_gain + ch->blue_gain;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-10-14 20:26:38 +08:00
|
|
|
if (sum == 0.0 || ! mix->preserve_luminosity)
|
2003-12-03 10:36:04 +08:00
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
return fabs (1 / sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline guchar
|
|
|
|
cm_mix_pixel (CmChannelType *ch,
|
|
|
|
guchar r,
|
|
|
|
guchar g,
|
|
|
|
guchar b,
|
|
|
|
gdouble norm)
|
|
|
|
{
|
|
|
|
gdouble c = ch->red_gain * r + ch->green_gain * g + ch->blue_gain * b;
|
|
|
|
|
|
|
|
c *= norm;
|
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
return (guchar) CLAMP0255 (c);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
static inline void
|
|
|
|
cm_process_pixel (CmParamsType *mix,
|
|
|
|
const guchar *s,
|
|
|
|
guchar *d,
|
|
|
|
const gdouble red_norm,
|
|
|
|
const gdouble green_norm,
|
|
|
|
const gdouble blue_norm,
|
|
|
|
const gdouble black_norm)
|
|
|
|
{
|
|
|
|
if (mix->monochrome)
|
|
|
|
{
|
|
|
|
d[0] = d[1] = d[2] =
|
|
|
|
cm_mix_pixel (&mix->black, s[0], s[1], s[2], black_norm);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d[0] = cm_mix_pixel (&mix->red, s[0], s[1], s[2], red_norm);
|
|
|
|
d[1] = cm_mix_pixel (&mix->green, s[0], s[1], s[2], green_norm);
|
|
|
|
d[2] = cm_mix_pixel (&mix->blue, s[0], s[1], s[2], blue_norm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
static void
|
2006-06-12 21:00:54 +08:00
|
|
|
channel_mixer (CmParamsType *mix,
|
|
|
|
GimpDrawable *drawable)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
GimpPixelRgn src_rgn, dest_rgn;
|
|
|
|
gpointer pr;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gdouble red_norm, green_norm, blue_norm, black_norm;
|
2006-06-12 21:04:35 +08:00
|
|
|
gint i, total, processed = 0;
|
|
|
|
gint x1, y1;
|
|
|
|
gint width, height;
|
2004-10-05 01:05:52 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
if (! gimp_drawable_mask_intersect (drawable->drawable_id,
|
2006-06-12 21:04:35 +08:00
|
|
|
&x1, &y1, &width, &height))
|
2006-06-12 21:00:54 +08:00
|
|
|
return;
|
2004-10-05 01:05:52 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
red_norm = cm_calculate_norm (mix, &mix->red);
|
|
|
|
green_norm = cm_calculate_norm (mix, &mix->green);
|
|
|
|
blue_norm = cm_calculate_norm (mix, &mix->blue);
|
|
|
|
black_norm = cm_calculate_norm (mix, &mix->black);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&src_rgn, drawable,
|
2006-06-12 21:04:35 +08:00
|
|
|
x1, y1, width, height, FALSE, FALSE);
|
2003-12-03 10:36:04 +08:00
|
|
|
gimp_pixel_rgn_init (&dest_rgn, drawable,
|
2006-06-12 21:04:35 +08:00
|
|
|
x1, y1, width, height, TRUE, TRUE);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:04:35 +08:00
|
|
|
total = width * height;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn), i = 0;
|
|
|
|
pr != NULL;
|
|
|
|
pr = gimp_pixel_rgns_process (pr), i++)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
const guchar *src = src_rgn.data;
|
|
|
|
guchar *dest = dest_rgn.data;
|
2006-06-12 21:04:35 +08:00
|
|
|
gint x, y;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
for (y = 0; y < src_rgn.h; y++)
|
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
const guchar *s = src;
|
|
|
|
guchar *d = dest;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
if (has_alpha)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
for (x = 0; x < src_rgn.w; x++, s += 4, d += 4)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
cm_process_pixel (mix, s, d,
|
|
|
|
red_norm, green_norm, blue_norm,
|
|
|
|
black_norm);
|
|
|
|
d[3] = s[3];
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
2006-06-12 21:00:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (x = 0; x < src_rgn.w; x++, s += 3, d += 3)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
cm_process_pixel (mix, s, d,
|
|
|
|
red_norm, green_norm, blue_norm,
|
|
|
|
black_norm);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
2006-06-12 21:00:54 +08:00
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
src += src_rgn.rowstride;
|
|
|
|
dest += dest_rgn.rowstride;
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
processed += src_rgn.w * src_rgn.h;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
if (i % 16 == 0)
|
|
|
|
gimp_progress_update ((gdouble) processed / (gdouble) total);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
|
2006-06-12 21:04:35 +08:00
|
|
|
gimp_drawable_update (drawable->drawable_id, x1, y1, width, height);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
static gboolean
|
2006-06-12 21:00:54 +08:00
|
|
|
cm_dialog (CmParamsType *mix,
|
|
|
|
GimpDrawable *drawable)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2004-10-05 01:05:52 +08:00
|
|
|
GtkWidget *main_vbox;
|
2007-07-07 04:47:44 +08:00
|
|
|
GtkWidget *vbox;
|
2003-12-03 10:36:04 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *label;
|
2004-05-19 07:07:29 +08:00
|
|
|
GtkWidget *image;
|
2003-12-03 10:36:04 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
gdouble red_value, green_value, blue_value;
|
|
|
|
gboolean run;
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
/* get values */
|
2006-06-12 21:00:54 +08:00
|
|
|
if (mix->monochrome)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
red_value = mix->black.red_gain * 100;
|
|
|
|
green_value = mix->black.green_gain * 100;
|
|
|
|
blue_value = mix->black.blue_gain * 100;
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
switch (mix->output_channel)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
2006-06-12 21:00:54 +08:00
|
|
|
red_value = mix->red.red_gain * 100;
|
|
|
|
green_value = mix->red.green_gain * 100;
|
|
|
|
blue_value = mix->red.blue_gain * 100;
|
2003-12-03 10:36:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CM_GREEN_CHANNEL:
|
2006-06-12 21:00:54 +08:00
|
|
|
red_value = mix->green.red_gain * 100;
|
|
|
|
green_value = mix->green.green_gain * 100;
|
|
|
|
blue_value = mix->green.blue_gain * 100;
|
2003-12-03 10:36:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CM_BLUE_CHANNEL:
|
2006-06-12 21:00:54 +08:00
|
|
|
red_value = mix->blue.red_gain * 100;
|
|
|
|
green_value = mix->blue.green_gain * 100;
|
|
|
|
blue_value = mix->blue.blue_gain * 100;
|
2003-12-03 10:36:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
2003-12-24 06:07:06 +08:00
|
|
|
red_value = green_value = blue_value = 0.0;
|
2003-12-03 10:36:04 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
dialog = gimp_dialog_new (_("Channel Mixer"), PLUG_IN_BINARY,
|
2003-12-03 10:36:04 +08:00
|
|
|
NULL, 0,
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
|
|
|
|
2003-12-24 06:07:06 +08:00
|
|
|
NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-02-09 04:40:33 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-08-15 19:09:18 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
2009-07-16 00:57:12 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
main_vbox);
|
2004-10-05 01:05:52 +08:00
|
|
|
gtk_widget_show (main_vbox);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-09-20 06:58:16 +08:00
|
|
|
preview = gimp_zoom_preview_new (drawable);
|
2008-07-21 21:41:00 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), preview, TRUE, TRUE, 0);
|
2004-10-05 01:05:52 +08:00
|
|
|
gtk_widget_show (preview);
|
2008-07-21 21:41:00 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
g_signal_connect_swapped (preview, "invalidated",
|
|
|
|
G_CALLBACK (cm_preview),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
frame = gimp_frame_new (NULL);
|
2004-10-05 01:05:52 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
|
2003-12-03 20:34:42 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2003-12-03 20:34:42 +08:00
|
|
|
gtk_frame_set_label_widget (GTK_FRAME (frame), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
label = gtk_label_new_with_mnemonic (_("O_utput channel:"));
|
2004-05-19 07:07:29 +08:00
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->combo = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
|
2004-05-19 07:07:29 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (mix->combo),
|
2004-05-19 07:07:29 +08:00
|
|
|
GIMP_INT_STORE_VALUE, CM_RED_CHANNEL,
|
|
|
|
GIMP_INT_STORE_LABEL, _("Red"),
|
|
|
|
GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_CHANNEL_RED,
|
|
|
|
-1);
|
2006-06-12 21:00:54 +08:00
|
|
|
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (mix->combo),
|
2004-05-19 07:07:29 +08:00
|
|
|
GIMP_INT_STORE_VALUE, CM_GREEN_CHANNEL,
|
|
|
|
GIMP_INT_STORE_LABEL, _("Green"),
|
|
|
|
GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_CHANNEL_GREEN,
|
|
|
|
-1);
|
2006-06-12 21:00:54 +08:00
|
|
|
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (mix->combo),
|
2004-05-19 07:07:29 +08:00
|
|
|
GIMP_INT_STORE_VALUE, CM_BLUE_CHANNEL,
|
|
|
|
GIMP_INT_STORE_LABEL, _("Blue"),
|
|
|
|
GIMP_INT_STORE_STOCK_ID, GIMP_STOCK_CHANNEL_BLUE,
|
|
|
|
-1);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (mix->combo),
|
|
|
|
mix->output_channel);
|
2003-12-03 20:34:42 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->combo, "changed",
|
2004-04-20 20:21:17 +08:00
|
|
|
G_CALLBACK (cm_combo_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 20:34:42 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), mix->combo, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (mix->combo);
|
2003-12-03 20:34:42 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
if (mix->monochrome)
|
|
|
|
gtk_widget_set_sensitive (mix->combo, FALSE);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), mix->combo);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
/*........................................................... */
|
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
table = gtk_table_new (3, 4, FALSE);
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
2003-12-03 20:34:42 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_RED,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
|
|
|
0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->red_data =
|
2004-05-19 07:07:29 +08:00
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 1, 0,
|
2003-12-03 20:34:42 +08:00
|
|
|
_("_Red:"), 150, -1,
|
|
|
|
red_value, -200.0, 200.0,
|
|
|
|
1.0, 10.0, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->red_data, "value-changed",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_red_scale_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_GREEN,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
|
|
|
0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->green_data =
|
2004-05-19 07:07:29 +08:00
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 1, 1,
|
2003-12-03 20:34:42 +08:00
|
|
|
_("_Green:"), 150, -1,
|
|
|
|
green_value, -200.0, 200.0,
|
|
|
|
1.0, 10.0, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->green_data, "value-changed",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_green_scale_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
|
2004-05-19 07:07:29 +08:00
|
|
|
image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_BLUE,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), image,
|
|
|
|
0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->blue_data =
|
2004-05-19 07:07:29 +08:00
|
|
|
GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 1, 2,
|
2003-12-03 20:34:42 +08:00
|
|
|
_("_Blue:"), 150, -1,
|
|
|
|
blue_value, -200.0, 200.0,
|
|
|
|
1.0, 10.0, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->blue_data, "value-changed",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_blue_scale_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-07-07 04:47:44 +08:00
|
|
|
vbox = gtk_vbox_new (6, FALSE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
/* The monochrome toggle */
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->monochrome_toggle =
|
|
|
|
gtk_check_button_new_with_mnemonic (_("_Monochrome"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mix->monochrome_toggle),
|
|
|
|
mix->monochrome);
|
2007-07-07 04:47:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), mix->monochrome_toggle,
|
2005-10-14 20:26:38 +08:00
|
|
|
FALSE, FALSE, 0);
|
2006-06-12 21:00:54 +08:00
|
|
|
gtk_widget_show (mix->monochrome_toggle);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->monochrome_toggle, "toggled",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_monochrome_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 20:34:42 +08:00
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
/* The preserve luminosity toggle */
|
2006-06-12 21:00:54 +08:00
|
|
|
mix->preserve_luminosity_toggle =
|
2004-05-26 04:16:07 +08:00
|
|
|
gtk_check_button_new_with_mnemonic (_("Preserve _luminosity"));
|
2003-12-03 10:36:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
|
2006-06-12 21:00:54 +08:00
|
|
|
(mix->preserve_luminosity_toggle),
|
|
|
|
mix->preserve_luminosity);
|
2007-07-07 04:47:44 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), mix->preserve_luminosity_toggle,
|
2003-12-03 20:34:42 +08:00
|
|
|
FALSE, FALSE, 0);
|
2006-06-12 21:00:54 +08:00
|
|
|
gtk_widget_show (mix->preserve_luminosity_toggle);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_signal_connect (mix->preserve_luminosity_toggle, "toggled",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_preserve_luminosity_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
/*........................................................... */
|
|
|
|
/* Horizontal box for file i/o */
|
2004-05-18 17:39:24 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 6);
|
2004-10-05 01:05:52 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
|
2003-12-03 20:34:42 +08:00
|
|
|
gtk_widget_show (hbox);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "clicked",
|
2003-12-03 20:34:42 +08:00
|
|
|
G_CALLBACK (cm_load_file_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 20:34:42 +08:00
|
|
|
|
|
|
|
button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
|
2003-12-03 10:36:04 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (cm_save_file_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-01-14 09:46:56 +08:00
|
|
|
button = gtk_button_new_from_stock (GIMP_STOCK_RESET);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (cm_reset_callback),
|
2006-06-12 21:00:54 +08:00
|
|
|
mix);
|
2005-01-14 09:46:56 +08:00
|
|
|
|
2004-07-31 03:55:03 +08:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
2003-12-03 11:00:54 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
|
|
|
|
return run;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_red_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
2005-10-14 20:26:38 +08:00
|
|
|
if (mix->monochrome)
|
|
|
|
{
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->black.red_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
{
|
|
|
|
switch (mix->output_channel)
|
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->red.red_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_GREEN_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->green.red_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_BLUE_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->blue.red_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_green_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
2005-10-14 20:26:38 +08:00
|
|
|
if (mix->monochrome)
|
|
|
|
{
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->black.green_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
{
|
|
|
|
switch (mix->output_channel)
|
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->red.green_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_GREEN_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->green.green_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_BLUE_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->blue.green_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_blue_scale_callback (GtkAdjustment *adjustment,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
2005-10-14 20:26:38 +08:00
|
|
|
if (mix->monochrome)
|
|
|
|
{
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->black.blue_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
{
|
|
|
|
switch (mix->output_channel)
|
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->red.blue_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_GREEN_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->green.blue_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
case CM_BLUE_CHANNEL:
|
2009-10-10 16:55:09 +08:00
|
|
|
mix->blue.blue_gain = gtk_adjustment_get_value (adjustment) / 100.0;
|
2005-10-14 20:26:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-10-05 01:05:52 +08:00
|
|
|
cm_preview (CmParamsType *mix,
|
|
|
|
GimpPreview *preview)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
guchar *src, *s;
|
|
|
|
guchar *dst, *d;
|
2004-10-05 01:05:52 +08:00
|
|
|
gint x, y;
|
|
|
|
gdouble red_norm, green_norm, blue_norm, black_norm;
|
|
|
|
gint width, height, bpp;
|
2005-09-21 05:52:54 +08:00
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
red_norm = cm_calculate_norm (mix, &mix->red);
|
|
|
|
green_norm = cm_calculate_norm (mix, &mix->green);
|
|
|
|
blue_norm = cm_calculate_norm (mix, &mix->blue);
|
|
|
|
black_norm = cm_calculate_norm (mix, &mix->black);
|
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
drawable = gimp_zoom_preview_get_drawable (GIMP_ZOOM_PREVIEW (preview));
|
|
|
|
|
|
|
|
src = s = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
|
|
|
|
&width, &height, &bpp);
|
2004-10-05 01:05:52 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
dst = d = g_new (guchar, width * height * bpp);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
for (y = 0; y < height; y++)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
for (x = 0; x < width; x++, s += bpp, d += bpp)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2006-06-12 21:00:54 +08:00
|
|
|
cm_process_pixel (mix, s, d,
|
|
|
|
red_norm, green_norm, blue_norm,
|
|
|
|
black_norm);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
if (bpp == 4)
|
2006-06-12 21:00:54 +08:00
|
|
|
d[3] = s[3];
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
}
|
2006-06-12 21:00:54 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_draw_buffer (GIMP_PREVIEW (preview), dst, bpp * width);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2006-06-12 21:00:54 +08:00
|
|
|
g_free (src);
|
2003-12-03 10:36:04 +08:00
|
|
|
g_free (dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_monochrome_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
|
|
|
{
|
|
|
|
mix->old_output_channel = mix->output_channel;
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome = TRUE;
|
2004-04-20 20:21:17 +08:00
|
|
|
gtk_widget_set_sensitive (mix->combo, FALSE);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mix->output_channel = mix->old_output_channel;
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome = FALSE;
|
2004-04-20 20:21:17 +08:00
|
|
|
gtk_widget_set_sensitive (mix->combo, TRUE);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cm_set_adjusters (mix);
|
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_preserve_luminosity_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity = TRUE;
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity = FALSE;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-10-05 01:05:52 +08:00
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
2003-12-03 19:29:40 +08:00
|
|
|
static gchar *
|
2004-07-04 21:40:24 +08:00
|
|
|
cm_settings_filename (void)
|
2003-12-03 19:29:40 +08:00
|
|
|
{
|
2004-07-04 21:40:24 +08:00
|
|
|
return g_build_filename (gimp_directory (),
|
|
|
|
"channel-mixer",
|
|
|
|
"settings",
|
|
|
|
NULL);
|
2003-12-03 19:29:40 +08:00
|
|
|
}
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
static void
|
|
|
|
cm_load_file_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
static GtkWidget *dialog = NULL;
|
|
|
|
|
|
|
|
if (! dialog)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
GtkWidget *parent = gtk_widget_get_toplevel (widget);
|
2004-07-04 21:40:24 +08:00
|
|
|
gchar *name;
|
2004-05-18 17:39:24 +08:00
|
|
|
|
|
|
|
dialog =
|
|
|
|
gtk_file_chooser_dialog_new (_("Load Channel Mixer Settings"),
|
|
|
|
GTK_WINDOW (parent),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2005-04-08 01:10:05 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-11-08 19:24:43 +08:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2004-05-18 17:39:24 +08:00
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
2003-12-03 10:36:04 +08:00
|
|
|
G_CALLBACK (cm_load_file_response_callback),
|
2003-12-24 06:07:06 +08:00
|
|
|
mix);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (dialog, "delete-event",
|
2003-12-03 10:36:04 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
|
|
|
|
2004-07-04 21:40:24 +08:00
|
|
|
name = cm_settings_filename ();
|
|
|
|
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), name);
|
|
|
|
g_free (name);
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-18 17:39:24 +08:00
|
|
|
cm_load_file_response_callback (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
CmParamsType *mix)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-07-04 21:40:24 +08:00
|
|
|
gchar *filename;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-07-04 21:40:24 +08:00
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-04-27 04:31:01 +08:00
|
|
|
fp = g_fopen (filename, "rb");
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
if (fp)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
|
|
|
gchar buf[3][CM_LINE_SIZE];
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2003-12-24 06:07:06 +08:00
|
|
|
buf[0][0] = '\0';
|
|
|
|
buf[1][0] = '\0';
|
|
|
|
buf[2][0] = '\0';
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
fgets (buf[0], CM_LINE_SIZE - 1, fp);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s", buf[0]);
|
2003-12-03 20:34:42 +08:00
|
|
|
if (strcmp (buf[0], "RED") == 0)
|
2003-12-03 10:36:04 +08:00
|
|
|
mix->output_channel = CM_RED_CHANNEL;
|
2003-12-03 20:34:42 +08:00
|
|
|
else if (strcmp (buf[0], "GREEN") == 0)
|
2003-12-03 10:36:04 +08:00
|
|
|
mix->output_channel = CM_GREEN_CHANNEL;
|
2003-12-03 20:34:42 +08:00
|
|
|
else if (strcmp (buf[0], "BLUE") == 0)
|
2003-12-03 10:36:04 +08:00
|
|
|
mix->output_channel = CM_BLUE_CHANNEL;
|
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s", buf[0]); /* preview flag, preserved for compatibility */
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s", buf[0]);
|
2003-12-03 20:34:42 +08:00
|
|
|
if (strcmp (buf[0], "TRUE") == 0)
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome = TRUE;
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome = FALSE;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s", buf[0]);
|
2003-12-03 20:34:42 +08:00
|
|
|
if (strcmp (buf[0], "TRUE") == 0)
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity = TRUE;
|
2003-12-03 10:36:04 +08:00
|
|
|
else
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity = FALSE;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s %1023s %1023s", buf[0], buf[1], buf[2]);
|
2003-12-03 20:34:42 +08:00
|
|
|
mix->red.red_gain = g_ascii_strtod (buf[0], NULL);
|
|
|
|
mix->red.green_gain = g_ascii_strtod (buf[1], NULL);
|
|
|
|
mix->red.blue_gain = g_ascii_strtod (buf[2], NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s %1023s %1023s", buf[0], buf[1], buf[2]);
|
2003-12-03 20:34:42 +08:00
|
|
|
mix->green.red_gain = g_ascii_strtod (buf[0], NULL);
|
|
|
|
mix->green.green_gain = g_ascii_strtod (buf[1], NULL);
|
|
|
|
mix->green.blue_gain = g_ascii_strtod (buf[2], NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s %1023s %1023s", buf[0], buf[1], buf[2]);
|
2003-12-03 20:34:42 +08:00
|
|
|
mix->blue.red_gain = g_ascii_strtod (buf[0], NULL);
|
|
|
|
mix->blue.green_gain = g_ascii_strtod (buf[1], NULL);
|
|
|
|
mix->blue.blue_gain = g_ascii_strtod (buf[2], NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-05-31 01:11:13 +08:00
|
|
|
fscanf (fp, "%*s %1023s %1023s %1023s", buf[0], buf[1], buf[2]);
|
2003-12-03 20:34:42 +08:00
|
|
|
mix->black.red_gain = g_ascii_strtod (buf[0], NULL);
|
|
|
|
mix->black.green_gain = g_ascii_strtod (buf[1], NULL);
|
|
|
|
mix->black.blue_gain = g_ascii_strtod (buf[2], NULL);
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
|
2005-01-14 09:46:56 +08:00
|
|
|
cm_update_ui (mix);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
else
|
2003-12-03 19:29:40 +08:00
|
|
|
{
|
|
|
|
g_message (_("Could not open '%s' for reading: %s"),
|
2004-07-04 21:40:24 +08:00
|
|
|
gimp_filename_to_utf8 (filename),
|
2004-04-20 20:21:17 +08:00
|
|
|
g_strerror (errno));
|
2003-12-03 19:29:40 +08:00
|
|
|
}
|
2004-07-04 21:40:24 +08:00
|
|
|
|
|
|
|
g_free (filename);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_widget_hide (dialog);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_save_file_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
static GtkWidget *dialog = NULL;
|
|
|
|
|
|
|
|
if (! dialog)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
GtkWidget *parent = gtk_widget_get_toplevel (widget);
|
2004-07-04 21:40:24 +08:00
|
|
|
gchar *name;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
dialog =
|
|
|
|
gtk_file_chooser_dialog_new (_("Save Channel Mixer Settings"),
|
|
|
|
GTK_WINDOW (parent),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
NULL);
|
|
|
|
|
2005-04-08 01:10:05 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2004-11-08 19:24:43 +08:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2004-05-18 17:39:24 +08:00
|
|
|
|
2007-02-02 16:57:15 +08:00
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
|
|
|
|
TRUE);
|
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
2003-12-03 10:36:04 +08:00
|
|
|
G_CALLBACK (cm_save_file_response_callback),
|
2003-12-24 06:07:06 +08:00
|
|
|
mix);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (dialog, "delete-event",
|
2003-12-03 10:36:04 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
|
|
|
|
2004-07-04 21:40:24 +08:00
|
|
|
name = cm_settings_filename ();
|
|
|
|
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), name);
|
|
|
|
g_free (name);
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-05-18 17:39:24 +08:00
|
|
|
cm_save_file_response_callback (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
CmParamsType *mix)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
gchar *filename;
|
|
|
|
FILE *file = NULL;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_widget_hide (dialog);
|
2003-12-03 10:36:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2003-12-03 10:36:04 +08:00
|
|
|
if (! filename)
|
|
|
|
return;
|
|
|
|
|
2007-04-27 04:31:01 +08:00
|
|
|
file = g_fopen (filename, "wb");
|
2003-12-03 19:29:40 +08:00
|
|
|
|
|
|
|
if (! file)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
g_message (_("Could not open '%s' for writing: %s"),
|
2004-01-19 11:06:04 +08:00
|
|
|
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
2004-05-18 17:39:24 +08:00
|
|
|
g_free (filename);
|
2003-12-03 10:36:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cm_save_file (mix, file);
|
|
|
|
|
2004-07-04 21:40:24 +08:00
|
|
|
g_message (_("Parameters were saved to '%s'"),
|
2004-01-19 11:06:04 +08:00
|
|
|
gimp_filename_to_utf8 (filename));
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2004-05-18 17:39:24 +08:00
|
|
|
gtk_widget_hide (dialog);
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_save_file (CmParamsType *mix,
|
|
|
|
FILE *fp)
|
|
|
|
{
|
|
|
|
const gchar *str = NULL;
|
2003-12-03 20:34:42 +08:00
|
|
|
gchar buf[3][G_ASCII_DTOSTR_BUF_SIZE];
|
2003-12-03 10:36:04 +08:00
|
|
|
|
|
|
|
switch (mix->output_channel)
|
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
|
|
|
str = "RED";
|
|
|
|
break;
|
|
|
|
case CM_GREEN_CHANNEL:
|
|
|
|
str = "GREEN";
|
|
|
|
break;
|
|
|
|
case CM_BLUE_CHANNEL:
|
|
|
|
str = "BLUE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-03 20:34:42 +08:00
|
|
|
fprintf (fp, "# Channel Mixer Configuration File\n");
|
|
|
|
|
|
|
|
fprintf (fp, "CHANNEL: %s\n", str);
|
2004-10-05 01:05:52 +08:00
|
|
|
fprintf (fp, "PREVIEW: %s\n", "TRUE"); /* preserved for compatibility */
|
2003-12-03 20:34:42 +08:00
|
|
|
fprintf (fp, "MONOCHROME: %s\n",
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome ? "TRUE" : "FALSE");
|
2003-12-03 20:34:42 +08:00
|
|
|
fprintf (fp, "PRESERVE_LUMINOSITY: %s\n",
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity ? "TRUE" : "FALSE");
|
2003-12-03 20:34:42 +08:00
|
|
|
|
|
|
|
fprintf (fp, "RED: %s %s %s\n",
|
|
|
|
g_ascii_formatd (buf[0], sizeof (buf[0]), "%5.3f",
|
|
|
|
mix->red.red_gain),
|
|
|
|
g_ascii_formatd (buf[1], sizeof (buf[1]), "%5.3f",
|
|
|
|
mix->red.green_gain),
|
|
|
|
g_ascii_formatd (buf[2], sizeof (buf[2]), "%5.3f",
|
|
|
|
mix->red.blue_gain));
|
|
|
|
|
|
|
|
fprintf (fp, "GREEN: %s %s %s\n",
|
|
|
|
g_ascii_formatd (buf[0], sizeof (buf[0]), "%5.3f",
|
|
|
|
mix->green.red_gain),
|
|
|
|
g_ascii_formatd (buf[1], sizeof (buf[1]), "%5.3f",
|
|
|
|
mix->green.green_gain),
|
|
|
|
g_ascii_formatd (buf[2], sizeof (buf[2]), "%5.3f",
|
|
|
|
mix->green.blue_gain));
|
|
|
|
|
|
|
|
fprintf (fp, "BLUE: %s %s %s\n",
|
|
|
|
g_ascii_formatd (buf[0], sizeof (buf[0]), "%5.3f",
|
|
|
|
mix->blue.red_gain),
|
|
|
|
g_ascii_formatd (buf[1], sizeof (buf[1]), "%5.3f",
|
|
|
|
mix->blue.green_gain),
|
|
|
|
g_ascii_formatd (buf[2], sizeof (buf[2]), "%5.3f",
|
|
|
|
mix->blue.blue_gain));
|
|
|
|
|
|
|
|
fprintf (fp, "BLACK: %s %s %s\n",
|
|
|
|
g_ascii_formatd (buf[0], sizeof (buf[0]), "%5.3f",
|
|
|
|
mix->black.red_gain),
|
|
|
|
g_ascii_formatd (buf[1], sizeof (buf[1]), "%5.3f",
|
|
|
|
mix->black.green_gain),
|
|
|
|
g_ascii_formatd (buf[2], sizeof (buf[2]), "%5.3f",
|
|
|
|
mix->black.blue_gain));
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
2005-01-14 09:46:56 +08:00
|
|
|
static void
|
|
|
|
cm_reset_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
|
|
|
{
|
|
|
|
cm_set_defaults (mix);
|
|
|
|
cm_update_ui (mix);
|
|
|
|
}
|
|
|
|
|
2003-12-03 10:36:04 +08:00
|
|
|
static void
|
2004-04-20 20:21:17 +08:00
|
|
|
cm_combo_callback (GtkWidget *widget,
|
|
|
|
CmParamsType *mix)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
2007-04-12 23:12:13 +08:00
|
|
|
gint value;
|
2003-12-03 10:36:04 +08:00
|
|
|
|
2007-04-12 23:12:13 +08:00
|
|
|
if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value))
|
|
|
|
{
|
|
|
|
mix->output_channel = value;
|
|
|
|
|
|
|
|
cm_set_adjusters (mix);
|
|
|
|
}
|
2003-12-03 10:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cm_set_adjusters (CmParamsType *mix)
|
|
|
|
{
|
2005-10-14 20:26:38 +08:00
|
|
|
if (mix->monochrome)
|
2003-12-03 10:36:04 +08:00
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (mix->red_data, mix->black.red_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->green_data, mix->black.green_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->blue_data, mix->black.blue_gain * 100.0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mix->output_channel)
|
|
|
|
{
|
|
|
|
case CM_RED_CHANNEL:
|
|
|
|
gtk_adjustment_set_value (mix->red_data, mix->red.red_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->green_data, mix->red.green_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->blue_data, mix->red.blue_gain * 100.0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CM_GREEN_CHANNEL:
|
|
|
|
gtk_adjustment_set_value (mix->red_data, mix->green.red_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->green_data, mix->green.green_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->blue_data, mix->green.blue_gain * 100.0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CM_BLUE_CHANNEL:
|
|
|
|
gtk_adjustment_set_value (mix->red_data, mix->blue.red_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->green_data, mix->blue.green_gain * 100.0);
|
|
|
|
gtk_adjustment_set_value (mix->blue_data, mix->blue.blue_gain * 100.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-01-14 09:46:56 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
cm_update_ui (CmParamsType *mix)
|
|
|
|
{
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mix->monochrome_toggle),
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->monochrome);
|
2005-01-14 09:46:56 +08:00
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mix->preserve_luminosity_toggle),
|
2005-10-14 20:26:38 +08:00
|
|
|
mix->preserve_luminosity);
|
2005-01-14 09:46:56 +08:00
|
|
|
|
|
|
|
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (mix->combo),
|
|
|
|
mix->output_channel);
|
|
|
|
|
|
|
|
cm_set_adjusters (mix);
|
|
|
|
|
|
|
|
gimp_preview_invalidate (GIMP_PREVIEW (preview));
|
|
|
|
}
|