2003-09-04 01:52:26 +08:00
|
|
|
|
/*
|
2007-06-06 16:44:52 +08:00
|
|
|
|
* This is a plug-in for GIMP.
|
2003-09-04 01:52:26 +08:00
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-09-04 01:52:26 +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-09-04 01:52:26 +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-09-04 01:52:26 +08:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Analyze colorcube.
|
|
|
|
|
*
|
|
|
|
|
* Author: robert@experimental.net
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
|
#include <glib/gstdio.h>
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
|
#define PLUG_IN_PROC "plug-in-ccanalyze"
|
2008-03-24 23:29:55 +08:00
|
|
|
|
#define PLUG_IN_BINARY "color-cube-analyze"
|
2011-04-09 02:31:34 +08:00
|
|
|
|
#define PLUG_IN_ROLE "gimp-color-cube-analyze"
|
2005-08-14 02:29:14 +08:00
|
|
|
|
|
|
|
|
|
/* size of histogram image */
|
|
|
|
|
#define PREWIDTH 256
|
|
|
|
|
#define PREHEIGHT 150
|
|
|
|
|
|
2003-09-04 01:52:26 +08:00
|
|
|
|
/* lets prototype */
|
|
|
|
|
static void query (void);
|
|
|
|
|
static void run (const gchar *name,
|
|
|
|
|
gint n_params,
|
|
|
|
|
const GimpParam *param,
|
|
|
|
|
gint *nreturn_vals,
|
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
static void doDialog (void);
|
|
|
|
|
static void analyze (GimpDrawable *drawable);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
static void histogram (guchar r,
|
|
|
|
|
guchar g,
|
|
|
|
|
guchar b,
|
|
|
|
|
gdouble a);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
static void fillPreview (GtkWidget *preview);
|
2003-09-04 03:22:49 +08:00
|
|
|
|
static void insertcolor (guchar r,
|
|
|
|
|
guchar g,
|
|
|
|
|
guchar b,
|
|
|
|
|
gdouble a);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
static void doLabel (GtkWidget *table,
|
|
|
|
|
const char *format,
|
|
|
|
|
...) G_GNUC_PRINTF (2, 3);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/* some global variables */
|
|
|
|
|
static gint width, height, bpp;
|
2003-09-04 03:22:49 +08:00
|
|
|
|
static gdouble hist_red[256], hist_green[256], hist_blue[256];
|
|
|
|
|
static gdouble maxred = 0.0, maxgreen = 0.0, maxblue = 0.0;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
static gint uniques = 0;
|
|
|
|
|
static gint32 imageID;
|
|
|
|
|
|
|
|
|
|
/* lets declare what we want to do */
|
2006-05-16 20:26:20 +08:00
|
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
|
|
|
|
NULL, /* init_proc */
|
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
|
query, /* query_proc */
|
|
|
|
|
run, /* run_proc */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* run program */
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
|
|
/* tell GIMP who we are */
|
|
|
|
|
static void
|
|
|
|
|
query (void)
|
|
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
|
static const GimpParamDef args[] =
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2009-04-12 00:57:42 +08:00
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
|
2003-09-04 01:52:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
|
static const GimpParamDef return_vals[] =
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2005-08-14 02:29:14 +08:00
|
|
|
|
{ GIMP_PDB_INT32, "num-colors", "Number of colors in the image" }
|
2003-09-04 01:52:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-16 05:10:34 +08:00
|
|
|
|
N_("Analyze the set of colors in the image"),
|
2003-09-04 01:52:26 +08:00
|
|
|
|
"Analyze colorcube and print some information about "
|
|
|
|
|
"the current image (also displays a color-histogram)",
|
|
|
|
|
"robert@experimental.net",
|
|
|
|
|
"robert@experimental.net",
|
|
|
|
|
"June 20th, 1997",
|
2004-05-07 08:30:24 +08:00
|
|
|
|
N_("Colorcube A_nalysis..."),
|
2003-09-04 01:52:26 +08:00
|
|
|
|
"RGB*, GRAY*, INDEXED*",
|
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
|
G_N_ELEMENTS (args), G_N_ELEMENTS (return_vals),
|
|
|
|
|
args, return_vals);
|
2015-10-02 09:45:37 +08:00
|
|
|
|
|
|
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Info");
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* main function */
|
|
|
|
|
static void
|
|
|
|
|
run (const gchar *name,
|
|
|
|
|
gint n_params,
|
|
|
|
|
const GimpParam *param,
|
|
|
|
|
gint *nreturn_vals,
|
|
|
|
|
GimpParam **return_vals)
|
|
|
|
|
{
|
|
|
|
|
static GimpParam values[2];
|
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
|
|
INIT_I18N ();
|
|
|
|
|
|
|
|
|
|
*nreturn_vals = 2;
|
2005-08-14 02:29:14 +08:00
|
|
|
|
*return_vals = values;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (run_mode == GIMP_RUN_NONINTERACTIVE)
|
|
|
|
|
{
|
|
|
|
|
if (n_params != 3)
|
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
2005-08-14 02:29:14 +08:00
|
|
|
|
imageID = param[1].data.d_image;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
|
|
|
|
|
gimp_drawable_is_gray (drawable->drawable_id) ||
|
|
|
|
|
gimp_drawable_is_indexed (drawable->drawable_id))
|
|
|
|
|
{
|
|
|
|
|
memset (hist_red, 0, sizeof (hist_red));
|
|
|
|
|
memset (hist_green, 0, sizeof (hist_green));
|
|
|
|
|
memset (hist_blue, 0, sizeof (hist_blue));
|
|
|
|
|
|
2006-11-17 16:11:35 +08:00
|
|
|
|
gimp_tile_cache_ntiles (2 *
|
|
|
|
|
(drawable->width / gimp_tile_width () + 1));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
analyze (drawable);
|
|
|
|
|
|
|
|
|
|
/* show dialog after we analyzed image */
|
|
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
|
doDialog ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
|
|
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
|
values[0].data.d_status = status;
|
|
|
|
|
values[1].type = GIMP_PDB_INT32;
|
|
|
|
|
values[1].data.d_int32 = uniques;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* do the analyzing */
|
|
|
|
|
static void
|
|
|
|
|
analyze (GimpDrawable *drawable)
|
|
|
|
|
{
|
|
|
|
|
GimpPixelRgn srcPR;
|
|
|
|
|
guchar *src_row, *cmap;
|
|
|
|
|
gint x, y, numcol;
|
2015-10-02 09:45:37 +08:00
|
|
|
|
gint x1, y1, x2, y2, w, h;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
guchar r, g, b;
|
2003-09-04 03:22:49 +08:00
|
|
|
|
gint a;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
guchar idx;
|
|
|
|
|
gboolean gray;
|
2003-09-04 03:22:49 +08:00
|
|
|
|
gboolean has_alpha;
|
|
|
|
|
gboolean has_sel;
|
|
|
|
|
guchar *sel;
|
|
|
|
|
GimpPixelRgn selPR;
|
|
|
|
|
gint ofsx, ofsy;
|
2004-01-20 06:47:58 +08:00
|
|
|
|
GimpDrawable *selDrawable;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2005-09-30 16:16:10 +08:00
|
|
|
|
gimp_progress_init (_("Colorcube Analysis"));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2015-10-02 09:45:37 +08:00
|
|
|
|
if (! gimp_drawable_mask_intersect (drawable->drawable_id, &x1, &y1, &w, &h))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
x2 = x1 + w;
|
|
|
|
|
y2 = y1 + h;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the size of the input image (this will/must be the same
|
|
|
|
|
* as the size of the output image).
|
|
|
|
|
*/
|
|
|
|
|
width = drawable->width;
|
|
|
|
|
height = drawable->height;
|
|
|
|
|
bpp = drawable->bpp;
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
has_sel = !gimp_selection_is_empty (imageID);
|
|
|
|
|
gimp_drawable_offsets (drawable->drawable_id, &ofsx, &ofsy);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/* initialize the pixel region */
|
|
|
|
|
gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE);
|
|
|
|
|
|
2004-11-02 20:00:25 +08:00
|
|
|
|
cmap = gimp_image_get_colormap (imageID, &numcol);
|
2010-07-09 18:27:36 +08:00
|
|
|
|
gray = (gimp_drawable_is_gray (drawable->drawable_id) ||
|
|
|
|
|
gimp_item_is_channel (drawable->drawable_id));
|
2003-09-04 03:22:49 +08:00
|
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
|
|
|
|
|
|
2004-01-20 06:47:58 +08:00
|
|
|
|
selDrawable = gimp_drawable_get (gimp_image_get_selection (imageID));
|
2003-09-04 03:22:49 +08:00
|
|
|
|
gimp_pixel_rgn_init (&selPR,
|
2004-01-20 06:47:58 +08:00
|
|
|
|
selDrawable,
|
2003-09-04 03:22:49 +08:00
|
|
|
|
0, 0, width, height, FALSE, FALSE);
|
|
|
|
|
|
|
|
|
|
/* allocate row buffer */
|
2004-07-30 20:03:30 +08:00
|
|
|
|
src_row = g_new (guchar, (x2 - x1) * bpp);
|
|
|
|
|
sel = g_new (guchar, x2 - x1);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
for (y = y1; y < y2; y++)
|
|
|
|
|
{
|
|
|
|
|
gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y, (x2 - x1));
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (has_sel)
|
|
|
|
|
gimp_pixel_rgn_get_row (&selPR, sel, x1 + ofsx, y + ofsy, (x2 - x1));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2015-10-02 09:45:37 +08:00
|
|
|
|
for (x = 0; x < w; x++)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2003-09-04 03:22:49 +08:00
|
|
|
|
/* Start with full opacity. */
|
|
|
|
|
a = 255;
|
|
|
|
|
|
2003-09-04 01:52:26 +08:00
|
|
|
|
/*
|
|
|
|
|
* If the image is indexed, fetch RGB values
|
|
|
|
|
* from colormap.
|
|
|
|
|
*/
|
|
|
|
|
if (cmap)
|
|
|
|
|
{
|
2003-09-04 03:22:49 +08:00
|
|
|
|
idx = src_row[x * bpp];
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
r = cmap[idx * 3];
|
|
|
|
|
g = cmap[idx * 3 + 1];
|
|
|
|
|
b = cmap[idx * 3 + 2];
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (has_alpha)
|
|
|
|
|
a = src_row[x * bpp + 1];
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
else if (gray)
|
|
|
|
|
{
|
|
|
|
|
r = g = b = src_row[x * bpp];
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (has_alpha)
|
|
|
|
|
a = src_row[x * bpp + 1];
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
r = src_row[x * bpp];
|
|
|
|
|
g = src_row[x * bpp + 1];
|
|
|
|
|
b = src_row[x * bpp + 2];
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (has_alpha)
|
|
|
|
|
a = src_row[x * bpp + 3];
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (has_sel)
|
|
|
|
|
a *= sel[x];
|
|
|
|
|
else
|
|
|
|
|
a *= 255;
|
|
|
|
|
|
|
|
|
|
if (a != 0)
|
|
|
|
|
insertcolor (r, g, b, (gdouble) a * (1.0 / (255.0 * 255.0)));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* tell the user what we're doing */
|
|
|
|
|
if ((y % 10) == 0)
|
2003-09-04 03:22:49 +08:00
|
|
|
|
gimp_progress_update ((gdouble) y / (gdouble) (y2 - y1));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-03 20:03:35 +08:00
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
|
2003-09-04 01:52:26 +08:00
|
|
|
|
/* clean up */
|
2004-01-20 06:47:58 +08:00
|
|
|
|
gimp_drawable_detach (selDrawable);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
g_free (src_row);
|
2003-09-04 03:22:49 +08:00
|
|
|
|
g_free (sel);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-09-04 03:22:49 +08:00
|
|
|
|
insertcolor (guchar r,
|
|
|
|
|
guchar g,
|
|
|
|
|
guchar b,
|
|
|
|
|
gdouble a)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2004-05-28 04:37:52 +08:00
|
|
|
|
static GHashTable *hash_table;
|
|
|
|
|
guint key;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2004-05-28 04:37:52 +08:00
|
|
|
|
if (!hash_table)
|
|
|
|
|
hash_table = g_hash_table_new (g_direct_hash, g_direct_equal);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2004-05-28 04:37:52 +08:00
|
|
|
|
histogram (r, g, b, a);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2004-05-28 04:37:52 +08:00
|
|
|
|
key = r + 256 * (g + 256 * b);
|
|
|
|
|
if (g_hash_table_lookup (hash_table, GINT_TO_POINTER (key)))
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-30 20:26:11 +08:00
|
|
|
|
g_hash_table_insert (hash_table, GINT_TO_POINTER (key),
|
2004-07-30 20:03:30 +08:00
|
|
|
|
GINT_TO_POINTER (1));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
uniques++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Update RGB count, and keep track of maximum values (which aren't used
|
|
|
|
|
* anywhere as of yet, but they might be useful sometime).
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2003-09-04 03:22:49 +08:00
|
|
|
|
histogram (guchar r,
|
|
|
|
|
guchar g,
|
|
|
|
|
guchar b,
|
|
|
|
|
gdouble a)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2003-09-04 03:22:49 +08:00
|
|
|
|
hist_red[r] += a;
|
|
|
|
|
hist_green[g] += a;
|
|
|
|
|
hist_blue[b] += a;
|
|
|
|
|
|
|
|
|
|
if (hist_red[r] > maxred)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
maxred = hist_red[r];
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (hist_green[g] > maxgreen)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
maxgreen = hist_green[g];
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
if (hist_blue[b] > maxblue)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
maxblue = hist_blue[b];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* show our results */
|
|
|
|
|
static void
|
|
|
|
|
doDialog (void)
|
|
|
|
|
{
|
2006-11-17 16:11:35 +08:00
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
GtkWidget *hbox;
|
|
|
|
|
GtkWidget *frame;
|
|
|
|
|
GtkWidget *preview;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, TRUE);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2011-04-09 02:31:34 +08:00
|
|
|
|
dialog = gimp_dialog_new (_("Colorcube Analysis"), PLUG_IN_ROLE,
|
2003-11-06 23:27:05 +08:00
|
|
|
|
NULL, 0,
|
2005-08-14 02:29:14 +08:00
|
|
|
|
gimp_standard_help_func, PLUG_IN_PROC,
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
|
_("_Close"), GTK_RESPONSE_CLOSE,
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
2005-09-06 05:40:29 +08:00
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2004-11-04 18:06:22 +08:00
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2009-07-16 00:57:12 +08:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
|
vbox, TRUE, TRUE, 0);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-05-19 02:13:48 +08:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2004-05-19 02:13:48 +08: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);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/* use preview for histogram window */
|
2004-07-30 20:03:30 +08:00
|
|
|
|
preview = gimp_preview_area_new ();
|
|
|
|
|
gtk_widget_set_size_request (preview, PREWIDTH, PREHEIGHT);
|
2004-05-19 02:13:48 +08:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), preview);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/* output results */
|
2006-02-28 20:31:04 +08:00
|
|
|
|
doLabel (vbox, _("Image dimensions: %d × %d"), width, height);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (uniques == 0)
|
2004-05-19 02:13:48 +08:00
|
|
|
|
doLabel (vbox, _("No colors"));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
else if (uniques == 1)
|
2004-05-19 02:13:48 +08:00
|
|
|
|
doLabel (vbox, _("Only one unique color"));
|
2003-09-04 01:52:26 +08:00
|
|
|
|
else
|
2004-05-19 02:13:48 +08:00
|
|
|
|
doLabel (vbox, _("Number of unique colors: %d"), uniques);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
/* show stuff */
|
|
|
|
|
gtk_widget_show_all (dialog);
|
|
|
|
|
|
2004-07-30 20:03:30 +08:00
|
|
|
|
fillPreview (preview);
|
|
|
|
|
|
2003-11-12 02:11:56 +08:00
|
|
|
|
gimp_dialog_run (GIMP_DIALOG (dialog));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
|
|
gtk_widget_destroy (dialog);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* shortcut */
|
|
|
|
|
static void
|
2004-05-19 02:13:48 +08:00
|
|
|
|
doLabel (GtkWidget *vbox,
|
|
|
|
|
const gchar *format,
|
2003-09-04 01:52:26 +08:00
|
|
|
|
...)
|
|
|
|
|
{
|
2004-05-19 02:13:48 +08:00
|
|
|
|
GtkWidget *label;
|
|
|
|
|
gchar *text;
|
|
|
|
|
va_list args;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
|
text = g_strdup_vprintf (format, args);
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (text);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2004-05-19 02:13:48 +08:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* fill our preview image with the color-histogram */
|
|
|
|
|
static void
|
|
|
|
|
fillPreview (GtkWidget *preview)
|
|
|
|
|
{
|
2004-07-30 20:26:11 +08:00
|
|
|
|
guchar *image, *column, *pixel;
|
2004-07-30 20:03:30 +08:00
|
|
|
|
gint x, y, rowstride;
|
|
|
|
|
gdouble histcount, val;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
rowstride = PREWIDTH * 3;
|
|
|
|
|
|
2004-07-30 20:26:11 +08:00
|
|
|
|
image = g_new0 (guchar, PREWIDTH * rowstride);
|
|
|
|
|
|
|
|
|
|
for (x = 0, column = image; x < PREWIDTH; x++, column += 3)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* For every channel, calculate a logarithmic value, scale it,
|
|
|
|
|
* and build a one-pixel bar.
|
|
|
|
|
* ... in the respective channel, preserving the other ones. --hb
|
|
|
|
|
*/
|
2003-09-04 03:22:49 +08:00
|
|
|
|
histcount = hist_red[x] > 1.0 ? hist_red[x] : 1.0;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
val = log (histcount) * (PREHEIGHT / 12);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (val > PREHEIGHT)
|
|
|
|
|
val = PREHEIGHT;
|
|
|
|
|
|
2004-07-30 20:26:11 +08:00
|
|
|
|
y = PREHEIGHT - 1;
|
|
|
|
|
pixel = column + (y * rowstride);
|
|
|
|
|
for (; y > (PREHEIGHT - val); y--)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2004-07-30 20:26:11 +08:00
|
|
|
|
pixel[0] = 255;
|
|
|
|
|
pixel -= rowstride;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
histcount = hist_green[x] > 1.0 ? hist_green[x] : 1.0;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
val = log (histcount) * (PREHEIGHT / 12);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (val > PREHEIGHT)
|
|
|
|
|
val = PREHEIGHT;
|
|
|
|
|
|
2004-07-30 20:26:11 +08:00
|
|
|
|
y = PREHEIGHT - 1;
|
|
|
|
|
pixel = column + (y * rowstride);
|
|
|
|
|
for (; y > (PREHEIGHT - val); y--)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2004-07-30 20:26:11 +08:00
|
|
|
|
pixel[1] = 255;
|
|
|
|
|
pixel -= rowstride;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
histcount = hist_blue[x] > 1.0 ? hist_blue[x] : 1.0;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
2003-09-04 03:22:49 +08:00
|
|
|
|
val = log (histcount) * (PREHEIGHT / 12);
|
2003-09-04 01:52:26 +08:00
|
|
|
|
|
|
|
|
|
if (val > PREHEIGHT)
|
|
|
|
|
val = PREHEIGHT;
|
|
|
|
|
|
2004-07-30 20:26:11 +08:00
|
|
|
|
y = PREHEIGHT - 1;
|
|
|
|
|
pixel = column + (y * rowstride);
|
|
|
|
|
for (; y > (PREHEIGHT - val); y--)
|
2003-09-04 01:52:26 +08:00
|
|
|
|
{
|
2004-07-30 20:26:11 +08:00
|
|
|
|
pixel[2] = 255;
|
|
|
|
|
pixel -= rowstride;
|
2003-09-04 01:52:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* move our data into the preview image */
|
2004-07-30 20:03:30 +08:00
|
|
|
|
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
|
|
|
|
|
0, 0, PREWIDTH, PREHEIGHT,
|
|
|
|
|
GIMP_RGB_IMAGE,
|
|
|
|
|
image,
|
|
|
|
|
3 * PREWIDTH);
|
2004-07-30 20:26:11 +08:00
|
|
|
|
|
2003-09-04 01:52:26 +08:00
|
|
|
|
g_free (image);
|
|
|
|
|
}
|