Commit 1309a075 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

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.
parent 41c1e003
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
......
......@@ -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 */
......
......@@ -32,4 +32,4 @@ void ico_specs_dialog_update_icon_preview (GtkWidget *dialog,
gint bpp);
#endif
#endif /* __ICO_DIALOG_H__ */
......@@ -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]);
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;
case 4:
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
{
guint32 color = palette[ico_get_nibble_from_data (xor_map,
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);
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,
w, 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);
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,
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);
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,
w, 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);
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;
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];
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];
}
}
}
}
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);
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;
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];
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;
if (interactive_ico)
{
guchar *temp = g_strdup_printf (_("Loading %s:"),
gimp_filename_to_utf8 (filename));
gimp_progress_init (temp);
g_free (temp);
}
gchar *temp;
gint32 image_ID;
MsIcon ico;
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;
......
......@@ -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__ */
......@@ -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;