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

« back to all changes in this revision

Viewing changes to plug-ins/common/gih.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:
43
43
#include "config.h"
44
44
 
45
45
#include <errno.h>
46
 
#include <stdio.h>
 
46
#include <stdlib.h>
47
47
#include <string.h>
48
 
#include <stdlib.h>
49
48
 
50
49
#include <sys/types.h>
51
50
#include <sys/stat.h>
52
51
#include <fcntl.h>
 
52
 
53
53
#ifdef HAVE_UNISTD_H
54
54
#include <unistd.h>
55
55
#endif
56
56
 
 
57
#include <glib/gstdio.h>
 
58
 
57
59
#include <glib.h>
58
60
 
59
61
#ifdef G_OS_WIN32
64
66
#define _O_BINARY 0
65
67
#endif
66
68
 
67
 
#include <gtk/gtk.h>
68
 
 
69
69
#include <libgimp/gimp.h>
70
70
#include <libgimp/gimpui.h>
71
71
#include <libgimpbase/gimpparasiteio.h>
76
76
#include "libgimp/stdplugins-intl.h"
77
77
 
78
78
 
 
79
#define LOAD_PROC          "file-gih-load"
 
80
#define SAVE_PROC          "file-gih-save"
 
81
#define PLUG_IN_BINARY     "gih"
79
82
#define DUMMY_PATTERN_NAME "x"
80
 
 
81
 
#define MAXDESCLEN 256
 
83
#define MAXDESCLEN         256
82
84
 
83
85
/* Parameters applicable each time we save a gih, saved in the
84
86
 * main gimp application between invocations of this plug-in.
151
153
                                      gint32        drawable_ID);
152
154
 
153
155
 
154
 
GimpPlugInInfo PLUG_IN_INFO =
 
156
const GimpPlugInInfo PLUG_IN_INFO =
155
157
{
156
158
  NULL,  /* init_proc  */
157
159
  NULL,  /* quit_proc  */
164
166
static void
165
167
query (void)
166
168
{
167
 
  static GimpParamDef gih_save_args[] =
 
169
  static const GimpParamDef gih_save_args[] =
168
170
  {
169
 
    { GIMP_PDB_INT32,    "run_mode",     "Interactive, non-interactive" },
170
 
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
171
 
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
172
 
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the brush pipe in" },
173
 
    { GIMP_PDB_STRING,   "raw_filename", "The name of the file to save the brush pipe in" },
174
 
    { GIMP_PDB_INT32,    "spacing",      "Spacing of the brush" },
175
 
    { GIMP_PDB_STRING,   "description",  "Short description of the brush pipe" },
176
 
    { GIMP_PDB_INT32,    "cell_width",   "Width of the brush cells" },
177
 
    { GIMP_PDB_INT32,    "cell_height",  "Width of the brush cells" },
178
 
    { GIMP_PDB_INT8,     "display_cols",   "Display column number" },
179
 
    { GIMP_PDB_INT8,     "display_rows",   "Display row number" },
180
 
    { GIMP_PDB_INT32,     "dimension",   "Dimension of the brush pipe" },
 
171
    { GIMP_PDB_INT32,       "run-mode",     "Interactive, non-interactive" },
 
172
    { GIMP_PDB_IMAGE,       "image",        "Input image" },
 
173
    { GIMP_PDB_DRAWABLE,    "drawable",     "Drawable to save" },
 
174
    { GIMP_PDB_STRING,      "filename",     "The name of the file to save the brush pipe in" },
 
175
    { GIMP_PDB_STRING,      "raw-filename", "The name of the file to save the brush pipe in" },
 
176
    { GIMP_PDB_INT32,       "spacing",      "Spacing of the brush" },
 
177
    { GIMP_PDB_STRING,      "description",  "Short description of the brush pipe" },
 
178
    { GIMP_PDB_INT32,       "cell-width",   "Width of the brush cells" },
 
179
    { GIMP_PDB_INT32,       "cell-height",  "Width of the brush cells" },
 
180
    { GIMP_PDB_INT8,        "display-cols", "Display column number" },
 
181
    { GIMP_PDB_INT8,        "display-rows", "Display row number" },
 
182
    { GIMP_PDB_INT32,       "dimension",    "Dimension of the brush pipe" },
181
183
    /* The number of rank and sel args depend on the dimension */
182
 
    { GIMP_PDB_INT8ARRAY,"rank",                 "Ranks of the dimensions" },
183
 
    { GIMP_PDB_INT32,     "dimension",   "Dimension (again)" },
184
 
    { GIMP_PDB_STRINGARRAY, "sel",       "Selection modes" }
185
 
  };
186
 
 
187
 
  static GimpParamDef gih_load_args[] =
188
 
  {
189
 
    { GIMP_PDB_INT32,  "run_mode",       "Interactive, non-interactive" },
190
 
    { GIMP_PDB_STRING, "filename",       "The name of the file to load" },
191
 
    { GIMP_PDB_STRING, "raw_filename",   "The name of the file to load" }
192
 
  };
193
 
  static GimpParamDef gih_load_return_vals[] =
194
 
  {
195
 
    { GIMP_PDB_IMAGE,  "image",          "Output image" }
196
 
  };
197
 
 
198
 
 
199
 
  gimp_install_procedure ("file_gih_load",
 
184
    { GIMP_PDB_INT8ARRAY,   "rank",         "Ranks of the dimensions" },
 
185
    { GIMP_PDB_INT32,       "dimension",    "Dimension (again)" },
 
186
    { GIMP_PDB_STRINGARRAY, "sel",          "Selection modes" }
 
187
  };
 
188
 
 
189
  static const GimpParamDef gih_load_args[] =
 
190
  {
 
191
    { GIMP_PDB_INT32,  "run-mode",     "Interactive, non-interactive" },
 
192
    { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
 
193
    { GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
 
194
  };
 
195
  static const GimpParamDef gih_load_return_vals[] =
 
196
  {
 
197
    { GIMP_PDB_IMAGE,  "image",        "Output image" }
 
198
  };
 
199
 
 
200
 
 
201
  gimp_install_procedure (LOAD_PROC,
200
202
                          "loads images in GIMP brush pipe format",
201
203
                          "This plug-in loads a GIMP brush pipe as an image.",
202
204
                          "Jens Lautenbacher, Sven Neumann",
209
211
                          G_N_ELEMENTS (gih_load_return_vals),
210
212
                          gih_load_args, gih_load_return_vals);
211
213
 
212
 
  gimp_plugin_icon_register ("file_gih_load",
213
 
                             GIMP_ICON_TYPE_STOCK_ID, GIMP_STOCK_BRUSH);
214
 
  gimp_register_file_handler_mime ("file_gih_load", "image/x-gimp-gih");
215
 
  gimp_register_magic_load_handler ("file_gih_load",
 
214
  gimp_plugin_icon_register (LOAD_PROC, GIMP_ICON_TYPE_STOCK_ID,
 
215
                             (const guint8 *) GIMP_STOCK_BRUSH);
 
216
  gimp_register_file_handler_mime (LOAD_PROC, "image/x-gimp-gih");
 
217
  gimp_register_magic_load_handler (LOAD_PROC,
216
218
                                    "gih",
217
219
                                    "",
218
220
                                    "");
219
221
 
220
 
  gimp_install_procedure ("file_gih_save",
 
222
  gimp_install_procedure (SAVE_PROC,
221
223
                          "saves images in GIMP brush pipe format",
222
224
                          "This plug-in saves an image in the GIMP brush pipe format. The image must have an alpha chnannel and can be multi-layered, and additionally the layers can be divided into a rectangular array of brushes.",
223
225
                          "Tor Lillqvist",
229
231
                          G_N_ELEMENTS (gih_save_args), 0,
230
232
                          gih_save_args, NULL);
231
233
 
232
 
  gimp_plugin_icon_register ("file_gih_save",
233
 
                             GIMP_ICON_TYPE_STOCK_ID, GIMP_STOCK_BRUSH);
 
234
  gimp_plugin_icon_register (SAVE_PROC, GIMP_ICON_TYPE_STOCK_ID,
 
235
                             (const guint8 *) GIMP_STOCK_BRUSH);
234
236
  gimp_register_file_handler_mime ("file_gih_save", "image/x-gimp-gih");
235
 
  gimp_register_save_handler ("file_gih_save",
 
237
  gimp_register_save_handler (SAVE_PROC,
236
238
                              "gih",
237
239
                              "");
238
240
}
267
269
 
268
270
  INIT_I18N();
269
271
 
270
 
  if (strcmp (name, "file_gih_load") == 0)
 
272
  if (strcmp (name, LOAD_PROC) == 0)
271
273
    {
272
274
      image_ID = gih_load_image (param[1].data.d_string);
273
275
 
282
284
          status = GIMP_PDB_EXECUTION_ERROR;
283
285
        }
284
286
    }
285
 
  else if (strcmp (name, "file_gih_save") == 0)
 
287
  else if (strcmp (name, SAVE_PROC) == 0)
286
288
    {
287
289
      image_ID = orig_image_ID = param[1].data.d_int32;
288
290
      drawable_ID = param[2].data.d_int32;
292
294
        {
293
295
        case GIMP_RUN_INTERACTIVE:
294
296
        case GIMP_RUN_WITH_LAST_VALS:
295
 
          gimp_ui_init ("gih", FALSE);
 
297
          gimp_ui_init (PLUG_IN_BINARY, FALSE);
296
298
          export = gimp_export_image (&image_ID, &drawable_ID, "GIH",
297
299
                                      GIMP_EXPORT_CAN_HANDLE_RGB    |
298
300
                                      GIMP_EXPORT_CAN_HANDLE_GRAY   |
327
329
        {
328
330
        case GIMP_RUN_INTERACTIVE:
329
331
          /*  Possibly retrieve data  */
330
 
          gimp_get_data ("file_gih_save", &info);
 
332
          gimp_get_data (SAVE_PROC, &info);
331
333
 
332
334
          gimp_pixpipe_params_init (&gihparams);
333
335
 
393
395
          break;
394
396
 
395
397
        case GIMP_RUN_WITH_LAST_VALS:
396
 
          gimp_get_data ("file_gih_save", &info);
 
398
          gimp_get_data (SAVE_PROC, &info);
397
399
          pipe_parasite =
398
400
            gimp_image_parasite_find (orig_image_ID,
399
401
                                      "gimp-brush-pipe-parameters");
409
411
          if (gih_save_image (param[3].data.d_string,
410
412
                              image_ID, orig_image_ID, drawable_ID))
411
413
            {
412
 
              gimp_set_data ("file_gih_save", &info, sizeof (info));
 
414
              gimp_set_data (SAVE_PROC, &info, sizeof (info));
413
415
            }
414
416
          else
415
417
            {
630
632
static gint32
631
633
gih_load_image (const gchar *filename)
632
634
{
633
 
  gchar   *temp;
634
635
  gint     fd;
635
636
  gint     i;
636
637
  gint32   image_ID;
641
642
  gchar   *paramstring;
642
643
  GimpParasite *pipe_parasite;
643
644
 
644
 
  fd = open (filename, O_RDONLY | _O_BINARY);
 
645
  fd = g_open (filename, O_RDONLY | _O_BINARY, 0);
645
646
 
646
647
  if (fd == -1)
647
648
    {
650
651
      return -1;
651
652
    }
652
653
 
653
 
  temp = g_strdup_printf (_("Opening '%s'..."),
654
 
                          gimp_filename_to_utf8 (filename));
655
 
  gimp_progress_init (temp);
656
 
  g_free (temp);
 
654
  gimp_progress_init_printf (_("Opening '%s'"),
 
655
                             gimp_filename_to_utf8 (filename));
657
656
 
658
657
  /* The file format starts with a painfully simple text header */
659
658
 
847
846
static gboolean
848
847
gih_save_dialog (gint32 image_ID)
849
848
{
850
 
  GtkWidget *dlg;
 
849
  GtkWidget *dialog;
851
850
  GtkWidget *table;
852
851
  GtkWidget *dimtable;
853
852
  GtkWidget *label;
864
863
  gint32     nlayers;
865
864
  gboolean   run;
866
865
 
867
 
  dlg = gimp_dialog_new (_("Save as Brush Pipe"), "gih",
868
 
                         NULL, 0,
869
 
                         gimp_standard_help_func, "file-gih-save",
870
 
 
871
 
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
872
 
                         GTK_STOCK_OK,     GTK_RESPONSE_OK,
873
 
 
874
 
                         NULL);
 
866
  dialog = gimp_dialog_new (_("Save as Brush Pipe"), PLUG_IN_BINARY,
 
867
                            NULL, 0,
 
868
                            gimp_standard_help_func, SAVE_PROC,
 
869
 
 
870
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
871
                            GTK_STOCK_SAVE,   GTK_RESPONSE_OK,
 
872
 
 
873
                            NULL);
 
874
 
 
875
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
876
                                           GTK_RESPONSE_OK,
 
877
                                           GTK_RESPONSE_CANCEL,
 
878
                                           -1);
 
879
 
 
880
  gimp_window_set_transient (GTK_WINDOW (dialog));
875
881
 
876
882
  /* The main table */
877
883
  table = gtk_table_new (8, 2, FALSE);
878
884
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
879
885
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
880
886
  gtk_container_set_border_width (GTK_CONTAINER (table), 12);
881
 
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), table, TRUE, TRUE, 0);
 
887
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table, TRUE, TRUE, 0);
882
888
  gtk_widget_show (table);
883
889
 
884
890
  /*
890
896
                             _("Spacing (percent):"), 0.0, 0.5,
891
897
                             spinbutton, 1, TRUE);
892
898
 
893
 
  g_signal_connect (adjustment, "value_changed",
 
899
  g_signal_connect (adjustment, "value-changed",
894
900
                    G_CALLBACK (gimp_int_adjustment_update),
895
901
                    &info.spacing);
896
902
 
928
934
  cellw_adjust.guides      = NULL;
929
935
  cellw_adjust.value       = &gihparams.cellwidth;
930
936
 
931
 
  g_signal_connect (adjustment, "value_changed",
 
937
  g_signal_connect (adjustment, "value-changed",
932
938
                    G_CALLBACK (size_adjustment_callback),
933
939
                    &cellw_adjust);
934
940
 
950
956
  cellh_adjust.guides      = NULL;
951
957
  cellh_adjust.value       = &gihparams.cellheight;
952
958
 
953
 
  g_signal_connect (adjustment, "value_changed",
 
959
  g_signal_connect (adjustment, "value-changed",
954
960
                    G_CALLBACK (size_adjustment_callback),
955
961
                    &cellh_adjust);
956
962
 
974
980
                             _("Number of cells:"), 0.0, 0.5,
975
981
                             spinbutton, 1, TRUE);
976
982
 
977
 
  g_signal_connect (adjustment, "value_changed",
 
983
  g_signal_connect (adjustment, "value-changed",
978
984
                    G_CALLBACK (gimp_int_adjustment_update),
979
985
                    &gihparams.ncells);
980
986
 
1033
1039
                             _("Dimension:"), 0.0, 0.5,
1034
1040
                             spinbutton, 1, TRUE);
1035
1041
 
1036
 
  g_signal_connect (adjustment, "value_changed",
 
1042
  g_signal_connect (adjustment, "value-changed",
1037
1043
                    G_CALLBACK (dim_callback),
1038
1044
                    &cellw_adjust);
1039
1045
 
1058
1064
      if (i >= gihparams.dim)
1059
1065
        gtk_widget_set_sensitive (spinbutton, FALSE);
1060
1066
 
1061
 
      g_signal_connect (adjustment, "value_changed",
 
1067
      g_signal_connect (adjustment, "value-changed",
1062
1068
                        G_CALLBACK (gimp_int_adjustment_update),
1063
1069
                        &gihparams.rank[i]);
1064
1070
 
1071
1077
          else
1072
1078
            cellw_adjust.rank0 = cellh_adjust.rank0 = NULL;
1073
1079
        }
1074
 
      
1075
1080
 
1076
1081
      cb = gtk_combo_box_new_text ();
1077
1082
 
1087
1092
              gtk_combo_box_set_active (GTK_COMBO_BOX (cb), j);
1088
1093
              break;
1089
1094
            }
1090
 
        
1091
1095
 
1092
1096
      gtk_table_attach (GTK_TABLE (dimtable), cb, 1, 2, i, i + 1,
1093
1097
                        GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1110
1114
                             _("Ranks:"), 0.0, 0.0,
1111
1115
                             dimtable, 1, FALSE);
1112
1116
 
1113
 
  gtk_widget_show (dlg);
 
1117
  gtk_widget_show (dialog);
1114
1118
 
1115
 
  run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
 
1119
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
1116
1120
 
1117
1121
  if (run)
1118
1122
    {
1127
1131
             num_useable_layers * gihparams.rows * gihparams.cols);
1128
1132
    }
1129
1133
 
1130
 
  gtk_widget_destroy (dlg);
 
1134
  gtk_widget_destroy (dialog);
1131
1135
 
1132
1136
  for (i = 0; i < cellw_adjust.nguides; i++)
1133
1137
    gimp_image_delete_guide (image_ID, cellw_adjust.guides[i]);
1233
1237
  GimpPixelRgn  pixel_rgn;
1234
1238
  GimpParasite *pipe_parasite;
1235
1239
  gchar *header;
1236
 
  gchar *msg, *parstring;
 
1240
  gchar *parstring;
1237
1241
  gint32 *layer_ID;
1238
1242
  gint fd;
1239
1243
  gint nlayers, layer, row, col;
1247
1251
  imageh = gimp_image_height (image_ID);
1248
1252
  gimp_tile_cache_size (gimp_tile_height () * imagew * 4);
1249
1253
 
1250
 
  fd = open (filename, O_CREAT | O_TRUNC | O_WRONLY | _O_BINARY, 0644);
 
1254
  fd = g_open (filename, O_CREAT | O_TRUNC | O_WRONLY | _O_BINARY, 0644);
1251
1255
 
1252
1256
  if (fd == -1)
1253
1257
    {
1256
1260
      return FALSE;
1257
1261
    }
1258
1262
 
1259
 
  msg = g_strdup_printf (_("Saving '%s'..."),
1260
 
                         gimp_filename_to_utf8 (filename));
1261
 
  gimp_progress_init (msg);
1262
 
  g_free (msg);
 
1263
  gimp_progress_init_printf (_("Saving '%s'"),
 
1264
                             gimp_filename_to_utf8 (filename));
1263
1265
 
1264
1266
  parstring = gimp_pixpipe_params_build (&gihparams);
1265
1267