26
26
#include "config.h"
28
28
#include <string.h>
30
#include <glib/gstdio.h>
33
32
#include <libgimp/gimp.h>
34
33
#include <libgimp/gimpui.h>
36
35
#include "libgimp/stdplugins-intl.h"
38
#define PLUG_IN_PROC "plug-in-ccanalyze"
39
#define PLUG_IN_BINARY "ccanalyze"
41
/* size of histogram image */
38
45
/* lets prototype */
39
46
static void query (void);
40
47
static void run (const gchar *name,
61
68
...) G_GNUC_PRINTF (2, 3);
63
70
/* some global variables */
64
static gchar *filename = NULL;
65
71
static gint width, height, bpp;
66
72
static gdouble hist_red[256], hist_green[256], hist_blue[256];
67
73
static gdouble maxred = 0.0, maxgreen = 0.0, maxblue = 0.0;
68
74
static gint uniques = 0;
69
75
static gint32 imageID;
71
/* size of histogram image */
72
static const int PREWIDTH = 256;
73
static const int PREHEIGHT = 150;
75
77
/* lets declare what we want to do */
76
GimpPlugInInfo PLUG_IN_INFO =
78
const GimpPlugInInfo PLUG_IN_INFO =
78
80
NULL, /* init_proc */
79
81
NULL, /* quit_proc */
91
static GimpParamDef args[] =
93
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
94
{ GIMP_PDB_IMAGE, "image", "Input image" },
95
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
98
static GimpParamDef return_vals[] =
100
{ GIMP_PDB_INT32, "num_colors", "Number of colors in the image" }
103
gimp_install_procedure ("plug_in_ccanalyze",
104
"Colorcube analysis",
93
static const GimpParamDef args[] =
95
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
96
{ GIMP_PDB_IMAGE, "image", "Input image" },
97
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
100
static const GimpParamDef return_vals[] =
102
{ GIMP_PDB_INT32, "num-colors", "Number of colors in the image" }
105
gimp_install_procedure (PLUG_IN_PROC,
106
N_("Analyze the set of colors in the image"),
105
107
"Analyze colorcube and print some information about "
106
108
"the current image (also displays a color-histogram)",
107
109
"robert@experimental.net",
113
115
G_N_ELEMENTS (args), G_N_ELEMENTS (return_vals),
114
116
args, return_vals);
116
gimp_plugin_menu_register ("plug_in_ccanalyze", "<Image>/Filters/Colors");
117
gimp_plugin_menu_register ("plug_in_ccanalyze", "<Image>/Layer/Colors/Info");
118
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Info");
120
121
/* main function */
146
147
if (status == GIMP_PDB_SUCCESS)
148
149
drawable = gimp_drawable_get (param[2].data.d_drawable);
149
imageID = param[1].data.d_image;
150
imageID = param[1].data.d_image;
151
152
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
152
153
gimp_drawable_is_gray (drawable->drawable_id) ||
156
157
memset (hist_green, 0, sizeof (hist_green));
157
158
memset (hist_blue, 0, sizeof (hist_blue));
159
filename = gimp_image_get_filename (imageID);
161
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
160
gimp_tile_cache_ntiles (2 *
161
(drawable->width / gimp_tile_width () + 1));
163
163
analyze (drawable);
198
198
GimpDrawable *selDrawable;
200
gimp_progress_init (_("Colorcube Analysis..."));
200
gimp_progress_init (_("Colorcube Analysis"));
202
202
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
356
gimp_ui_init ("ccanalyze", TRUE);
358
dialog = gimp_dialog_new (_("Colorcube Analysis"), "ccanalyze",
354
gimp_ui_init (PLUG_IN_BINARY, TRUE);
356
dialog = gimp_dialog_new (_("Colorcube Analysis"), PLUG_IN_BINARY,
360
gimp_standard_help_func, "plug-in-ccanalyze",
358
gimp_standard_help_func, PLUG_IN_PROC,
362
360
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
364
gimp_window_set_transient (GTK_WINDOW (dialog));
366
366
vbox = gtk_vbox_new (FALSE, 6);
367
367
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
368
368
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox,
381
381
gtk_container_add (GTK_CONTAINER (frame), preview);
383
383
/* output results */
384
doLabel (vbox, _("Image dimensions: %d x %d"), width, height);
384
doLabel (vbox, _("Image dimensions: %d × %d"), width, height);
386
386
if (uniques == 0)
387
387
doLabel (vbox, _("No colors"));
391
391
doLabel (vbox, _("Number of unique colors: %d"), uniques);
393
memsize = gimp_memsize_to_string (width * height * bpp);
394
doLabel (vbox, _("Uncompressed size: %s"), memsize);
397
if (filename && !stat (filename, &st) && !gimp_image_is_dirty (imageID))
399
gchar *memsize = gimp_memsize_to_string (st.st_size);
401
doLabel (vbox, _("Filename: %s"), filename);
402
doLabel (vbox, _("Compressed size: %s"), memsize);
403
doLabel (vbox, _("Compression ratio (approx.): %d to 1"),
404
(gint) RINT ((gdouble) (width * height * bpp) / st.st_size));
410
394
gtk_widget_show_all (dialog);