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

« back to all changes in this revision

Viewing changes to plug-ins/common/grid.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:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
39
39
 
40
40
#include "config.h"
41
41
 
42
 
#include <stdlib.h>
43
 
#include <stdio.h>
44
42
#include <string.h>
45
43
 
46
 
#include <gtk/gtk.h>
47
 
 
48
44
#include <libgimp/gimp.h>
49
45
#include <libgimp/gimpui.h>
50
46
 
51
47
#include "libgimp/stdplugins-intl.h"
52
48
 
 
49
 
 
50
#define PLUG_IN_PROC        "plug-in-grid"
 
51
#define PLUG_IN_BINARY      "grid"
53
52
#define SPIN_BUTTON_WIDTH    8
54
53
#define COLOR_BUTTON_WIDTH  55
55
54
 
71
70
static gint        dialog          (gint32         image_ID,
72
71
                                    GimpDrawable  *drawable);
73
72
 
74
 
GimpPlugInInfo PLUG_IN_INFO =
 
73
const GimpPlugInInfo PLUG_IN_INFO =
75
74
{
76
75
  NULL,  /* init_proc  */
77
76
  NULL,  /* quit_proc  */
114
113
static
115
114
void query (void)
116
115
{
117
 
  static GimpParamDef args[] =
 
116
  static const GimpParamDef args[] =
118
117
  {
119
 
    { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive" },
120
 
    { GIMP_PDB_IMAGE,    "image",    "Input image" },
121
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
122
 
 
123
 
    { GIMP_PDB_INT32,    "hwidth",   "Horizontal Width   (>= 0)" },
124
 
    { GIMP_PDB_INT32,    "hspace",   "Horizontal Spacing (>= 1)" },
125
 
    { GIMP_PDB_INT32,    "hoffset",  "Horizontal Offset  (>= 0)" },
126
 
    { GIMP_PDB_COLOR,    "hcolor",   "Horizontal Colour" },
127
 
    { GIMP_PDB_INT8,     "hopacity", "Horizontal Opacity (0...255)" },
128
 
 
129
 
    { GIMP_PDB_INT32,    "vwidth",   "Vertical Width   (>= 0)" },
130
 
    { GIMP_PDB_INT32,    "vspace",   "Vertical Spacing (>= 1)" },
131
 
    { GIMP_PDB_INT32,    "voffset",  "Vertical Offset  (>= 0)" },
132
 
    { GIMP_PDB_COLOR,    "vcolor",   "Vertical Colour" },
133
 
    { GIMP_PDB_INT8,     "vopacity", "Vertical Opacity (0...255)" },
134
 
 
135
 
    { GIMP_PDB_INT32,    "iwidth",   "Intersection Width   (>= 0)" },
136
 
    { GIMP_PDB_INT32,    "ispace",   "Intersection Spacing (>= 0)" },
137
 
    { GIMP_PDB_INT32,    "ioffset",  "Intersection Offset  (>= 0)" },
138
 
    { GIMP_PDB_COLOR,    "icolor",   "Intersection Colour" },
 
118
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive"   },
 
119
    { GIMP_PDB_IMAGE,    "image",    "Input image"                    },
 
120
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"                 },
 
121
 
 
122
    { GIMP_PDB_INT32,    "hwidth",   "Horizontal Width   (>= 0)"      },
 
123
    { GIMP_PDB_INT32,    "hspace",   "Horizontal Spacing (>= 1)"      },
 
124
    { GIMP_PDB_INT32,    "hoffset",  "Horizontal Offset  (>= 0)"      },
 
125
    { GIMP_PDB_COLOR,    "hcolor",   "Horizontal Colour"              },
 
126
    { GIMP_PDB_INT8,     "hopacity", "Horizontal Opacity (0...255)"   },
 
127
 
 
128
    { GIMP_PDB_INT32,    "vwidth",   "Vertical Width   (>= 0)"        },
 
129
    { GIMP_PDB_INT32,    "vspace",   "Vertical Spacing (>= 1)"        },
 
130
    { GIMP_PDB_INT32,    "voffset",  "Vertical Offset  (>= 0)"        },
 
131
    { GIMP_PDB_COLOR,    "vcolor",   "Vertical Colour"                },
 
132
    { GIMP_PDB_INT8,     "vopacity", "Vertical Opacity (0...255)"     },
 
133
 
 
134
    { GIMP_PDB_INT32,    "iwidth",   "Intersection Width   (>= 0)"    },
 
135
    { GIMP_PDB_INT32,    "ispace",   "Intersection Spacing (>= 0)"    },
 
136
    { GIMP_PDB_INT32,    "ioffset",  "Intersection Offset  (>= 0)"    },
 
137
    { GIMP_PDB_COLOR,    "icolor",   "Intersection Colour"            },
139
138
    { GIMP_PDB_INT8,     "iopacity", "Intersection Opacity (0...255)" }
140
139
  };
141
140
 
142
 
  gimp_install_procedure ("plug_in_grid",
143
 
                          "Draws a grid.",
 
141
  gimp_install_procedure (PLUG_IN_PROC,
 
142
                          N_("Draw a grid on the image"),
144
143
                          "Draws a grid using the specified colors. "
145
144
                          "The grid origin is the upper left corner.",
146
145
                          "Tim Newsome",
152
151
                          G_N_ELEMENTS (args), 0,
153
152
                          args, NULL);
154
153
 
155
 
  gimp_plugin_menu_register ("plug_in_grid", "<Image>/Filters/Render/Pattern");
 
154
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Render/Pattern");
156
155
}
157
156
 
158
157
static void
190
189
          grid_cfg.hcolor  = param[6].data.d_color;
191
190
 
192
191
          gimp_rgb_set_alpha (&(grid_cfg.hcolor),
193
 
                              ((double) (guint) param[7].data.d_int8) / 255.0);
 
192
                              ((double) param[7].data.d_int8) / 255.0);
194
193
 
195
194
 
196
195
          grid_cfg.vwidth  = MAX (0, param[8].data.d_int32);
199
198
          grid_cfg.vcolor  = param[11].data.d_color;
200
199
 
201
200
          gimp_rgb_set_alpha (&(grid_cfg.vcolor),
202
 
                              ((double) (guint)  param[12].data.d_int8) / 255.0);
 
201
                              ((double) param[12].data.d_int8) / 255.0);
203
202
 
204
203
 
205
204
 
220
219
      grid_cfg.vcolor = grid_cfg.icolor = grid_cfg.hcolor;
221
220
 
222
221
      /*  Possibly retrieve data  */
223
 
      gimp_get_data ("plug_in_grid", &grid_cfg);
 
222
      gimp_get_data (PLUG_IN_PROC, &grid_cfg);
224
223
    }
225
224
 
226
225
  if (run_mode == GIMP_RUN_INTERACTIVE)
239
238
 
240
239
  if (status == GIMP_PDB_SUCCESS)
241
240
    {
242
 
      gimp_progress_init (_("Drawing Grid..."));
 
241
      gimp_progress_init (_("Drawing grid"));
243
242
      gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
244
243
 
245
244
      grid (image_ID, drawable, NULL);
248
247
        gimp_displays_flush ();
249
248
 
250
249
      if (run_mode == GIMP_RUN_INTERACTIVE)
251
 
        gimp_set_data ("plug_in_grid", &grid_cfg, sizeof (grid_cfg));
 
250
        gimp_set_data (PLUG_IN_PROC, &grid_cfg, sizeof (grid_cfg));
252
251
 
253
252
      gimp_drawable_detach (drawable);
254
253
    }
300
299
{
301
300
  gint b;
302
301
 
303
 
  if (alpha)
304
 
    {
305
 
      bytes--;
306
 
    }
307
 
 
308
302
  if (blend)
309
303
    {
 
304
      if (alpha)
 
305
        bytes--;
 
306
 
310
307
      for (b = 0; b < bytes; b++)
311
308
        {
312
309
          *p1 = *p1 * (1.0 - p2[3]/255.0) + p2[b] * p2[3]/255.0;
321
318
 
322
319
  if (alpha && *p1 < 255)
323
320
    {
324
 
      b = *p1 + 255.0 * ((double)p2[3] / (255.0 - *p1));
 
321
      b = *p1 + 255.0 * ((gdouble) p2[3] / (255.0 - *p1));
 
322
 
325
323
      *p1 = b > 255 ? 255 : b;
326
324
    }
327
325
}
358
356
      break;
359
357
 
360
358
    case GIMP_GRAY:
361
 
      hcolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.hcolor);
362
 
      vcolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.vcolor);
363
 
      icolor[0] = gimp_rgb_intensity_uchar (&grid_cfg.icolor);
 
359
      hcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.hcolor);
 
360
      vcolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.vcolor);
 
361
      icolor[0] = gimp_rgb_luminance_uchar (&grid_cfg.icolor);
364
362
      blend = TRUE;
365
363
      break;
366
364
 
410
408
    {
411
409
      gimp_pixel_rgn_get_row (&srcPR, dest, sx1, y, (sx2 - sx1));
412
410
 
413
 
      y_offset = y - grid_cfg.hoffset;
 
411
      y_offset = y - grid_cfg.voffset;
414
412
      while (y_offset < 0)
415
 
        y_offset += grid_cfg.hspace;
 
413
        y_offset += grid_cfg.vspace;
416
414
 
417
415
      if ((y_offset +
418
 
           (grid_cfg.hwidth / 2)) % grid_cfg.hspace < grid_cfg.hwidth)
 
416
           (grid_cfg.hwidth / 2)) % grid_cfg.vspace < grid_cfg.hwidth)
419
417
        {
420
418
          for (x = sx1; x < sx2; x++)
421
419
            {
426
424
 
427
425
      for (x = sx1; x < sx2; x++)
428
426
        {
429
 
          x_offset = grid_cfg.vspace + x - grid_cfg.voffset;
 
427
          x_offset = grid_cfg.hspace + x - grid_cfg.hoffset;
430
428
          while (x_offset < 0)
431
 
            x_offset += grid_cfg.vspace;
 
429
            x_offset += grid_cfg.hspace;
432
430
 
433
431
          if ((x_offset +
434
 
               (grid_cfg.vwidth / 2)) % grid_cfg.vspace < grid_cfg.vwidth)
 
432
               (grid_cfg.vwidth / 2)) % grid_cfg.hspace < grid_cfg.vwidth)
435
433
            {
436
434
              pix_composite (&dest[(x-sx1) * bytes],
437
435
                             vcolor, bytes, blend, alpha);
438
436
            }
439
437
 
440
438
          if ((x_offset +
441
 
               (grid_cfg.iwidth / 2)) % grid_cfg.vspace < grid_cfg.iwidth
 
439
               (grid_cfg.iwidth / 2)) % grid_cfg.hspace < grid_cfg.iwidth
442
440
              &&
443
 
              ((y_offset % grid_cfg.hspace >= grid_cfg.ispace
 
441
              ((y_offset % grid_cfg.vspace >= grid_cfg.ispace
444
442
                &&
445
 
                y_offset % grid_cfg.hspace < grid_cfg.ioffset)
 
443
                y_offset % grid_cfg.vspace < grid_cfg.ioffset)
446
444
               ||
447
 
               (grid_cfg.hspace -
448
 
                (y_offset % grid_cfg.hspace) >= grid_cfg.ispace
 
445
               (grid_cfg.vspace -
 
446
                (y_offset % grid_cfg.vspace) >= grid_cfg.ispace
449
447
                &&
450
 
                grid_cfg.hspace -
451
 
                (y_offset % grid_cfg.hspace) < grid_cfg.ioffset)))
 
448
                grid_cfg.vspace -
 
449
                (y_offset % grid_cfg.vspace) < grid_cfg.ioffset)))
452
450
            {
453
451
              pix_composite (&dest[(x-sx1) * bytes],
454
452
                             icolor, bytes, blend, alpha);
456
454
        }
457
455
 
458
456
      if ((y_offset +
459
 
           (grid_cfg.iwidth / 2)) % grid_cfg.hspace < grid_cfg.iwidth)
 
457
           (grid_cfg.iwidth / 2)) % grid_cfg.vspace < grid_cfg.iwidth)
460
458
        {
461
459
          for (x = sx1; x < sx2; x++)
462
460
            {
463
 
              x_offset = grid_cfg.vspace + x - grid_cfg.voffset;
 
461
              x_offset = grid_cfg.hspace + x - grid_cfg.hoffset;
464
462
              while (x_offset < 0)
465
 
                x_offset += grid_cfg.vspace;
 
463
                x_offset += grid_cfg.hspace;
466
464
 
467
 
              if ((x_offset % grid_cfg.vspace >= grid_cfg.ispace
 
465
              if ((x_offset % grid_cfg.hspace >= grid_cfg.ispace
468
466
                   &&
469
 
                   x_offset % grid_cfg.vspace < grid_cfg.ioffset)
 
467
                   x_offset % grid_cfg.hspace < grid_cfg.ioffset)
470
468
                  ||
471
 
                  (grid_cfg.vspace -
472
 
                   (x_offset % grid_cfg.vspace) >= grid_cfg.ispace
 
469
                  (grid_cfg.hspace -
 
470
                   (x_offset % grid_cfg.hspace) >= grid_cfg.ispace
473
471
                   &&
474
 
                   grid_cfg.vspace -
475
 
                   (x_offset % grid_cfg.vspace) < grid_cfg.ioffset))
 
472
                   grid_cfg.hspace -
 
473
                   (x_offset % grid_cfg.hspace) < grid_cfg.ioffset))
476
474
                {
477
475
                  pix_composite (&dest[(x-sx1) * bytes],
478
476
                                 icolor, bytes, blend, alpha);
488
486
        }
489
487
      else
490
488
        {
491
 
          gimp_pixel_rgn_set_row (&destPR, dest, sx1, y, (sx2 - sx1) );
492
 
          gimp_progress_update ((double) y / (double) (sy2 - sy1));
 
489
          gimp_pixel_rgn_set_row (&destPR, dest, sx1, y, (sx2 - sx1));
 
490
 
 
491
          if (y % 16 == 0)
 
492
            gimp_progress_update ((gdouble) y / (gdouble) (sy2 - sy1));
493
493
        }
494
494
    }
495
495
 
630
630
 
631
631
  g_return_val_if_fail (main_dialog == NULL, FALSE);
632
632
 
633
 
  gimp_ui_init ("grid", TRUE);
 
633
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
634
634
 
635
 
  main_dialog = dlg = gimp_dialog_new (_("Grid"), "grid",
 
635
  main_dialog = dlg = gimp_dialog_new (_("Grid"), PLUG_IN_BINARY,
636
636
                                       NULL, 0,
637
 
                                       gimp_standard_help_func, "plug-in-grid",
 
637
                                       gimp_standard_help_func, PLUG_IN_PROC,
638
638
 
639
639
                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
640
640
                                       GTK_STOCK_OK,     GTK_RESPONSE_OK,
641
641
 
642
642
                                       NULL);
643
643
 
 
644
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
 
645
                                           GTK_RESPONSE_OK,
 
646
                                           GTK_RESPONSE_CANCEL,
 
647
                                           -1);
 
648
 
 
649
  gimp_window_set_transient (GTK_WINDOW (dlg));
 
650
 
644
651
  /*  Get the image resolution and unit  */
645
652
  gimp_image_get_resolution (image_ID, &xres, &yres);
646
653
  unit = gimp_image_get_unit (image_ID);
731
738
  /* connect to the 'value_changed' signal because we have to take care
732
739
   * of keeping the entries in sync when the chainbutton is active
733
740
   */
734
 
  g_signal_connect (width, "value_changed",
 
741
  g_signal_connect (width, "value-changed",
735
742
                    G_CALLBACK (entry_callback),
736
743
                    chain_button);
737
 
  g_signal_connect_swapped (width, "value_changed",
 
744
  g_signal_connect_swapped (width, "value-changed",
738
745
                            G_CALLBACK (gimp_preview_invalidate),
739
746
                            preview);
740
747
 
795
802
   * we have to take care of keeping the entries in sync when the
796
803
   * chainbutton is active
797
804
   */
798
 
  g_signal_connect (space, "value_changed",
 
805
  g_signal_connect (space, "value-changed",
799
806
                    G_CALLBACK (entry_callback),
800
807
                    chain_button);
801
808
  g_signal_connect (space, "unit_changed",
802
809
                    G_CALLBACK (entry_callback),
803
810
                    chain_button);
804
 
  g_signal_connect_swapped (space, "value_changed",
 
811
  g_signal_connect_swapped (space, "value-changed",
805
812
                            G_CALLBACK (gimp_preview_invalidate),
806
813
                            preview);
807
814
 
868
875
   * we have to take care of keeping the entries in sync when the
869
876
   * chainbutton is active
870
877
   */
871
 
  g_signal_connect (offset, "value_changed",
 
878
  g_signal_connect (offset, "value-changed",
872
879
                    G_CALLBACK (entry_callback),
873
880
                    chain_button);
874
881
  g_signal_connect (offset, "unit_changed",
875
882
                    G_CALLBACK (entry_callback),
876
883
                    chain_button);
877
 
  g_signal_connect_swapped (offset, "value_changed",
 
884
  g_signal_connect_swapped (offset, "value-changed",
878
885
                            G_CALLBACK (gimp_preview_invalidate),
879
886
                            preview);
880
887
 
894
901
  gtk_table_attach_defaults (GTK_TABLE (table), hcolor_button, 0, 1, 1, 2);
895
902
  gtk_widget_show (hcolor_button);
896
903
 
897
 
  g_signal_connect (hcolor_button, "color_changed",
 
904
  g_signal_connect (hcolor_button, "color-changed",
898
905
                    G_CALLBACK (gimp_color_button_get_color),
899
906
                    &grid_cfg.hcolor);
900
 
  g_signal_connect (hcolor_button, "color_changed",
 
907
  g_signal_connect (hcolor_button, "color-changed",
901
908
                    G_CALLBACK (color_callback),
902
909
                    chain_button);
903
 
  g_signal_connect_swapped (hcolor_button, "color_changed",
 
910
  g_signal_connect_swapped (hcolor_button, "color-changed",
904
911
                            G_CALLBACK (gimp_preview_invalidate),
905
912
                            preview);
906
913
 
912
919
  gtk_table_attach_defaults (GTK_TABLE (table), vcolor_button, 1, 2, 1, 2);
913
920
  gtk_widget_show (vcolor_button);
914
921
 
915
 
  g_signal_connect (vcolor_button, "color_changed",
 
922
  g_signal_connect (vcolor_button, "color-changed",
916
923
                    G_CALLBACK (gimp_color_button_get_color),
917
924
                    &grid_cfg.vcolor);
918
 
  g_signal_connect (vcolor_button, "color_changed",
 
925
  g_signal_connect (vcolor_button, "color-changed",
919
926
                    G_CALLBACK (color_callback),
920
927
                    chain_button);
921
 
  g_signal_connect_swapped (vcolor_button, "color_changed",
 
928
  g_signal_connect_swapped (vcolor_button, "color-changed",
922
929
                            G_CALLBACK (gimp_preview_invalidate),
923
930
                            preview);
924
931
 
930
937
  gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2);
931
938
  gtk_widget_show (button);
932
939
 
933
 
  g_signal_connect (button, "color_changed",
 
940
  g_signal_connect (button, "color-changed",
934
941
                    G_CALLBACK (gimp_color_button_get_color),
935
942
                    &grid_cfg.icolor);
936
 
  g_signal_connect_swapped (button, "color_changed",
 
943
  g_signal_connect_swapped (button, "color-changed",
937
944
                            G_CALLBACK (gimp_preview_invalidate),
938
945
                            preview);
939
946