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

« back to all changes in this revision

Viewing changes to plug-ins/winicon/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070502163303-6wchheivjxgjtlna
Tags: upstream-2.3.16
ImportĀ upstreamĀ versionĀ 2.3.16

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-1997 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * GIMP Plug-in for Windows Icon files.
22
22
#include "config.h"
23
23
 
24
24
#include <string.h>
25
 
#include <stdio.h>
26
25
 
27
26
#include <libgimp/gimp.h>
28
27
#include <libgimp/gimpui.h>
35
34
 
36
35
#include "libgimp/stdplugins-intl.h"
37
36
 
 
37
#define LOAD_PROC        "file-ico-load"
 
38
#define LOAD_THUMB_PROC  "file-ico-load-thumb"
 
39
#define SAVE_PROC        "file-ico-save"
 
40
 
38
41
 
39
42
static void   query (void);
40
43
static void   run   (const gchar      *name,
44
47
                     GimpParam       **return_vals);
45
48
 
46
49
 
47
 
GimpPlugInInfo PLUG_IN_INFO =
 
50
const GimpPlugInInfo PLUG_IN_INFO =
48
51
{
49
52
  NULL,  /* init_proc  */
50
53
  NULL,  /* quit_proc  */
59
62
static void
60
63
query (void)
61
64
{
62
 
  static GimpParamDef load_args[] =
 
65
  static const GimpParamDef load_args[] =
63
66
  {
64
 
    { GIMP_PDB_INT32,    "run_mode",     "Interactive, non-interactive" },
 
67
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
65
68
    { GIMP_PDB_STRING,   "filename",     "The name of the file to load" },
66
 
    { GIMP_PDB_STRING,   "raw_filename", "The name entered"             }
 
69
    { GIMP_PDB_STRING,   "raw-filename", "The name entered"             }
67
70
  };
68
 
  static GimpParamDef load_return_vals[] =
 
71
  static const GimpParamDef load_return_vals[] =
69
72
  {
70
73
    { GIMP_PDB_IMAGE, "image", "Output image" },
71
74
  };
72
75
 
73
 
  static GimpParamDef save_args[] =
74
 
  {
75
 
    { GIMP_PDB_INT32,    "run_mode",     "Interactive, non-interactive" },
 
76
  static const GimpParamDef thumb_args[] =
 
77
  {
 
78
    { GIMP_PDB_STRING, "filename",     "The name of the file to load"  },
 
79
    { GIMP_PDB_INT32,  "thumb-size",   "Preferred thumbnail size"      }
 
80
  };
 
81
  static const GimpParamDef thumb_return_vals[] =
 
82
  {
 
83
    { GIMP_PDB_IMAGE,  "image",        "Thumbnail image"               },
 
84
    { GIMP_PDB_INT32,  "image-width",  "Width of full-sized image"     },
 
85
    { GIMP_PDB_INT32,  "image-height", "Height of full-sized image"    }
 
86
  };
 
87
 
 
88
  static const GimpParamDef save_args[] =
 
89
  {
 
90
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
76
91
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
77
92
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
78
93
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
79
 
    { GIMP_PDB_STRING,   "raw_filename", "The name entered" },
 
94
    { GIMP_PDB_STRING,   "raw-filename", "The name entered" },
80
95
  };
81
96
 
82
 
  gimp_install_procedure ("file_ico_load",
 
97
  gimp_install_procedure (LOAD_PROC,
83
98
                          "Loads files of Windows ICO file format",
84
99
                          "Loads files of Windows ICO file format",
85
100
                          "Christian Kreibich <christian@whoop.org>",
92
107
                          G_N_ELEMENTS (load_return_vals),
93
108
                          load_args, load_return_vals);
94
109
 
95
 
  gimp_register_file_handler_mime ("file_ico_load", "image/x-ico");
96
 
  gimp_register_magic_load_handler ("file_ico_load",
 
110
  gimp_register_file_handler_mime (LOAD_PROC, "image/x-ico");
 
111
  gimp_register_magic_load_handler (LOAD_PROC,
97
112
                                    "ico",
98
113
                                    "",
99
114
                                    "0,string,\\000\\001\\000\\000,0,string,\\000\\002\\000\\000");
100
115
 
101
 
  gimp_install_procedure ("file_ico_save",
 
116
  gimp_install_procedure (LOAD_THUMB_PROC,
 
117
                          "Loads a preview from an Windows ICO file",
 
118
                          "",
 
119
                          "Dom Lachowicz, Sven Neumann",
 
120
                          "Sven Neumann <sven@gimp.org>",
 
121
                          "2005",
 
122
                          NULL,
 
123
                          NULL,
 
124
                          GIMP_PLUGIN,
 
125
                          G_N_ELEMENTS (thumb_args),
 
126
                          G_N_ELEMENTS (thumb_return_vals),
 
127
                          thumb_args, thumb_return_vals);
 
128
 
 
129
  gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
 
130
 
 
131
  gimp_install_procedure (SAVE_PROC,
102
132
                          "Saves files in Windows ICO file format",
103
133
                          "Saves files in Windows ICO file format",
104
134
                          "Christian Kreibich <christian@whoop.org>",
110
140
                          G_N_ELEMENTS (save_args), 0,
111
141
                          save_args, NULL);
112
142
 
113
 
  gimp_register_file_handler_mime ("file_ico_save", "image/x-ico");
114
 
  gimp_register_save_handler ("file_ico_save", "ico", "");
 
143
  gimp_register_file_handler_mime (SAVE_PROC, "image/x-ico");
 
144
  gimp_register_save_handler (SAVE_PROC, "ico", "");
115
145
}
116
146
 
117
147
static void
121
151
     gint             *nreturn_vals,
122
152
     GimpParam       **return_vals)
123
153
{
124
 
  static GimpParam   values[2];
 
154
  static GimpParam   values[4];
125
155
  gint32             image_ID;
126
156
  gint32             drawable_ID;
127
157
  GimpRunMode        run_mode;
137
167
  values[0].type          = GIMP_PDB_STATUS;
138
168
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
139
169
 
140
 
  if (strcmp (name, "file_ico_load") == 0)
 
170
  if (strcmp (name, LOAD_PROC) == 0)
141
171
    {
142
172
      switch (run_mode)
143
173
        {
155
185
 
156
186
      if (status == GIMP_PDB_SUCCESS)
157
187
        {
158
 
          image_ID = LoadICO (param[1].data.d_string);
 
188
          image_ID = ico_load_image (param[1].data.d_string);
159
189
 
160
190
          if (image_ID != -1)
161
191
            {
169
199
            }
170
200
        }
171
201
    }
172
 
  else if (strcmp (name, "file_ico_save") == 0)
 
202
  else if (strcmp (name, LOAD_THUMB_PROC) == 0)
 
203
    {
 
204
      if (nparams < 2)
 
205
        {
 
206
          status = GIMP_PDB_CALLING_ERROR;
 
207
        }
 
208
      else
 
209
        {
 
210
          const gchar *filename = param[0].data.d_string;
 
211
          gint         width    = param[1].data.d_int32;
 
212
          gint         height   = param[1].data.d_int32;
 
213
          gint32       image_ID;
 
214
 
 
215
          image_ID = ico_load_thumbnail_image (filename, &width, &height);
 
216
 
 
217
          if (image_ID != -1)
 
218
            {
 
219
              *nreturn_vals = 4;
 
220
 
 
221
              values[1].type         = GIMP_PDB_IMAGE;
 
222
              values[1].data.d_image = image_ID;
 
223
              values[2].type         = GIMP_PDB_INT32;
 
224
              values[2].data.d_int32 = width;
 
225
              values[3].type         = GIMP_PDB_INT32;
 
226
              values[3].data.d_int32 = height;
 
227
            }
 
228
          else
 
229
            {
 
230
              status = GIMP_PDB_EXECUTION_ERROR;
 
231
            }
 
232
        }
 
233
    }
 
234
  else if (strcmp (name, SAVE_PROC) == 0)
173
235
    {
174
236
      gchar *file_name;
175
237
 
197
259
 
198
260
      if (status == GIMP_PDB_SUCCESS)
199
261
        {
200
 
          status = SaveICO (file_name, image_ID);
 
262
          status = ico_save_image (file_name, image_ID, run_mode);
201
263
        }
202
264
 
203
265
      if (export == GIMP_EXPORT_EXPORT)
213
275
}
214
276
 
215
277
 
216
 
guint8 *
217
 
ico_alloc_map (gint  width,
218
 
               gint  height,
219
 
               gint  bpp,
220
 
               gint *length)
 
278
gint
 
279
ico_rowstride (gint width,
 
280
               gint bpp)
221
281
{
222
 
  gint    len = 0;
223
 
  guint8 *map = NULL;
224
 
 
225
282
  switch (bpp)
226
283
    {
227
284
    case 1:
228
285
      if ((width % 32) == 0)
229
 
        len = (width * height / 8);
 
286
        return width / 8;
230
287
      else
231
 
        len = 4 * ((width/32 + 1) * height);
 
288
        return 4 * (width/32 + 1);
232
289
      break;
233
290
 
234
291
    case 4:
235
292
      if ((width % 8) == 0)
236
 
        len = (width * height / 2);
 
293
        return width / 2;
237
294
      else
238
 
        len = 4 * ((width/8 + 1) * height);
 
295
        return 4 * (width/8 + 1);
239
296
      break;
240
297
 
241
298
    case 8:
242
299
      if ((width % 4) == 0)
243
 
        len = width * height;
 
300
        return width;
244
301
      else
245
 
        len = 4 * ((width/4 + 1) * height);
 
302
        return 4 * (width/4 + 1);
246
303
      break;
247
304
 
 
305
    case 24:
 
306
      if (((width*3) % 4) == 0)
 
307
        return width * 3;
 
308
      else
 
309
        return 4 * (width*3/4+1);
 
310
 
 
311
    case 32:
 
312
      return width * 4;
 
313
 
248
314
    default:
249
 
      len = width * height * (bpp/8);
 
315
      g_warning ("invalid bitrate: %d\n", bpp);
 
316
      g_assert_not_reached ();
 
317
      return width * (bpp/8);
250
318
    }
 
319
}
 
320
 
 
321
guint8 *
 
322
ico_alloc_map (gint  width,
 
323
               gint  height,
 
324
               gint  bpp,
 
325
               gint *length)
 
326
{
 
327
  gint    len = 0;
 
328
  guint8 *map = NULL;
 
329
 
 
330
  len = ico_rowstride (width, bpp) * height;
251
331
 
252
332
  *length = len;
253
333
  map = g_new0 (guint8, len);
255
335
  return map;
256
336
}
257
337
 
258
 
 
259
 
void
260
 
ico_cleanup (MsIcon *ico)
261
 
{
262
 
  gint i;
263
 
 
264
 
  if (!ico)
265
 
    return;
266
 
 
267
 
  if (ico->fp)
268
 
    fclose (ico->fp);
269
 
 
270
 
  if (ico->icon_dir)
271
 
    g_free (ico->icon_dir);
272
 
 
273
 
  if (ico->icon_data)
274
 
    {
275
 
      for (i = 0; i < ico->icon_count; i++)
276
 
        {
277
 
          g_free (ico->icon_data[i].palette);
278
 
          g_free (ico->icon_data[i].xor_map);
279
 
          g_free (ico->icon_data[i].and_map);
280
 
        }
281
 
      g_free (ico->icon_data);
282
 
    }
283
 
}