1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
4
* GIMP Plug-in for Windows Icon files.
5
* Copyright (C) 2002 Christian Kreibich <christian@whoop.org>.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
#include <libgimp/gimp.h>
28
#include <libgimp/gimpui.h>
36
#include "libgimp/stdplugins-intl.h"
39
static void query (void);
40
static void run (const gchar *name,
42
const GimpParam *param,
44
GimpParam **return_vals);
47
GimpPlugInInfo PLUG_IN_INFO =
51
query, /* query_proc */
62
static GimpParamDef load_args[] =
64
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
65
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
66
{ GIMP_PDB_STRING, "raw_filename", "The name entered" }
68
static GimpParamDef load_return_vals[] =
70
{ GIMP_PDB_IMAGE, "image", "Output image" },
73
static GimpParamDef save_args[] =
75
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
76
{ GIMP_PDB_IMAGE, "image", "Input image" },
77
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
78
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
79
{ GIMP_PDB_STRING, "raw_filename", "The name entered" },
82
gimp_install_procedure ("file_ico_load",
83
"Loads files of Windows ICO file format",
84
"Loads files of Windows ICO file format",
85
"Christian Kreibich <christian@whoop.org>",
86
"Christian Kreibich <christian@whoop.org>",
88
N_("Microsoft Windows icon"),
91
G_N_ELEMENTS (load_args),
92
G_N_ELEMENTS (load_return_vals),
93
load_args, load_return_vals);
95
gimp_register_file_handler_mime ("file_ico_load", "image/x-ico");
96
gimp_register_magic_load_handler ("file_ico_load",
99
"0,string,\\000\\001\\000\\000,0,string,\\000\\002\\000\\000");
101
gimp_install_procedure ("file_ico_save",
102
"Saves files in Windows ICO file format",
103
"Saves files in Windows ICO file format",
104
"Christian Kreibich <christian@whoop.org>",
105
"Christian Kreibich <christian@whoop.org>",
107
N_("Microsoft Windows icon"),
110
G_N_ELEMENTS (save_args), 0,
113
gimp_register_file_handler_mime ("file_ico_save", "image/x-ico");
114
gimp_register_save_handler ("file_ico_save", "ico", "");
118
run (const gchar *name,
120
const GimpParam *param,
122
GimpParam **return_vals)
124
static GimpParam values[2];
127
GimpRunMode run_mode;
128
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
129
GimpExportReturn export = GIMP_EXPORT_CANCEL;
133
run_mode = param[0].data.d_int32;
136
*return_vals = values;
137
values[0].type = GIMP_PDB_STATUS;
138
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
140
if (strcmp (name, "file_ico_load") == 0)
144
case GIMP_RUN_INTERACTIVE:
147
case GIMP_RUN_NONINTERACTIVE:
149
status = GIMP_PDB_CALLING_ERROR;
156
if (status == GIMP_PDB_SUCCESS)
158
image_ID = LoadICO (param[1].data.d_string);
163
values[1].type = GIMP_PDB_IMAGE;
164
values[1].data.d_image = image_ID;
168
status = GIMP_PDB_EXECUTION_ERROR;
172
else if (strcmp (name, "file_ico_save") == 0)
176
image_ID = param[1].data.d_int32;
177
drawable_ID = param[2].data.d_int32;
178
file_name = param[3].data.d_string;
182
case GIMP_RUN_INTERACTIVE:
185
case GIMP_RUN_NONINTERACTIVE:
186
/* Make sure all the arguments are there! */
188
status = GIMP_PDB_CALLING_ERROR;
191
case GIMP_RUN_WITH_LAST_VALS:
198
if (status == GIMP_PDB_SUCCESS)
200
status = SaveICO (file_name, image_ID);
203
if (export == GIMP_EXPORT_EXPORT)
204
gimp_image_delete (image_ID);
208
status = GIMP_PDB_CALLING_ERROR;
211
values[0].type = GIMP_PDB_STATUS;
212
values[0].data.d_status = status;
217
ico_alloc_map (gint width,
228
if ((width % 32) == 0)
229
len = (width * height / 8);
231
len = 4 * ((width/32 + 1) * height);
235
if ((width % 8) == 0)
236
len = (width * height / 2);
238
len = 4 * ((width/8 + 1) * height);
242
if ((width % 4) == 0)
243
len = width * height;
245
len = 4 * ((width/4 + 1) * height);
249
len = width * height * (bpp/8);
253
map = g_new0 (guint8, len);
260
ico_cleanup (MsIcon *ico)
271
g_free (ico->icon_dir);
275
for (i = 0; i < ico->icon_count; i++)
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);
281
g_free (ico->icon_data);