1998-11-06 00:51:39 +00:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
* mapcolor plugin
|
|
|
|
* Copyright (C) 1998 Peter Kirchgessner
|
1999-11-24 23:58:46 +00:00
|
|
|
* email: peter@kirchgessner.net, WWW: http://www.kirchgessner.net)
|
1998-11-06 00:51:39 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Event history:
|
|
|
|
* V 1.00, PK, 26-Oct-98: Creation.
|
1999-11-24 23:58:46 +00:00
|
|
|
* V 1.01, PK, 21-Nov-99: Fix problem with working on layered images
|
|
|
|
* Internationalization
|
2000-03-24 16:21:35 +00:00
|
|
|
* V 1.02, PK, 19-Mar-00: Better explaining text/dialogue
|
|
|
|
* Preview added
|
|
|
|
* Fix problem with divide by zero
|
2000-05-22 11:35:28 +00:00
|
|
|
* V 1.03,neo, 22-May-00: Fixed divide by zero in preview code.
|
1998-11-06 00:51:39 +00:00
|
|
|
*/
|
2004-09-28 23:08:17 +00:00
|
|
|
|
2000-05-22 11:35:28 +00:00
|
|
|
#define VERSIO 1.03
|
|
|
|
static char dversio[] = "v1.03 22-May-00";
|
|
|
|
static char ident[] = "@(#) GIMP mapcolor plug-in v1.03 22-May-00";
|
1998-11-06 00:51:39 +00:00
|
|
|
|
1999-11-20 02:16:17 +00:00
|
|
|
#include "config.h"
|
2000-01-07 10:39:33 +00:00
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2000-01-07 10:39:33 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2000-05-01 17:01:18 +00:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-07 10:39:33 +00:00
|
|
|
|
1999-11-15 19:46:06 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define PRV_WIDTH 50
|
|
|
|
#define PRV_HEIGHT 20
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2001-01-14 20:25:46 +00:00
|
|
|
GimpRGB colors[4];
|
|
|
|
gint32 map_mode;
|
1999-11-15 19:46:06 +00:00
|
|
|
} PluginValues;
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
PluginValues plvals =
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2000-01-11 15:48:00 +00:00
|
|
|
{
|
2001-01-14 20:25:46 +00:00
|
|
|
{ 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
{ 1.0, 1.0, 1.0, 1.0 },
|
|
|
|
{ 0.0, 0.0, 0.0, 1.0 },
|
|
|
|
{ 1.0, 1.0, 1.0, 1.0 },
|
2000-01-11 15:48:00 +00:00
|
|
|
},
|
1999-11-15 19:46:06 +00:00
|
|
|
0
|
|
|
|
};
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
|
|
|
|
/* Preview handling stuff */
|
|
|
|
|
|
|
|
#define IMG_PRV_SIZE 128
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2000-05-01 17:01:18 +00:00
|
|
|
guint width, height;
|
2000-03-24 16:21:35 +00:00
|
|
|
guchar *img;
|
|
|
|
} IMG_PREVIEW;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2000-05-01 17:01:18 +00:00
|
|
|
GtkWidget *preview;
|
2000-03-24 16:21:35 +00:00
|
|
|
IMG_PREVIEW *img_preview;
|
|
|
|
IMG_PREVIEW *map_preview;
|
|
|
|
} PLInterface;
|
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
static guchar redmap[256], greenmap[256], bluemap[256];
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
/* Declare some local functions.
|
|
|
|
*/
|
2000-01-11 15:48:00 +00:00
|
|
|
static void query (void);
|
2003-07-02 12:03:08 +00:00
|
|
|
static void run (const gchar *name,
|
2004-08-01 17:16:42 +00:00
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2000-02-07 20:35:13 +00:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1998-11-06 00:51:39 +00:00
|
|
|
};
|
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
static IMG_PREVIEW *img_preview_alloc (guint width, guint height);
|
|
|
|
static void img_preview_free (IMG_PREVIEW *ip);
|
|
|
|
static void img_preview_copy (IMG_PREVIEW *src, IMG_PREVIEW **dst);
|
|
|
|
static IMG_PREVIEW *img_preview_create_from_drawable (guint maxsize,
|
2004-08-01 17:16:42 +00:00
|
|
|
gint32 drawable_ID);
|
2000-03-24 16:21:35 +00:00
|
|
|
|
|
|
|
static void update_img_preview (void);
|
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
static gboolean dialog (gint32 drawable_ID);
|
|
|
|
static void get_mapping (GimpRGB *src_col1,
|
2004-08-01 17:16:42 +00:00
|
|
|
GimpRGB *src_col2,
|
|
|
|
GimpRGB *dst_col1,
|
|
|
|
GimpRGB *dst_col2,
|
|
|
|
gint32 map_mode,
|
|
|
|
guchar *redmap,
|
|
|
|
guchar *greenmap,
|
|
|
|
guchar *bluemap);
|
2000-02-07 20:35:13 +00:00
|
|
|
static void add_color_button (gint csel_index,
|
2004-08-01 17:16:42 +00:00
|
|
|
gint left,
|
|
|
|
gint top,
|
|
|
|
GtkWidget *table);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
static void color_mapping (GimpDrawable *drawable);
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
static gchar *csel_title[4] =
|
|
|
|
{
|
|
|
|
N_("First Source Color"),
|
2000-02-07 20:35:13 +00:00
|
|
|
N_("Second Source Color"),
|
2000-03-24 16:21:35 +00:00
|
|
|
N_("First Destination Color"),
|
|
|
|
N_("Second Destination Color")
|
1999-11-15 19:46:06 +00:00
|
|
|
};
|
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
static PLInterface plinterface;
|
|
|
|
|
|
|
|
|
|
|
|
/* Allocate image preview structure and preview memory */
|
|
|
|
static IMG_PREVIEW *
|
2003-11-06 15:27:05 +00:00
|
|
|
img_preview_alloc (guint width,
|
2004-08-01 17:16:42 +00:00
|
|
|
guint height)
|
2001-01-14 20:25:46 +00:00
|
|
|
{
|
|
|
|
IMG_PREVIEW *ip;
|
2000-03-24 16:21:35 +00:00
|
|
|
|
2001-12-06 02:28:58 +00:00
|
|
|
ip = g_new (IMG_PREVIEW, 1);
|
2003-09-13 18:07:44 +00:00
|
|
|
ip->img = g_new (guchar, width * height*3);
|
2001-01-14 20:25:46 +00:00
|
|
|
ip->width = width;
|
|
|
|
ip->height = height;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
return ip;
|
2000-03-24 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free image preview */
|
|
|
|
static void
|
|
|
|
img_preview_free (IMG_PREVIEW *ip)
|
|
|
|
{
|
2003-09-13 18:07:44 +00:00
|
|
|
if (ip)
|
|
|
|
{
|
|
|
|
g_free (ip->img);
|
|
|
|
g_free (ip);
|
|
|
|
}
|
2000-03-24 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
/* Copy image preview. Create/modify destination preview */
|
2000-03-24 16:21:35 +00:00
|
|
|
static void
|
2003-11-06 15:27:05 +00:00
|
|
|
img_preview_copy (IMG_PREVIEW *src,
|
2004-08-01 17:16:42 +00:00
|
|
|
IMG_PREVIEW **dst)
|
2000-03-24 16:21:35 +00:00
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
{
|
|
|
|
gint numbytes;
|
|
|
|
IMG_PREVIEW *dst_p;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
if ((src == NULL) || (src->img == NULL) || (dst == NULL)) return;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
numbytes = src->width * src->height * 3; /* 1 byte spare */
|
|
|
|
if (numbytes <= 0) return;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
if (*dst == NULL) /* Create new preview ? */
|
|
|
|
{
|
|
|
|
*dst = img_preview_alloc (src->width, src->height);
|
|
|
|
memcpy ((*dst)->img, src->img, numbytes);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
/* destination preview already exists */
|
|
|
|
dst_p = *dst;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2003-09-13 18:07:44 +00:00
|
|
|
/* Did not already allocate enough memory ? */
|
|
|
|
if ((dst_p->img != NULL) && (dst_p->width*dst_p->height*3 < numbytes))
|
|
|
|
{
|
|
|
|
g_free (dst_p->img);
|
|
|
|
dst_p->width = dst_p->height = 0;
|
|
|
|
dst_p->img = NULL;
|
|
|
|
}
|
|
|
|
if (dst_p->img == NULL)
|
|
|
|
{
|
|
|
|
dst_p->img = (guchar *)g_malloc (numbytes);
|
|
|
|
}
|
|
|
|
dst_p->width = src->width;
|
|
|
|
dst_p->height = src->height;
|
|
|
|
memcpy (dst_p->img, src->img, numbytes);
|
2000-03-24 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static IMG_PREVIEW *
|
2003-11-06 15:27:05 +00:00
|
|
|
img_preview_create_from_drawable (guint maxsize,
|
2004-08-01 17:16:42 +00:00
|
|
|
gint32 drawable_ID)
|
2000-05-22 11:35:28 +00:00
|
|
|
{
|
2004-08-01 17:16:42 +00:00
|
|
|
GimpDrawable *drw;
|
2004-09-28 23:08:17 +00:00
|
|
|
GimpPixelRgn pixel_rgn;
|
|
|
|
guint drw_width, drw_height;
|
|
|
|
guint prv_width, prv_height;
|
|
|
|
gint src_x, src_y, x, y;
|
|
|
|
guchar *prv_data, *img_data, *cu_row;
|
|
|
|
gdouble xfactor, yfactor;
|
|
|
|
gint tile_height, row_start, row_end;
|
|
|
|
gint bpp;
|
|
|
|
IMG_PREVIEW *ip;
|
2004-08-01 17:16:42 +00:00
|
|
|
|
|
|
|
drw_width = gimp_drawable_width (drawable_ID);
|
|
|
|
drw_height = gimp_drawable_height (drawable_ID);
|
|
|
|
tile_height = (gint)gimp_tile_height();
|
|
|
|
bpp = gimp_drawable_bpp(drawable_ID);
|
|
|
|
|
|
|
|
img_data = g_malloc (drw_width * tile_height * bpp);
|
|
|
|
if (img_data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Calculate preview size */
|
|
|
|
if ((drw_width <= maxsize) && (drw_height <= maxsize))
|
|
|
|
{
|
|
|
|
prv_width = drw_width;
|
|
|
|
prv_height = drw_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xfactor = ((double)maxsize) / ((double)drw_width);
|
|
|
|
yfactor = ((double)maxsize) / ((double)drw_height);
|
|
|
|
if (xfactor < yfactor)
|
|
|
|
{
|
|
|
|
prv_width = maxsize;
|
|
|
|
prv_height = (guint)(drw_height * xfactor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prv_width = (guint)(drw_width * yfactor);
|
|
|
|
prv_height = maxsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ip = img_preview_alloc (prv_width, prv_height);
|
|
|
|
if (ip == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
drw = gimp_drawable_get (drawable_ID);
|
|
|
|
prv_data = ip->img;
|
|
|
|
gimp_pixel_rgn_init (&pixel_rgn, drw, 0, 0, drw_width, drw_height,
|
|
|
|
FALSE, FALSE);
|
|
|
|
row_start = row_end = -1;
|
|
|
|
|
|
|
|
/* Get the pixels for the preview from the drawable */
|
|
|
|
for (y = 0; y < prv_height; y++)
|
|
|
|
{
|
|
|
|
src_y = (drw_height * y) / prv_height;
|
|
|
|
if (src_y > row_end) /* Need new row ? */
|
|
|
|
{
|
|
|
|
row_start = (src_y / tile_height) * tile_height;
|
|
|
|
row_end = row_start+tile_height-1;
|
|
|
|
if (row_end > drw_height-1) row_end = drw_height-1;
|
|
|
|
gimp_pixel_rgn_get_rect (&pixel_rgn, img_data, 0, row_start, drw_width,
|
|
|
|
row_end-row_start+1);
|
|
|
|
}
|
|
|
|
cu_row = img_data + (src_y-row_start)*drw_width*bpp;
|
|
|
|
for (x = 0; x < prv_width; x++)
|
|
|
|
{
|
|
|
|
src_x = (drw_width * x) / prv_width;
|
|
|
|
memcpy (prv_data, cu_row+bpp*src_x, 3);
|
|
|
|
prv_data += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_drawable_detach (drw);
|
|
|
|
g_free (img_data);
|
|
|
|
return ip;
|
2000-03-24 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
|
|
|
query (void)
|
|
|
|
|
|
|
|
{
|
2000-08-22 01:26:57 +00:00
|
|
|
static GimpParamDef adjust_args[] =
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2004-09-28 23:08:17 +00:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (not used)" },
|
2000-08-22 01:26:57 +00:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable to adjust" }
|
1998-11-06 00:51:39 +00:00
|
|
|
};
|
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
static GimpParamDef map_args[] =
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2004-09-28 23:08:17 +00:00
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image (not used)" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable where colors are to map" },
|
|
|
|
{ GIMP_PDB_COLOR, "srccolor_1", "First source color" },
|
|
|
|
{ GIMP_PDB_COLOR, "srccolor_2", "Second source color" },
|
|
|
|
{ GIMP_PDB_COLOR, "dstcolor_1", "First destination color" },
|
|
|
|
{ GIMP_PDB_COLOR, "dstcolor_2", "Second destination color" },
|
|
|
|
{ GIMP_PDB_INT32, "map_mode", "Mapping mode (0: linear, others reserved)" }
|
1998-11-06 00:51:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
gimp_install_procedure ("plug_in_color_adjust",
|
2000-03-24 16:21:35 +00:00
|
|
|
"Adjust color range given by foreground/background "
|
|
|
|
"color to black/white",
|
|
|
|
"The current foreground color is mapped to black "
|
|
|
|
"(black point), the current background color is "
|
|
|
|
"mapped to white (white point). Intermediate "
|
|
|
|
"colors are interpolated",
|
1998-11-06 00:51:39 +00:00
|
|
|
"Peter Kirchgessner",
|
|
|
|
"Peter Kirchgessner",
|
|
|
|
dversio,
|
2004-05-07 13:15:52 +00:00
|
|
|
N_("Adjust _FG-BG"),
|
1998-11-06 00:51:39 +00:00
|
|
|
"RGB*",
|
2000-08-22 01:26:57 +00:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 02:28:58 +00:00
|
|
|
G_N_ELEMENTS (adjust_args), 0,
|
1998-11-06 00:51:39 +00:00
|
|
|
adjust_args, NULL);
|
|
|
|
|
2004-05-07 13:15:52 +00:00
|
|
|
gimp_plugin_menu_register ("plug_in_color_adjust",
|
|
|
|
N_("<Image>/Filters/Colors/Map"));
|
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
gimp_install_procedure ("plug_in_color_map",
|
2000-03-24 16:21:35 +00:00
|
|
|
"Map color range specified by two colors"
|
2004-08-01 17:16:42 +00:00
|
|
|
"to color range specified by two other color.",
|
2000-03-24 16:21:35 +00:00
|
|
|
"Map color range specified by two colors"
|
2004-08-01 17:16:42 +00:00
|
|
|
"to color range specified by two other color."
|
2000-03-24 16:21:35 +00:00
|
|
|
"Intermediate colors are interpolated.",
|
1998-11-06 00:51:39 +00:00
|
|
|
"Peter Kirchgessner",
|
|
|
|
"Peter Kirchgessner",
|
|
|
|
dversio,
|
2004-05-07 13:15:52 +00:00
|
|
|
N_("Color Range _Mapping..."),
|
1998-11-06 00:51:39 +00:00
|
|
|
"RGB*",
|
2000-08-22 01:26:57 +00:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 02:28:58 +00:00
|
|
|
G_N_ELEMENTS (map_args), 0,
|
1998-11-06 00:51:39 +00:00
|
|
|
map_args, NULL);
|
2004-05-07 13:15:52 +00:00
|
|
|
|
|
|
|
gimp_plugin_menu_register ("plug_in_color_map",
|
|
|
|
N_("<Image>/Filters/Colors/Map"));
|
1998-11-06 00:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-07-02 12:03:08 +00:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
{
|
2001-01-15 00:06:43 +00:00
|
|
|
static GimpParam values[1];
|
2001-12-29 13:26:29 +00:00
|
|
|
GimpRunMode run_mode;
|
2001-01-15 00:06:43 +00:00
|
|
|
GimpDrawable *drawable = NULL;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2001-12-29 13:26:29 +00:00
|
|
|
gint j;
|
2001-01-15 00:06:43 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
INIT_I18N ();
|
1999-11-24 23:58:46 +00:00
|
|
|
|
2004-09-28 23:08:17 +00:00
|
|
|
run_mode = param[0].data.d_int32;
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2001-12-29 13:26:29 +00:00
|
|
|
*return_vals = values;
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2001-12-29 13:26:29 +00:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1998-11-06 00:51:39 +00:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
while (status == GIMP_PDB_SUCCESS)
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2000-01-11 15:48:00 +00:00
|
|
|
if (nparams < 3)
|
2004-08-01 17:16:42 +00:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
|
|
|
/* Make sure the drawable is RGB color */
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
2001-06-14 20:07:38 +00:00
|
|
|
if (!gimp_drawable_is_rgb (drawable->drawable_id))
|
2004-08-01 17:16:42 +00:00
|
|
|
{
|
|
|
|
g_message (_("Cannot operate on gray or indexed color images."));
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
|
|
|
if (strcmp (name, "plug_in_color_adjust") == 0)
|
2004-08-01 17:16:42 +00:00
|
|
|
{
|
|
|
|
if (nparams != 3) /* Make sure all the arguments are there */
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-09-22 18:43:09 +00:00
|
|
|
gimp_context_get_foreground (plvals.colors);
|
|
|
|
gimp_context_get_background (plvals.colors + 1);
|
2000-02-07 20:35:13 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
gimp_rgb_set (plvals.colors + 2, 0.0, 0.0, 0.0);
|
|
|
|
gimp_rgb_set (plvals.colors + 3, 1.0, 1.0, 1.0);
|
2000-02-07 20:35:13 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
plvals.map_mode = 0;
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2003-06-13 14:37:00 +00:00
|
|
|
gimp_progress_init (_("Adjusting Foreground/Background..."));
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
color_mapping (drawable);
|
|
|
|
break;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
|
|
|
if (strcmp (name, "plug_in_color_map") == 0)
|
2004-08-01 17:16:42 +00:00
|
|
|
{
|
|
|
|
if (run_mode == GIMP_RUN_NONINTERACTIVE)
|
|
|
|
{
|
|
|
|
if (nparams != 8) /* Make sure all the arguments are there */
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
|
|
|
plvals.colors[j] = param[3+j].data.d_color;
|
|
|
|
}
|
|
|
|
plvals.map_mode = param[7].data.d_int32;
|
|
|
|
}
|
|
|
|
else if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
{
|
|
|
|
gimp_get_data (name, &plvals);
|
|
|
|
|
2004-09-22 18:43:09 +00:00
|
|
|
gimp_context_get_foreground (plvals.colors);
|
|
|
|
gimp_context_get_background (plvals.colors + 1);
|
2004-08-01 17:16:42 +00:00
|
|
|
|
|
|
|
if (!dialog (param[2].data.d_drawable))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (run_mode == GIMP_RUN_WITH_LAST_VALS)
|
|
|
|
{
|
|
|
|
gimp_get_data (name, &plvals);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2003-06-13 14:37:00 +00:00
|
|
|
gimp_progress_init (_("Mapping colors..."));
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
color_mapping (drawable);
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_set_data (name, &plvals, sizeof (plvals));
|
2000-01-11 15:48:00 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1998-11-06 00:51:39 +00:00
|
|
|
}
|
|
|
|
|
2000-08-22 01:26:57 +00:00
|
|
|
if ((status == GIMP_PDB_SUCCESS) && (run_mode != GIMP_RUN_NONINTERACTIVE))
|
1998-11-06 00:51:39 +00:00
|
|
|
gimp_displays_flush ();
|
|
|
|
|
2004-09-28 23:08:17 +00:00
|
|
|
if (drawable != NULL)
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
static void
|
|
|
|
update_img_preview (void)
|
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
{
|
|
|
|
IMG_PREVIEW *dst_ip = plinterface.map_preview;
|
|
|
|
IMG_PREVIEW *src_ip = plinterface.img_preview;
|
2004-09-28 23:08:17 +00:00
|
|
|
GtkWidget *preview = plinterface.preview;
|
|
|
|
guchar redmap[256], greenmap[256], bluemap[256];
|
|
|
|
guchar *src, *dst;
|
|
|
|
gint j;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
if ((dst_ip == NULL) || (src_ip == NULL)) return;
|
2003-11-06 15:27:05 +00:00
|
|
|
|
|
|
|
get_mapping (plvals.colors,
|
2004-08-01 17:16:42 +00:00
|
|
|
plvals.colors + 1,
|
|
|
|
plvals.colors + 2,
|
|
|
|
plvals.colors + 3,
|
|
|
|
plvals.map_mode,
|
2001-01-14 20:25:46 +00:00
|
|
|
redmap, greenmap, bluemap);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2001-01-14 20:25:46 +00:00
|
|
|
j = dst_ip->width*dst_ip->height;
|
|
|
|
src = src_ip->img;
|
|
|
|
dst = dst_ip->img;
|
|
|
|
|
|
|
|
while (j-- > 0)
|
|
|
|
{
|
|
|
|
*(dst++) = redmap[*(src++)];
|
|
|
|
*(dst++) = greenmap[*(src++)];
|
|
|
|
*(dst++) = bluemap[*(src++)];
|
|
|
|
}
|
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
|
|
|
|
0, 0, dst_ip->width, dst_ip->height,
|
|
|
|
GIMP_RGB_IMAGE,
|
|
|
|
dst_ip->img,
|
|
|
|
dst_ip->width*3);
|
2001-01-14 20:25:46 +00:00
|
|
|
}
|
2000-03-24 16:21:35 +00:00
|
|
|
|
2000-05-01 17:01:18 +00:00
|
|
|
static gboolean
|
2000-03-24 16:21:35 +00:00
|
|
|
dialog (gint32 drawable_ID)
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2003-11-06 15:27:05 +00:00
|
|
|
GtkWidget *dlg;
|
2004-05-19 16:51:32 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *frame;
|
2003-11-06 15:27:05 +00:00
|
|
|
GtkWidget *table;
|
2000-03-24 16:21:35 +00:00
|
|
|
IMG_PREVIEW *ip;
|
2003-11-06 15:27:05 +00:00
|
|
|
gint j;
|
|
|
|
gboolean run;
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2000-05-01 17:01:18 +00:00
|
|
|
gimp_ui_init ("mapcolor", TRUE);
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
memset (&plinterface, 0, sizeof (plinterface));
|
|
|
|
|
|
|
|
dlg = gimp_dialog_new (_("Map Color Range"), "mapcolor",
|
2003-11-06 15:27:05 +00:00
|
|
|
NULL, 0,
|
2004-08-01 17:16:42 +00:00
|
|
|
gimp_standard_help_func, "plug-in-color-map",
|
2000-01-07 10:39:33 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
NULL);
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2004-05-19 16:51:32 +00:00
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2000-03-24 16:21:35 +00:00
|
|
|
/* Preview */
|
|
|
|
ip = img_preview_create_from_drawable (IMG_PRV_SIZE, drawable_ID);
|
|
|
|
if (ip)
|
2000-05-01 17:01:18 +00:00
|
|
|
{
|
2004-05-19 16:51:32 +00:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *preview;
|
|
|
|
|
2000-05-01 17:01:18 +00:00
|
|
|
plinterface.img_preview = ip;
|
|
|
|
img_preview_copy (plinterface.img_preview, &(plinterface.map_preview));
|
|
|
|
|
2004-05-19 16:51:32 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
2000-05-01 17:01:18 +00:00
|
|
|
|
2004-05-19 16:51:32 +00:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
2000-05-01 17:01:18 +00:00
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
preview = gimp_preview_area_new ();
|
2000-05-01 17:01:18 +00:00
|
|
|
plinterface.preview = preview;
|
2004-08-01 17:16:42 +00:00
|
|
|
gtk_widget_set_size_request (preview, ip->width, ip->height);
|
2004-05-19 16:51:32 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
2000-05-01 17:01:18 +00:00
|
|
|
gtk_widget_show (preview);
|
|
|
|
}
|
2000-03-24 16:21:35 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 2; j++)
|
2000-05-01 17:01:18 +00:00
|
|
|
{
|
2004-05-19 16:51:32 +00:00
|
|
|
frame = gimp_frame_new ((j == 0) ?
|
|
|
|
_("Source color range") :
|
|
|
|
_("Destination color range"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
2000-05-01 17:01:18 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
/* The table keeps the color selections */
|
|
|
|
table = gtk_table_new (1, 4, FALSE);
|
2004-05-19 16:51:32 +00:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
2000-05-01 17:01:18 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
add_color_button (j * 2, 0, 0, table);
|
|
|
|
add_color_button (j * 2 + 1, 2, 0, table);
|
|
|
|
}
|
2000-03-24 16:21:35 +00:00
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
gtk_widget_show (dlg);
|
|
|
|
|
2004-08-01 17:16:42 +00:00
|
|
|
update_img_preview ();
|
|
|
|
|
2003-11-11 18:11:56 +00:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
|
2003-11-06 15:27:05 +00:00
|
|
|
|
|
|
|
if (run)
|
|
|
|
plvals.map_mode = 0; /* Currently always linear mapping */
|
|
|
|
|
|
|
|
gtk_widget_destroy (dlg);
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
img_preview_free (plinterface.img_preview);
|
|
|
|
img_preview_free (plinterface.map_preview);
|
|
|
|
|
|
|
|
return run;
|
1998-11-06 00:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-01-11 15:48:00 +00:00
|
|
|
add_color_button (gint csel_index,
|
|
|
|
gint left,
|
|
|
|
gint top,
|
1999-11-15 19:46:06 +00:00
|
|
|
GtkWidget *table)
|
1998-11-06 00:51:39 +00:00
|
|
|
{
|
2000-01-11 15:48:00 +00:00
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
button = gimp_color_button_new (gettext (csel_title[csel_index]),
|
2004-08-01 17:16:42 +00:00
|
|
|
PRV_WIDTH, PRV_HEIGHT,
|
|
|
|
&plvals.colors[csel_index],
|
|
|
|
GIMP_COLOR_AREA_FLAT);
|
2003-11-06 15:27:05 +00:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), left + 1, top,
|
2004-08-01 17:16:42 +00:00
|
|
|
(left == 0) ? _("From:") : _("To:"),
|
|
|
|
0.0, 0.5,
|
|
|
|
button, 1, TRUE);
|
2001-12-29 13:26:29 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
g_signal_connect (button, "color_changed",
|
|
|
|
G_CALLBACK (gimp_color_button_get_color),
|
2001-12-29 13:26:29 +00:00
|
|
|
&plvals.colors[csel_index]);
|
2003-01-07 06:16:02 +00:00
|
|
|
g_signal_connect (button, "color_changed",
|
2001-12-29 13:26:29 +00:00
|
|
|
G_CALLBACK (update_img_preview),
|
|
|
|
NULL);
|
1998-11-06 00:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-14 20:25:46 +00:00
|
|
|
get_mapping (GimpRGB *src_col1,
|
|
|
|
GimpRGB *src_col2,
|
|
|
|
GimpRGB *dst_col1,
|
|
|
|
GimpRGB *dst_col2,
|
|
|
|
gint32 map_mode,
|
|
|
|
guchar *redmap,
|
|
|
|
guchar *greenmap,
|
|
|
|
guchar *bluemap)
|
1999-11-15 19:46:06 +00:00
|
|
|
{
|
2001-01-14 20:25:46 +00:00
|
|
|
guchar src1[3];
|
|
|
|
guchar src2[3];
|
|
|
|
guchar dst1[3];
|
|
|
|
guchar dst2[3];
|
2003-09-13 18:07:44 +00:00
|
|
|
gint rgb, i, a, as, b, bs;
|
1999-11-15 19:46:06 +00:00
|
|
|
guchar *colormap[3];
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
/* Currently we always do a linear mapping */
|
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
colormap[0] = redmap;
|
|
|
|
colormap[1] = greenmap;
|
|
|
|
colormap[2] = bluemap;
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
gimp_rgb_get_uchar (src_col1, src1, src1 + 1, src1 + 2);
|
|
|
|
gimp_rgb_get_uchar (src_col2, src2, src2 + 1, src2 + 2);
|
|
|
|
gimp_rgb_get_uchar (dst_col1, dst1, dst1 + 1, dst1 + 2);
|
|
|
|
gimp_rgb_get_uchar (dst_col2, dst2, dst2 + 1, dst2 + 2);
|
2001-01-14 20:25:46 +00:00
|
|
|
|
2000-01-11 15:48:00 +00:00
|
|
|
switch (map_mode)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
for (rgb = 0; rgb < 3; rgb++)
|
2004-08-01 17:16:42 +00:00
|
|
|
{
|
|
|
|
a = src1[rgb]; as = dst1[rgb];
|
|
|
|
b = src2[rgb]; bs = dst2[rgb];
|
2001-01-14 20:25:46 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
if (b == a)
|
2004-08-01 17:16:42 +00:00
|
|
|
b = a + 1;
|
|
|
|
for (i = 0; i < 256; i++)
|
2002-11-05 23:01:04 +00:00
|
|
|
{
|
2004-08-01 17:16:42 +00:00
|
|
|
gint j = ((i - a) * (bs - as)) / (b - a) + as;
|
2003-09-13 18:07:44 +00:00
|
|
|
colormap[rgb][i] = CLAMP0255(j);
|
2002-11-05 23:01:04 +00:00
|
|
|
}
|
2004-08-01 17:16:42 +00:00
|
|
|
}
|
2000-01-11 15:48:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
static void
|
2003-09-13 18:07:44 +00:00
|
|
|
mapcolor_func (const guchar *src,
|
2004-08-01 17:16:42 +00:00
|
|
|
guchar *dest,
|
|
|
|
gint bpp,
|
|
|
|
gpointer data)
|
2003-09-13 18:07:44 +00:00
|
|
|
{
|
|
|
|
dest[0] = redmap[src[0]];
|
|
|
|
dest[1] = greenmap[src[1]];
|
|
|
|
dest[2] = bluemap[src[2]];
|
2003-11-06 15:27:05 +00:00
|
|
|
if (bpp > 3)
|
2003-09-13 18:07:44 +00:00
|
|
|
dest[3] = src[3];
|
|
|
|
}
|
|
|
|
|
1998-11-06 00:51:39 +00:00
|
|
|
static void
|
2000-08-22 01:26:57 +00:00
|
|
|
color_mapping (GimpDrawable *drawable)
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
{
|
2001-01-14 20:25:46 +00:00
|
|
|
if (gimp_rgb_distance (&plvals.colors[0], &plvals.colors[1]) < 0.0001)
|
|
|
|
return;
|
1998-11-06 00:51:39 +00:00
|
|
|
|
2001-06-14 20:07:38 +00:00
|
|
|
if (!gimp_drawable_is_rgb (drawable->drawable_id))
|
2000-03-24 16:21:35 +00:00
|
|
|
{
|
2003-11-15 13:53:33 +00:00
|
|
|
g_message (_("Cannot operate on gray or indexed color images."));
|
2000-03-24 16:21:35 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-11-06 00:51:39 +00:00
|
|
|
|
|
|
|
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
|
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
get_mapping (plvals.colors,
|
2004-08-01 17:16:42 +00:00
|
|
|
plvals.colors + 1,
|
|
|
|
plvals.colors + 2,
|
|
|
|
plvals.colors + 3,
|
|
|
|
plvals.map_mode,
|
1998-11-06 00:51:39 +00:00
|
|
|
redmap, greenmap, bluemap);
|
|
|
|
|
2004-09-28 23:08:17 +00:00
|
|
|
gimp_rgn_iterate2 (drawable, 0 /* unused */, mapcolor_func, NULL);
|
1998-11-06 00:51:39 +00:00
|
|
|
}
|