Commit 006882a0 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

plug-ins/winicon/main.[ch] (ico_image_get_reduced_buf)

2004-11-26  Sven Neumann  <sven@gimp.org>

	* plug-ins/winicon/main.[ch] (ico_image_get_reduced_buf)
	* plug-ins/winicon/icodialog.c
	* plug-ins/winicon/icoload.c
	* plug-ins/winicon/icosave.c: fixed drawable handling. This
	plug-in is still a complete mess and needs a lot more work.
parent 9083a57e
2004-11-26 Sven Neumann <sven@gimp.org>
* plug-ins/winicon/main.[ch] (ico_image_get_reduced_buf)
* plug-ins/winicon/icodialog.c
* plug-ins/winicon/icoload.c
* plug-ins/winicon/icosave.c: fixed drawable handling. This
plug-in is still a complete mess and needs a lot more work.
2004-11-26 Sven Neumann <sven@gimp.org>
 
* app/tools/gimppaintoptions-gui.c (gimp_paint_options_gui): only
......
......@@ -255,6 +255,8 @@ ico_specs_dialog_update_icon_preview (GtkWidget *dialog,
gint w, h;
guchar *buffer;
gboolean result;
GimpDrawable *drawable = gimp_drawable_get (layer);
GimpDrawable *tmp;
tmp_image = gimp_image_new (gimp_drawable_width (layer),
gimp_drawable_height (layer),
......@@ -267,15 +269,18 @@ ico_specs_dialog_update_icon_preview (GtkWidget *dialog,
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
gimp_image_add_layer (tmp_image, tmp_layer, 0);
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);
tmp = gimp_drawable_get (tmp_layer);
gimp_pixel_rgn_init (&src_pixel_rgn, drawable, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, tmp, 0, 0, w, h, TRUE, FALSE);
buffer = g_malloc (w * h * 4);
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_drawable_detach (tmp);
gimp_drawable_detach (drawable);
if (bpp < 32)
{
result = gimp_image_convert_indexed (tmp_image,
......@@ -287,11 +292,12 @@ ico_specs_dialog_update_icon_preview (GtkWidget *dialog,
"dummy");
}
gimp_image_delete (tmp_image);
preview = ico_specs_dialog_get_layer_preview (dialog, layer);
ico_fill_preview_with_thumb (preview, tmp_layer);
gtk_widget_queue_draw (preview);
gimp_image_delete (tmp_image);
g_free (buffer);
}
......
......@@ -483,7 +483,7 @@ ico_to_gimp (MsIcon *ico)
0, 0, drawable->width, drawable->height);
g_free(dest_vec);
gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable);
}
......
......@@ -453,7 +453,7 @@ ico_init_data (MsIcon *ico,
MsIconEntry *entry;
MsIconData *data;
gint and_len, xor_len, palette_index, x, y;
gint num_colors = 0, num_colors_used = 0, buf_bpp, black_index;
gint num_colors = 0, num_colors_used = 0, black_index;
guchar *buffer = NULL, *pixel;
guint32 *buffer32;
guchar *palette;
......@@ -479,8 +479,7 @@ ico_init_data (MsIcon *ico,
data->header_size, data->width, data->height, data->planes, data->bpp));
/* Reduce colors in copy of image */
ico_image_get_reduced_buf (layer, bpp, &num_colors_used,
&palette, &buffer, &buf_bpp);
ico_image_get_reduced_buf (layer, bpp, &num_colors_used, &palette, &buffer);
buffer32 = (guint32 *) buffer;
/* Set up colormap and andmap when necessary: */
......
......@@ -291,6 +291,9 @@ ico_image_reduce_layer_bpp (guint32 layer,
if (bpp <= 8)
{
GimpDrawable *drawable = gimp_drawable_get (layer);
GimpDrawable *tmp;
buffer = g_new (guchar, w * h * 4);
tmp_image = gimp_image_new (gimp_drawable_width (layer),
......@@ -299,10 +302,11 @@ ico_image_reduce_layer_bpp (guint32 layer,
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);
tmp = gimp_drawable_get (tmp_layer);
gimp_pixel_rgn_init (&src_pixel_rgn, drawable, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, tmp, 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);
......@@ -317,15 +321,15 @@ 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);
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);
gimp_pixel_rgn_init (&src_pixel_rgn, tmp, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, drawable, 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_drawable_detach (tmp);
gimp_image_delete (tmp_image);
gimp_drawable_update (layer, 0, 0, w ,h);
/* WTF! What else can I do to make the layer dialog update??? */
gimp_drawable_detach (drawable);
g_free (buffer);
}
......@@ -337,8 +341,7 @@ ico_image_get_reduced_buf (guint32 layer,
gint bpp,
gint *num_colors,
guchar **cmap_out,
guchar **buf_out,
gint *buf_bpp)
guchar **buf_out)
{
GimpPixelRgn src_pixel_rgn, dst_pixel_rgn;
gint32 tmp_image;
......@@ -346,8 +349,7 @@ ico_image_get_reduced_buf (guint32 layer,
gint w, h;
guchar *buffer;
guchar *cmap;
gboolean result;
GimpDrawable *drawable;
GimpDrawable *drawable = gimp_drawable_get (layer);
w = gimp_drawable_width (layer);
h = gimp_drawable_height (layer);
......@@ -358,27 +360,33 @@ ico_image_get_reduced_buf (guint32 layer,
if (bpp <= 8)
{
GimpDrawable *tmp;
tmp_image = gimp_image_new (gimp_drawable_width (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_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_drawable_type (layer),
100, GIMP_NORMAL_MODE);
tmp = gimp_drawable_get (tmp_layer);
gimp_pixel_rgn_init (&src_pixel_rgn, drawable, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_init (&dst_pixel_rgn, tmp, 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_drawable_flush (tmp);
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");
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);
......@@ -388,45 +396,40 @@ ico_image_get_reduced_buf (guint32 layer,
/* 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);
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_init (&dst_pixel_rgn, tmp, 0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_set_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
gimp_drawable_flush (tmp);
result = gimp_image_convert_indexed (tmp_image,
GIMP_FS_DITHER,
GIMP_MAKE_PALETTE,
(1 << bpp) - 1,
TRUE,
FALSE,
"dummy");
}
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);
cmap = gimp_image_get_colormap (tmp_image, num_colors);
*cmap_out = g_memdup (cmap, *num_colors * 3);
result = gimp_image_convert_rgb (tmp_image);
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_init (&dst_pixel_rgn, tmp, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_get_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
drawable = gimp_drawable_get (tmp_layer);
*buf_bpp = drawable->bpp;
gimp_drawable_detach (tmp);
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, drawable, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_get_rect (&dst_pixel_rgn, buffer, 0, 0, w, h);
drawable = gimp_drawable_get (layer);
*buf_bpp = drawable->bpp;
}
gimp_drawable_detach (drawable);
*buf_out = buffer;
}
......@@ -452,15 +455,17 @@ ico_get_layer_num_colors (gint32 layer,
gint x, y, w, h, alpha, num_colors = 0;
guint32 *buffer = NULL, *color;
GHashTable *hash;
GimpDrawable *drawable = gimp_drawable_get (layer);
w = gimp_drawable_width (layer);
h = gimp_drawable_height (layer);
buffer = g_new (gint32, w * h);
gimp_pixel_rgn_init (&pixel_rgn, gimp_drawable_get (layer),
0, 0, w, h, TRUE, FALSE);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, w, h, FALSE, FALSE);
gimp_pixel_rgn_get_rect (&pixel_rgn, (guchar*) buffer, 0, 0, w, h);
gimp_drawable_detach (drawable);
hash = g_hash_table_new (g_int_hash, g_int_equal);
*uses_alpha_levels = FALSE;
......
......@@ -102,8 +102,7 @@ void ico_image_get_reduced_buf (guint32 layer,
gint bpp,
gint *num_colors,
guchar **cmap,
guchar **buffer,
gint *buf_bpp);
guchar **buffer);
gint ico_get_layer_num_colors (gint32 layer,
gboolean *uses_alpha_levels);
void ico_cleanup (MsIcon *ico);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment