~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/ccanalyze.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "config.h"
27
27
 
28
28
#include <string.h>
29
 
#include <sys/stat.h>
30
29
 
31
 
#include <gtk/gtk.h>
 
30
#include <glib/gstdio.h>
32
31
 
33
32
#include <libgimp/gimp.h>
34
33
#include <libgimp/gimpui.h>
35
34
 
36
35
#include "libgimp/stdplugins-intl.h"
37
36
 
 
37
 
 
38
#define PLUG_IN_PROC   "plug-in-ccanalyze"
 
39
#define PLUG_IN_BINARY "ccanalyze"
 
40
 
 
41
/* size of histogram image */
 
42
#define PREWIDTH  256
 
43
#define PREHEIGHT 150
 
44
 
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);
62
69
 
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;
70
76
 
71
 
/* size of histogram image */
72
 
static const int PREWIDTH = 256;
73
 
static const int PREHEIGHT = 150;
74
 
 
75
77
/* lets declare what we want to do */
76
 
GimpPlugInInfo PLUG_IN_INFO =
 
78
const GimpPlugInInfo PLUG_IN_INFO =
77
79
{
78
80
  NULL,  /* init_proc  */
79
81
  NULL,  /* quit_proc  */
88
90
static void
89
91
query (void)
90
92
{
91
 
  static GimpParamDef args[] =
92
 
  {
93
 
    { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive" },
94
 
    { GIMP_PDB_IMAGE,    "image",    "Input image" },
95
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }
96
 
  };
97
 
 
98
 
  static GimpParamDef return_vals[] =
99
 
  {
100
 
    { GIMP_PDB_INT32, "num_colors", "Number of colors in the image" }
101
 
  };
102
 
 
103
 
  gimp_install_procedure ("plug_in_ccanalyze",
104
 
                          "Colorcube analysis",
 
93
  static const GimpParamDef args[] =
 
94
  {
 
95
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive" },
 
96
    { GIMP_PDB_IMAGE,    "image",    "Input image"                  },
 
97
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"               }
 
98
  };
 
99
 
 
100
  static const GimpParamDef return_vals[] =
 
101
  {
 
102
    { GIMP_PDB_INT32, "num-colors", "Number of colors in the image" }
 
103
  };
 
104
 
 
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);
115
117
 
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");
118
119
}
119
120
 
120
121
/* main function */
135
136
  INIT_I18N ();
136
137
 
137
138
  *nreturn_vals = 2;
138
 
  *return_vals = values;
 
139
  *return_vals  = values;
139
140
 
140
141
  if (run_mode == GIMP_RUN_NONINTERACTIVE)
141
142
    {
146
147
  if (status == GIMP_PDB_SUCCESS)
147
148
    {
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;
150
151
 
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));
158
159
 
159
 
          filename = gimp_image_get_filename (imageID);
160
 
 
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));
162
162
 
163
163
          analyze (drawable);
164
164
 
197
197
  gint          ofsx, ofsy;
198
198
  GimpDrawable *selDrawable;
199
199
 
200
 
  gimp_progress_init (_("Colorcube Analysis..."));
 
200
  gimp_progress_init (_("Colorcube Analysis"));
201
201
 
202
202
  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
203
203
 
345
345
static void
346
346
doDialog (void)
347
347
{
348
 
  GtkWidget   *dialog;
349
 
  GtkWidget   *vbox;
350
 
  GtkWidget   *hbox;
351
 
  GtkWidget   *frame;
352
 
  GtkWidget   *preview;
353
 
  gchar       *memsize;
354
 
  struct stat  st;
355
 
 
356
 
  gimp_ui_init ("ccanalyze", TRUE);
357
 
 
358
 
  dialog = gimp_dialog_new (_("Colorcube Analysis"), "ccanalyze",
 
348
  GtkWidget *dialog;
 
349
  GtkWidget *vbox;
 
350
  GtkWidget *hbox;
 
351
  GtkWidget *frame;
 
352
  GtkWidget *preview;
 
353
 
 
354
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
 
355
 
 
356
  dialog = gimp_dialog_new (_("Colorcube Analysis"), PLUG_IN_BINARY,
359
357
                            NULL, 0,
360
 
                            gimp_standard_help_func, "plug-in-ccanalyze",
 
358
                            gimp_standard_help_func, PLUG_IN_PROC,
361
359
 
362
360
                            GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
363
361
 
364
362
                            NULL);
365
363
 
 
364
  gimp_window_set_transient (GTK_WINDOW (dialog));
 
365
 
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);
382
382
 
383
383
  /* output results */
384
 
  doLabel (vbox, _("Image dimensions: %d x %d"), width, height);
 
384
  doLabel (vbox, _("Image dimensions: %d × %d"), width, height);
385
385
 
386
386
  if (uniques == 0)
387
387
    doLabel (vbox, _("No colors"));
390
390
  else
391
391
    doLabel (vbox, _("Number of unique colors: %d"), uniques);
392
392
 
393
 
  memsize = gimp_memsize_to_string (width * height * bpp);
394
 
  doLabel (vbox, _("Uncompressed size: %s"), memsize);
395
 
  g_free (memsize);
396
 
 
397
 
  if (filename && !stat (filename, &st) && !gimp_image_is_dirty (imageID))
398
 
    {
399
 
      gchar *memsize = gimp_memsize_to_string (st.st_size);
400
 
 
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));
405
 
 
406
 
      g_free (memsize);
407
 
    }
408
 
 
409
393
  /* show stuff */
410
394
  gtk_widget_show_all (dialog);
411
395