plug-ins/winicon/icodialog.[ch] plug-ins/winicon/icoload.[ch]

2004-11-10  Michael Natterer  <mitch@gimp.org>

	* plug-ins/winicon/icodialog.[ch]
	* plug-ins/winicon/icoload.[ch]
	* plug-ins/winicon/icosave.[ch]
	* plug-ins/winicon/main.[ch]: call progress functions
	unconditionally; removed global "interactive" variable; use
	standard strings for open/save progress messages; gui, indentation
	& coding style cleanup; untabified.
This commit is contained in:
Michael Natterer 2004-11-10 14:44:58 +00:00 committed by Michael Natterer
parent 41c1e003d4
commit 1309a075cf
9 changed files with 383 additions and 404 deletions

View file

@ -1,3 +1,13 @@
2004-11-10 Michael Natterer <mitch@gimp.org>
* plug-ins/winicon/icodialog.[ch]
* plug-ins/winicon/icoload.[ch]
* plug-ins/winicon/icosave.[ch]
* plug-ins/winicon/main.[ch]: call progress functions
unconditionally; removed global "interactive" variable; use
standard strings for open/save progress messages; gui, indentation
& coding style cleanup; untabified.
2004-11-10 Michael Schumacher <schumaml@cvs.gnome.org>
* plug-ins/winsnap/winsnap.c: applied a patch from Sven Neumann

View file

@ -23,8 +23,6 @@
#include <stdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
@ -44,7 +42,7 @@ static void combo_bpp_changed (GtkWidget *combo,
static GtkWidget *
ico_preview_new(gint32 layer)
ico_preview_new (gint32 layer)
{
GtkWidget *icon_preview;
@ -59,10 +57,10 @@ static void
ico_fill_preview_with_thumb (GtkWidget *widget,
gint32 drawable_ID)
{
guchar *drawable_data;
gint bpp;
gint width;
gint height;
guchar *drawable_data;
gint bpp;
gint width;
gint height;
width = gimp_drawable_width (drawable_ID);
height = gimp_drawable_height (drawable_ID);
@ -95,7 +93,7 @@ ico_fill_preview_with_thumb (GtkWidget *widget,
/* This function creates and returns an hbox for an icon,
which then gets added to the dialog's main vbox. */
static GtkWidget*
static GtkWidget *
ico_create_icon_hbox (GtkWidget *icon_preview,
gint32 layer,
gint layer_num)
@ -105,7 +103,10 @@ ico_create_icon_hbox (GtkWidget *icon_preview,
GtkWidget *combo;
hbox = gtk_hbox_new (FALSE, 6);
alignment = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_box_pack_start (GTK_BOX (hbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
/* To make life easier for the callbacks, we store the
layer's ID and stacking number with the hbox. */
@ -116,10 +117,8 @@ ico_create_icon_hbox (GtkWidget *icon_preview,
"icon_layer_num", GINT_TO_POINTER (layer_num));
g_object_set_data (G_OBJECT (hbox), "icon_preview", icon_preview);
gtk_widget_show (icon_preview);
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
gtk_widget_show (alignment);
gtk_container_add (GTK_CONTAINER (alignment), icon_preview);
gtk_widget_show (icon_preview);
combo = gimp_int_combo_box_new (_("1 bpp, 1-bit alpha, 2-slot palette"), 1,
_("4 bpp, 1-bit alpha, 16-slot palette"), 4,
@ -133,21 +132,20 @@ ico_create_icon_hbox (GtkWidget *icon_preview,
hbox);
g_object_set_data (G_OBJECT (hbox), "icon_menu", combo);
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
gtk_widget_show (combo);
return hbox;
}
GtkWidget*
GtkWidget *
ico_specs_dialog_new (gint num_layers)
{
GtkWidget *dialog;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *scrolledwindow;
GtkWidget *viewport;
gint *icon_depths, i;
dialog = gimp_dialog_new (_("GIMP Windows Icon Plugin"), "winicon",
@ -171,11 +169,10 @@ ico_specs_dialog_new (gint num_layers)
g_object_set_data (G_OBJECT (dialog), "icon_depths", icon_depths);
vbox = GTK_DIALOG (dialog)->vbox;
frame = gimp_frame_new (_("Icon details"));
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
TRUE, TRUE, 0);
gtk_widget_show (frame);
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
@ -184,13 +181,11 @@ ico_specs_dialog_new (gint num_layers)
gtk_container_add (GTK_CONTAINER (frame), scrolledwindow);
gtk_widget_show (scrolledwindow);
viewport = gtk_viewport_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolledwindow), viewport);
gtk_widget_show (viewport);
vbox = gtk_vbox_new (TRUE, 6);
vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
g_object_set_data (G_OBJECT (dialog), "icons_vbox", vbox);
gtk_container_add (GTK_CONTAINER (viewport), vbox);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolledwindow),
vbox);
gtk_widget_show (vbox);
return dialog;
@ -236,9 +231,10 @@ ico_specs_dialog_add_icon (GtkWidget *dialog,
gchar key[MAXLEN];
vbox = g_object_get_data (G_OBJECT (dialog), "icons_vbox");
preview = ico_preview_new (layer);
hbox = ico_create_icon_hbox (preview, layer, layer_num);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
/* Let's make the hbox accessible through the layer ID */

View file

@ -32,4 +32,4 @@ void ico_specs_dialog_update_icon_preview (GtkWidget *dialog,
gint bpp);
#endif
#endif /* __ICO_DIALOG_H__ */

View file

@ -25,8 +25,6 @@
#include <string.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
/* #define ICO_DBG */
@ -59,8 +57,8 @@ static gint32 ico_to_gimp (MsIcon *ico);
static gint
ico_read_int32 (FILE *fp,
guint32 *data,
gint count)
guint32 *data,
gint count)
{
gint i, total;
@ -69,7 +67,7 @@ ico_read_int32 (FILE *fp,
{
ico_read_int8 (fp, (guint8 *) data, count * 4);
for (i = 0; i < count; i++)
data[i] = GUINT32_FROM_LE (data[i]);
data[i] = GUINT32_FROM_LE (data[i]);
}
return total * 4;
@ -78,8 +76,8 @@ ico_read_int32 (FILE *fp,
static gint
ico_read_int16 (FILE *fp,
guint16 *data,
gint count)
guint16 *data,
gint count)
{
gint i, total;
@ -88,7 +86,7 @@ ico_read_int16 (FILE *fp,
{
ico_read_int8 (fp, (guint8 *) data, count * 2);
for (i = 0; i < count; i++)
data[i] = GUINT16_FROM_LE (data[i]);
data[i] = GUINT16_FROM_LE (data[i]);
}
return total * 2;
@ -97,8 +95,8 @@ ico_read_int16 (FILE *fp,
static gint
ico_read_int8 (FILE *fp,
guint8 *data,
gint count)
guint8 *data,
gint count)
{
gint total;
gint bytes;
@ -221,10 +219,10 @@ ico_read_data (MsIcon *ico,
if (data->bpp <= 8)
{
if (data->used_clrs == 0)
data->used_clrs = (1 << data->bpp);
data->used_clrs = (1 << data->bpp);
D((" allocating a %i-slot palette for %i bpp.\n",
data->used_clrs, data->bpp));
data->used_clrs, data->bpp));
data->palette = g_new0 (guint32, data->used_clrs);
ico->cp += ico_read_int8 (ico->fp,
@ -256,7 +254,7 @@ ico_load (MsIcon *ico)
ico->icon_data = g_new0 (MsIconData, ico->icon_count);
D(("*** %s: Microsoft icon file, containing %i icon(s)\n",
ico->filename, ico->icon_count));
ico->filename, ico->icon_count));
for (i = 0; i < ico->icon_count; i++)
ico_read_entry(ico, &ico->icon_dir[i]);
@ -352,9 +350,9 @@ ico_to_gimp (MsIcon *ico)
for (icon_nr = 0; icon_nr < ico->icon_count; icon_nr++)
{
if (ico->icon_dir[icon_nr].width > max_w)
max_w = ico->icon_dir[icon_nr].width;
max_w = ico->icon_dir[icon_nr].width;
if (ico->icon_dir[icon_nr].height > max_h)
max_h = ico->icon_dir[icon_nr].height;
max_h = ico->icon_dir[icon_nr].height;
}
/* Allocate the Gimp image */
@ -368,8 +366,7 @@ ico_to_gimp (MsIcon *ico)
{
GimpPixelRgn pixel_rgn;
if (interactive_ico)
gimp_progress_update ((gdouble) icon_nr / (gdouble) ico->icon_count);
gimp_progress_update ((gdouble) icon_nr / (gdouble) ico->icon_count);
w = ico->icon_dir[icon_nr].width;
h = ico->icon_dir[icon_nr].height;
@ -385,7 +382,7 @@ ico_to_gimp (MsIcon *ico)
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
if (first_layer == -1)
first_layer = layer;
first_layer = layer;
gimp_image_add_layer (image, layer, icon_nr);
drawable = gimp_drawable_get (layer);
@ -393,97 +390,97 @@ ico_to_gimp (MsIcon *ico)
dest_vec = g_malloc (w * h * 4);
switch (idata->bpp)
{
case 1:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_bit_from_data (xor_map,
{
case 1:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_bit_from_data (xor_map,
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
case 4:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_nibble_from_data (xor_map,
case 4:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_nibble_from_data (xor_map,
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
case 8:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_byte_from_data (xor_map,
case 8:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_byte_from_data (xor_map,
w, y * w + x)];
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
R_VAL_GIMP (dest) = R_VAL (&color);
G_VAL_GIMP (dest) = G_VAL (&color);
B_VAL_GIMP (dest) = B_VAL (&color);
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
break;
default:
{
int bytespp = idata->bpp/8;
default:
{
int bytespp = idata->bpp/8;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 *dest = &(dest_vec[(h-1-y) * w + x]);
B_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp];
G_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 1];
R_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 2];
B_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp];
G_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 1];
R_VAL_GIMP(dest) = xor_map[(y * w + x) * bytespp + 2];
if (idata->bpp < 32)
{
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
else
{
A_VAL_GIMP (dest) = xor_map[(y * w + x) * bytespp + 3];
}
}
}
}
if (idata->bpp < 32)
{
if (ico_get_bit_from_data (and_map, w, y*w + x))
A_VAL_GIMP (dest) = 0;
else
A_VAL_GIMP (dest) = 255;
}
else
{
A_VAL_GIMP (dest) = xor_map[(y * w + x) * bytespp + 3];
}
}
}
}
gimp_pixel_rgn_init (&pixel_rgn, drawable,
0, 0, drawable->width, drawable->height,
0, 0, drawable->width, drawable->height,
TRUE, FALSE);
gimp_pixel_rgn_set_rect (&pixel_rgn, (guchar*) dest_vec,
0, 0, drawable->width, drawable->height);
0, 0, drawable->width, drawable->height);
g_free(dest_vec);
gimp_drawable_flush (drawable);
@ -492,8 +489,7 @@ ico_to_gimp (MsIcon *ico)
gimp_image_set_active_layer (image, first_layer);
if (interactive_ico)
gimp_progress_update (1.0);
gimp_progress_update (1.0);
return image;
}
@ -502,16 +498,14 @@ ico_to_gimp (MsIcon *ico)
gint32
LoadICO (const gchar *filename)
{
gint32 image_ID;
MsIcon ico;
gchar *temp;
gint32 image_ID;
MsIcon ico;
if (interactive_ico)
{
guchar *temp = g_strdup_printf (_("Loading %s:"),
gimp_filename_to_utf8 (filename));
gimp_progress_init (temp);
g_free (temp);
}
temp = g_strdup_printf (_("Opening '%s'..."),
gimp_filename_to_utf8 (filename));
gimp_progress_init (temp);
g_free (temp);
if (! ico_init (filename, &ico))
return -1;

View file

@ -30,4 +30,4 @@ gint ico_get_byte_from_data (guint8 *data, gint line_width, gint byte);
gint32 LoadICO (const gchar *file_name);
#endif
#endif /* __ICO_LOAD_H__ */

View file

@ -25,8 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
@ -57,8 +55,8 @@ static void ico_set_byte_in_data (guint8 *data, gint line_width,
static gint
ico_write_int32 (FILE *fp,
guint32 *data,
gint count)
guint32 *data,
gint count)
{
gint total;
@ -87,8 +85,8 @@ ico_write_int32 (FILE *fp,
static gint
ico_write_int16 (FILE *fp,
guint16 *data,
gint count)
guint16 *data,
gint count)
{
gint total;
@ -117,8 +115,8 @@ ico_write_int16 (FILE *fp,
static gint
ico_write_int8 (FILE *fp,
guint8 *data,
gint count)
guint8 *data,
gint count)
{
gint total;
gint bytes;
@ -163,8 +161,8 @@ ico_show_icon_dialog (gint32 image_ID,
/* Scale the thing to approximately fit its content, but not too large ... */
gtk_window_set_default_size (GTK_WINDOW (dialog),
350,
(num_layers > 5 ? 500 : num_layers * 100));
350,
(num_layers > 5 ? 500 : num_layers * 100));
icon_depths = g_object_get_data (G_OBJECT (dialog), "icon_depths");
@ -181,32 +179,32 @@ ico_show_icon_dialog (gint32 image_ID,
icon_menu = g_object_get_data (G_OBJECT (hbox), "icon_menu");
if (!uses_alpha_values)
{
if (num_colors <= 2)
{
/* Let's suggest monochrome */
icon_depths[i] = 1;
icon_depths[num_layers + i] = 1;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 2);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 0);
}
else if (num_colors <= 16)
{
/* Let's suggest 4bpp */
icon_depths[i] = 4;
icon_depths[num_layers + i] = 4;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 4);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 1);
}
else if (num_colors <= 256)
{
/* Let's suggest 8bpp */
icon_depths[i] = 8;
icon_depths[num_layers + i] = 8;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 8);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 2);
}
}
{
if (num_colors <= 2)
{
/* Let's suggest monochrome */
icon_depths[i] = 1;
icon_depths[num_layers + i] = 1;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 2);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 0);
}
else if (num_colors <= 16)
{
/* Let's suggest 4bpp */
icon_depths[i] = 4;
icon_depths[num_layers + i] = 4;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 4);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 1);
}
else if (num_colors <= 256)
{
/* Let's suggest 8bpp */
icon_depths[i] = 8;
icon_depths[num_layers + i] = 8;
ico_specs_dialog_update_icon_preview (dialog, layers[i], 8);
gtk_combo_box_set_active (GTK_COMBO_BOX (icon_menu), 2);
}
}
/* Otherwise, or if real alpha levels are used, stick with 32bpp */
}
@ -358,28 +356,28 @@ ico_create_palette(guchar *cmap,
palette[i * 4] = cmap[i * 3 + 2];
if ((cmap[i*3] == 0) &&
(cmap[i*3 + 1] == 0) &&
(cmap[i*3 + 2] == 0))
{
*black_slot = i;
}
(cmap[i*3 + 1] == 0) &&
(cmap[i*3 + 2] == 0))
{
*black_slot = i;
}
}
if (*black_slot == -1)
{
if (num_colors_used == num_colors)
{
D(("WARNING -- no room for black, this shouldn't happen.\n"));
*black_slot = num_colors - 1;
{
D(("WARNING -- no room for black, this shouldn't happen.\n"));
*black_slot = num_colors - 1;
palette[(num_colors-1) * 4] = 0;
palette[(num_colors-1) * 4 + 1] = 0;
palette[(num_colors-1) * 4 + 2] = 0;
}
palette[(num_colors-1) * 4] = 0;
palette[(num_colors-1) * 4 + 1] = 0;
palette[(num_colors-1) * 4 + 2] = 0;
}
else
{
*black_slot = num_colors_used;
}
{
*black_slot = num_colors_used;
}
}
return (guint32 *) palette;
@ -497,7 +495,7 @@ ico_init_data (MsIcon *ico,
color_to_slot = ico_create_color_to_palette_map (data->palette,
num_colors_used);
D((" created %i-slot colormap with %i colors, black at slot %i\n",
num_colors, num_colors_used, black_index));
num_colors, num_colors_used, black_index));
}
/* Create and_map. It's padded out to 32 bits per line: */
@ -507,9 +505,9 @@ ico_init_data (MsIcon *ico,
for (y = 0; y < entry->height; y++)
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
pixel = (guint8 *) &buffer32[y * entry->width + x];
ico_set_bit_in_data (data->and_map, entry->width,
ico_set_bit_in_data (data->and_map, entry->width,
(entry->height-y-1) * entry->width + x,
(pixel[3] == 255 ? 0 : 1));
}
@ -522,91 +520,91 @@ ico_init_data (MsIcon *ico,
{
case 1:
for (y = 0; y < entry->height; y++)
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index (color_to_slot,
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index (color_to_slot,
pixel[0], pixel[1], pixel[2]);
if (ico_get_bit_from_data (data->and_map, entry->width,
if (ico_get_bit_from_data (data->and_map, entry->width,
(entry->height-y-1) * entry->width + x))
{
ico_set_bit_in_data (data->xor_map, entry->width,
{
ico_set_bit_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
black_index);
}
else
{
ico_set_bit_in_data (data->xor_map, entry->width,
}
else
{
ico_set_bit_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
palette_index);
}
}
}
}
break;
case 4:
for (y = 0; y < entry->height; y++)
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index(color_to_slot,
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index(color_to_slot,
pixel[0], pixel[1], pixel[2]);
if (ico_get_bit_from_data (data->and_map, entry->width,
if (ico_get_bit_from_data (data->and_map, entry->width,
(entry->height-y-1) * entry->width + x))
{
ico_set_nibble_in_data (data->xor_map, entry->width,
{
ico_set_nibble_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
black_index);
}
else
{
ico_set_nibble_in_data (data->xor_map, entry->width,
}
else
{
ico_set_nibble_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
palette_index);
}
}
}
}
break;
case 8:
for (y = 0; y < entry->height; y++)
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index (color_to_slot,
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
palette_index = ico_get_palette_index (color_to_slot,
pixel[0],
pixel[1],
pixel[2]);
if (ico_get_bit_from_data (data->and_map, entry->width,
if (ico_get_bit_from_data (data->and_map, entry->width,
(entry->height-y-1) * entry->width + x))
{
ico_set_byte_in_data (data->xor_map, entry->width,
{
ico_set_byte_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
black_index);
}
else
{
ico_set_byte_in_data (data->xor_map, entry->width,
}
else
{
ico_set_byte_in_data (data->xor_map, entry->width,
(entry->height-y-1) * entry->width + x,
palette_index);
}
}
}
}
break;
default:
for (y = 0; y < entry->height; y++)
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
for (x = 0; x < entry->width; x++)
{
pixel = (guint8 *) &buffer32[y * entry->width + x];
((guint32 *) data->xor_map)[(entry->height-y-1) * entry->width + x] =
GUINT32_TO_LE ((pixel[0] << 16) |
((guint32 *) data->xor_map)[(entry->height-y-1) * entry->width + x] =
GUINT32_TO_LE ((pixel[0] << 16) |
(pixel[1] << 8) |
(pixel[2]) |
(pixel[3] << 24));
}
}
}
D((" filled and_map of length %i, xor_map of length %i\n",
@ -639,8 +637,7 @@ ico_setup (MsIcon *ico,
for (i = 0; i < num_icons; i++)
{
ico_init_direntry (&ico->icon_dir[i], layers[i], icon_depths[i]);
if (interactive_ico)
gimp_progress_update ((gdouble) i / (gdouble) num_icons * 0.3);
gimp_progress_update ((gdouble) i / (gdouble) num_icons * 0.3);
}
/* Set up data entries (the actual icons), and calculate each one's size */
@ -649,13 +646,12 @@ ico_setup (MsIcon *ico,
ico_init_data (ico, i, layers[i], icon_depths[i]);
ico->icon_dir[i].size =
ico->icon_data[i].header_size +
ico->icon_data[i].palette_len +
ico->icon_data[i].xor_len +
ico->icon_data[i].and_len;
ico->icon_data[i].header_size +
ico->icon_data[i].palette_len +
ico->icon_data[i].xor_len +
ico->icon_data[i].and_len;
if (interactive_ico)
gimp_progress_update (0.3 + (gdouble) i / (gdouble) num_icons * 0.3);
gimp_progress_update (0.3 + (gdouble) i / (gdouble) num_icons * 0.3);
}
/* Finally, calculate offsets for each icon and store them in each entry */
@ -666,14 +662,12 @@ ico_setup (MsIcon *ico,
ico->icon_dir[i].offset = offset;
offset += ico->icon_dir[i].size;
if (interactive_ico)
gimp_progress_update (0.6 + (gdouble) i / (gdouble) num_icons * 0.3);
gimp_progress_update (0.6 + (gdouble) i / (gdouble) num_icons * 0.3);
}
if (interactive_ico)
gimp_progress_update (1.0);
gimp_progress_update (1.0);
g_free(layers);
g_free (layers);
}
@ -727,12 +721,12 @@ ico_sync_image_to_ico (gint32 image,
for (i = 0; i < num_layers; i++)
{
if (icon_depths[i] < icon_depths[num_layers + i])
{
D(("Layer '%s' was reduced to %i bpp -- updating source image.\n",
gimp_layer_get_name (layers[i]), icon_depths[i]));
{
D(("Layer '%s' was reduced to %i bpp -- updating source image.\n",
gimp_layer_get_name (layers[i]), icon_depths[i]));
ico_image_reduce_layer_bpp (layers[i], icon_depths[i]);
}
ico_image_reduce_layer_bpp (layers[i], icon_depths[i]);
}
}
g_free(layers);
@ -750,11 +744,11 @@ ico_layers_too_big (gint32 image)
for (i = 0; i < num_layers; i++)
{
if ((gimp_drawable_width (layers[i]) > 255) ||
(gimp_drawable_height (layers[i]) > 255))
{
g_free (layers);
return TRUE;
}
(gimp_drawable_height (layers[i]) > 255))
{
g_free (layers);
return TRUE;
}
}
g_free (layers);
@ -766,14 +760,15 @@ GimpPDBStatusType
SaveICO (const gchar *filename,
gint32 image)
{
MsIcon ico;
gint *icon_depths = NULL;
gint num_icons;
GimpPDBStatusType exit_state;
MsIcon ico;
gchar *temp_buf;
gint *icon_depths = NULL;
gint num_icons;
GimpPDBStatusType exit_state;
D(("*** Saving Microsoft icon file %s\n", filename));
if (ico_layers_too_big(image))
if (ico_layers_too_big (image))
{
g_message (_("Windows icons cannot be higher or wider than 255 pixels."));
return GIMP_PDB_EXECUTION_ERROR;
@ -782,20 +777,17 @@ SaveICO (const gchar *filename,
if (gimp_image_base_type (image) != GIMP_RGB)
{
if (! gimp_image_convert_rgb (image))
return GIMP_PDB_EXECUTION_ERROR;
return GIMP_PDB_EXECUTION_ERROR;
}
/* First, set up the icon specs dialog and show it: */
if ((icon_depths = ico_show_icon_dialog(image, &num_icons)) == NULL)
if ((icon_depths = ico_show_icon_dialog (image, &num_icons)) == NULL)
return GIMP_PDB_CANCEL;
if (interactive_ico)
{
guchar *temp_buf = g_strdup_printf (_("Saving %s:"),
gimp_filename_to_utf8 (filename));
gimp_progress_init (temp_buf);
g_free (temp_buf);
}
temp_buf = g_strdup_printf (_("Saving '%s'..."),
gimp_filename_to_utf8 (filename));
gimp_progress_init (temp_buf);
g_free (temp_buf);
/* Okay, let's actually save the thing with the depths the
user specified. */

View file

@ -24,7 +24,7 @@
GimpPDBStatusType SaveICO (const gchar *file_name,
gint32 image_ID);
gint32 image_ID);
#endif
#endif /* __ICO_SAVE_H__ */

View file

@ -24,8 +24,6 @@
#include <string.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
@ -38,15 +36,12 @@
#include "libgimp/stdplugins-intl.h"
gboolean interactive_ico = FALSE;
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
GimpPlugInInfo PLUG_IN_INFO =
@ -57,8 +52,10 @@ GimpPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
MAIN ()
static void
query (void)
{
@ -83,30 +80,30 @@ query (void)
};
gimp_install_procedure ("file_ico_load",
"Loads files of Windows ICO file format",
"Loads files of Windows ICO file format",
"Christian Kreibich <christian@whoop.org>",
"Christian Kreibich <christian@whoop.org>",
"2002",
"Loads files of Windows ICO file format",
"Loads files of Windows ICO file format",
"Christian Kreibich <christian@whoop.org>",
"Christian Kreibich <christian@whoop.org>",
"2002",
N_("Microsoft Windows icon"),
NULL,
GIMP_PLUGIN,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (load_args),
G_N_ELEMENTS (load_return_vals),
load_args, load_return_vals);
gimp_register_file_handler_mime ("file_ico_load", "image/x-ico");
gimp_register_magic_load_handler ("file_ico_load",
"ico",
"",
"0,string,\\000\\001\\000\\000,0,string,\\000\\002\\000\\000");
"ico",
"",
"0,string,\\000\\001\\000\\000,0,string,\\000\\002\\000\\000");
gimp_install_procedure ("file_ico_save",
"Saves files in Windows ICO file format",
"Saves files in Windows ICO file format",
"Christian Kreibich <christian@whoop.org>",
"Christian Kreibich <christian@whoop.org>",
"2002",
"Christian Kreibich <christian@whoop.org>",
"Christian Kreibich <christian@whoop.org>",
"2002",
N_("Microsoft Windows icon"),
"INDEXEDA, GRAYA, RGBA",
GIMP_PLUGIN,
@ -143,36 +140,34 @@ run (const gchar *name,
if (strcmp (name, "file_ico_load") == 0)
{
switch (run_mode)
{
{
case GIMP_RUN_INTERACTIVE:
interactive_ico = TRUE;
break;
case GIMP_RUN_NONINTERACTIVE:
interactive_ico = FALSE;
if (nparams != 3)
status = GIMP_PDB_CALLING_ERROR;
break;
case GIMP_RUN_NONINTERACTIVE:
if (nparams != 3)
status = GIMP_PDB_CALLING_ERROR;
break;
default:
break;
}
default:
break;
}
if (status == GIMP_PDB_SUCCESS)
{
image_ID = LoadICO (param[1].data.d_string);
{
image_ID = LoadICO (param[1].data.d_string);
if (image_ID != -1)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
if (image_ID != -1)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
}
else if (strcmp (name, "file_ico_save") == 0)
{
@ -185,18 +180,15 @@ run (const gchar *name,
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
interactive_ico = TRUE;
break;
case GIMP_RUN_NONINTERACTIVE:
interactive_ico = FALSE;
/* Make sure all the arguments are there! */
if (nparams < 5)
if (nparams < 5)
status = GIMP_PDB_CALLING_ERROR;
break;
case GIMP_RUN_WITH_LAST_VALS:
interactive_ico = FALSE;
break;
default:
@ -204,53 +196,53 @@ run (const gchar *name,
}
if (status == GIMP_PDB_SUCCESS)
{
status = SaveICO (file_name, image_ID);
}
{
status = SaveICO (file_name, image_ID);
}
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID);
gimp_image_delete (image_ID);
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
values[0].type = GIMP_PDB_STATUS;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
}
guint8 *
ico_alloc_map(gint width,
gint height,
gint bpp,
gint *length)
guint8 *
ico_alloc_map (gint width,
gint height,
gint bpp,
gint *length)
{
gint len = 0;
gint len = 0;
guint8 *map = NULL;
switch (bpp)
{
case 1:
if ((width % 32) == 0)
len = (width * height / 8);
len = (width * height / 8);
else
len = 4 * ((width/32 + 1) * height);
len = 4 * ((width/32 + 1) * height);
break;
case 4:
if ((width % 8) == 0)
len = (width * height / 2);
len = (width * height / 2);
else
len = 4 * ((width/8 + 1) * height);
len = 4 * ((width/8 + 1) * height);
break;
case 8:
if ((width % 4) == 0)
len = width * height;
len = width * height;
else
len = 4 * ((width/4 + 1) * height);
len = 4 * ((width/4 + 1) * height);
break;
default:
@ -258,7 +250,7 @@ ico_alloc_map(gint width,
}
*length = len;
map = g_new0(guint8, len);
map = g_new0 (guint8, len);
return map;
}
@ -273,11 +265,11 @@ ico_cmap_contains_black (guchar *cmap,
for (i = 0; i < num_colors; i++)
{
if ((cmap[3*i] == 0) &&
(cmap[3*i+1] == 0) &&
(cmap[3*i+2] == 0))
{
return TRUE;
}
(cmap[3*i+1] == 0) &&
(cmap[3*i+2] == 0))
{
return TRUE;
}
}
return FALSE;
@ -288,29 +280,29 @@ void
ico_image_reduce_layer_bpp (guint32 layer,
gint bpp)
{
GimpPixelRgn src_pixel_rgn, dst_pixel_rgn;
gint32 tmp_image;
gint32 tmp_layer;
gint w, h;
guchar *buffer;
GimpPixelRgn src_pixel_rgn, dst_pixel_rgn;
gint32 tmp_image;
gint32 tmp_layer;
gint w, h;
guchar *buffer;
w = gimp_drawable_width(layer);
h = gimp_drawable_height(layer);
w = gimp_drawable_width (layer);
h = gimp_drawable_height (layer);
if (bpp <= 8)
{
buffer = g_new (guchar, w * h * 4);
tmp_image = gimp_image_new (gimp_drawable_width (layer),
gimp_drawable_height (layer),
GIMP_RGB);
gimp_drawable_height (layer),
GIMP_RGB);
tmp_layer = gimp_layer_new (tmp_image, "tmp", w, h,
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
gimp_pixel_rgn_init (&src_pixel_rgn, gimp_drawable_get(layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get(tmp_layer),
0, 0, w, h, TRUE, FALSE);
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
gimp_pixel_rgn_init (&src_pixel_rgn, gimp_drawable_get (layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get (tmp_layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&src_pixel_rgn, buffer, 0, 0, w, h);
gimp_pixel_rgn_set_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
gimp_image_add_layer (tmp_image, tmp_layer, 0);
@ -326,7 +318,7 @@ ico_image_reduce_layer_bpp (guint32 layer,
gimp_image_convert_rgb (tmp_image);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get (tmp_layer),
0, 0, w, h, TRUE, FALSE);
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
gimp_pixel_rgn_set_rect (&src_pixel_rgn, buffer, 0, 0, w, h);
@ -367,49 +359,49 @@ ico_image_get_reduced_buf (guint32 layer,
if (bpp <= 8)
{
tmp_image = gimp_image_new (gimp_drawable_width (layer),
gimp_drawable_height (layer),
gimp_drawable_height (layer),
GIMP_RGB);
tmp_layer = gimp_layer_new (tmp_image, "tmp", w, h,
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
gimp_pixel_rgn_init (&src_pixel_rgn, gimp_drawable_get(layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get(tmp_layer),
0, 0, w, h, TRUE, FALSE);
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get (tmp_layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&src_pixel_rgn, buffer, 0, 0, w, h);
gimp_pixel_rgn_set_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
gimp_image_add_layer (tmp_image, tmp_layer, 0);
result = gimp_image_convert_indexed(tmp_image,
GIMP_FS_DITHER,
GIMP_MAKE_PALETTE,
1 << bpp,
TRUE,
FALSE,
"dummy");
result = gimp_image_convert_indexed (tmp_image,
GIMP_FS_DITHER,
GIMP_MAKE_PALETTE,
1 << bpp,
TRUE,
FALSE,
"dummy");
cmap = gimp_image_get_colormap (tmp_image, num_colors);
if (*num_colors == (1 << bpp) &&
!ico_cmap_contains_black(cmap, *num_colors))
{
/* Damn. Windows icons with color maps need the color black.
We need to eliminate one more color to make room for black: */
{
/* Damn. Windows icons with color maps need the color black.
We need to eliminate one more color to make room for black: */
result = gimp_image_convert_rgb(tmp_image);
result = gimp_image_convert_rgb (tmp_image);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get(tmp_layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_set_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get (tmp_layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_set_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
result = gimp_image_convert_indexed(tmp_image,
GIMP_FS_DITHER,
GIMP_MAKE_PALETTE,
(1 << bpp) - 1,
TRUE,
FALSE,
"dummy");
}
result = gimp_image_convert_indexed (tmp_image,
GIMP_FS_DITHER,
GIMP_MAKE_PALETTE,
(1 << bpp) - 1,
TRUE,
FALSE,
"dummy");
}
cmap = gimp_image_get_colormap (tmp_image, num_colors);
*cmap_out = g_memdup (cmap, *num_colors * 3);
@ -417,18 +409,18 @@ ico_image_get_reduced_buf (guint32 layer,
result = gimp_image_convert_rgb (tmp_image);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get(tmp_layer),
0, 0, w, h, TRUE, FALSE);
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
drawable = gimp_drawable_get(tmp_layer);
drawable = gimp_drawable_get (tmp_layer);
*buf_bpp = drawable->bpp;
gimp_image_delete(tmp_image);
gimp_image_delete (tmp_image);
}
else
{
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get(layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, gimp_drawable_get (layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
drawable = gimp_drawable_get (layer);
@ -466,7 +458,7 @@ ico_get_layer_num_colors (gint32 layer,
buffer = g_new (gint32, w * h);
gimp_pixel_rgn_init (&pixel_rgn, gimp_drawable_get (layer),
0, 0, w, h, TRUE, FALSE);
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_get_rect (&pixel_rgn, (guchar*) buffer, 0, 0, w, h);
hash = g_hash_table_new (g_int_hash, g_int_equal);
@ -475,22 +467,22 @@ ico_get_layer_num_colors (gint32 layer,
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
color = g_new0 (guint32, 1);
*color = buffer[y * w + x];
alpha = ((guint8*) color)[3];
color = g_new0 (guint32, 1);
*color = buffer[y * w + x];
alpha = ((guint8*) color)[3];
if (alpha != 0 && alpha != 255)
*uses_alpha_levels = TRUE;
if (alpha != 0 && alpha != 255)
*uses_alpha_levels = TRUE;
g_hash_table_insert(hash, color, color);
g_hash_table_insert (hash, color, color);
}
num_colors = g_hash_table_size(hash);
num_colors = g_hash_table_size (hash);
g_hash_table_foreach (hash, ico_free_color_item, NULL);
g_hash_table_destroy (hash);
g_free(buffer);
g_free (buffer);
return num_colors;
}
@ -506,7 +498,7 @@ ico_cleanup (MsIcon *ico)
return;
if (ico->fp)
fclose(ico->fp);
fclose (ico->fp);
if (ico->icon_dir)
g_free (ico->icon_dir);
@ -514,13 +506,11 @@ ico_cleanup (MsIcon *ico)
if (ico->icon_data)
{
for (i = 0; i < ico->icon_count; i++)
{
g_free (ico->icon_data[i].palette);
g_free (ico->icon_data[i].xor_map);
g_free (ico->icon_data[i].and_map);
}
{
g_free (ico->icon_data[i].palette);
g_free (ico->icon_data[i].xor_map);
g_free (ico->icon_data[i].and_map);
}
g_free (ico->icon_data);
}
}

View file

@ -23,9 +23,6 @@
#define __MAIN_H__
extern gboolean interactive_ico;
#ifdef ICO_DBG
#define D(x) \
{ \
@ -112,4 +109,4 @@ gint ico_get_layer_num_colors (gint32 layer,
void ico_cleanup (MsIcon *ico);
#endif
#endif /* __MAIN_H__ */