plug-ins/winicon/icoload.c added a thumbnail loader for .ico files Fixes

2005-05-07  Sven Neumann  <sven@gimp.org>

	* plug-ins/winicon/icoload.c
	* plug-ins/winicon/main.c: added a thumbnail loader for .ico files
	Fixes bug #158191.
This commit is contained in:
Sven Neumann 2005-05-07 00:06:33 +00:00 committed by Sven Neumann
parent e016f2db02
commit b163c36962
3 changed files with 134 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2005-05-07 Sven Neumann <sven@gimp.org>
* plug-ins/winicon/icoload.c
* plug-ins/winicon/main.c: added a thumbnail loader for .ico files
Fixes bug #158191.
2005-05-07 Sven Neumann <sven@gimp.org>
* plug-ins/winicon/icoload.[ch]

View File

@ -484,9 +484,6 @@ ico_load_image (const gchar *filename)
height = ico.icon_dir[i].height;
}
for (i = 0; i < ico.icon_count; i++)
ico_read_data (&ico, i);
if (width < 1 || height < 1)
return -1;
@ -494,6 +491,9 @@ ico_load_image (const gchar *filename)
gimp_image_set_filename (image, ico.filename);
/* Scan icons again and set up a layer for each icon */
for (i = 0; i < ico.icon_count; i++)
ico_read_data (&ico, i);
layer = ico_load_layer (image, &ico, 0);
for (i = 1; i < ico.icon_count; i++)
ico_load_layer (image, &ico, i);
@ -514,6 +514,70 @@ ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height)
{
/* FIXME: implement thumbnail loading (bug #158191) */
MsIcon ico;
gint32 image;
gint32 layer;
gint w = 0;
gint h = 0;
gint match = 0;
gint i;
gimp_progress_init (NULL);
gimp_progress_set_text (_("Opening thumbnail for '%s'..."),
gimp_filename_to_utf8 (filename));
if (! ico_init (filename, &ico))
return -1;
ico.cp += ico_read_int16 (ico.fp, &ico.icon_count, 1);
ico.icon_dir = g_new0 (MsIconEntry, ico.icon_count);
ico.icon_data = g_new0 (MsIconData, ico.icon_count);
D(("*** %s: Microsoft icon file, containing %i icon(s)\n",
ico.filename, ico.icon_count));
for (i = 0; i < ico.icon_count; i++)
ico_read_entry (&ico, &ico.icon_dir[i]);
/* Do a quick scan of the icons in the file to find the best match */
for (i = 0; i < ico.icon_count; i++)
{
if ((ico.icon_dir[i].width > w && w < *width) ||
(ico.icon_dir[i].height > h && h < *height))
{
w = ico.icon_dir[i].width;
h = ico.icon_dir[i].height;
match = i;
}
}
if (w < 1 || h < 1)
return -1;
ico_read_data (&ico, match);
image = gimp_image_new (w, h, GIMP_RGB);
layer = ico_load_layer (image, &ico, match);
/* Do a quick scan of the icons in the file to find the largest icon */
for (i = 0, w = 0, h = 0; i < ico.icon_count; i++)
{
if (ico.icon_dir[i].width > w)
w = ico.icon_dir[i].width;
if (ico.icon_dir[i].height > h)
h = ico.icon_dir[i].height;
}
*width = w;
*height = h;
D(("*** thumbnail successfully loaded.\n\n"));
gimp_progress_update (1.0);
ico_cleanup (&ico);
return image;
}

View File

@ -69,6 +69,18 @@ query (void)
{ GIMP_PDB_IMAGE, "image", "Output image" },
};
static GimpParamDef thumb_args[] =
{
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
{ GIMP_PDB_INT32, "thumb_size", "Preferred thumbnail size" }
};
static GimpParamDef thumb_return_vals[] =
{
{ GIMP_PDB_IMAGE, "image", "Thumbnail image" },
{ GIMP_PDB_INT32, "image_width", "Width of full-sized image" },
{ GIMP_PDB_INT32, "image_height", "Height of full-sized image" }
};
static GimpParamDef save_args[] =
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
@ -97,6 +109,21 @@ query (void)
"",
"0,string,\\000\\001\\000\\000,0,string,\\000\\002\\000\\000");
gimp_install_procedure ("file_ico_load_thumb",
"Loads a preview from an Windows ICO file",
"",
"Dom Lachowicz, Sven Neumann",
"Sven Neumann <sven@gimp.org>",
"2005",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (thumb_args),
G_N_ELEMENTS (thumb_return_vals),
thumb_args, thumb_return_vals);
gimp_register_thumbnail_loader ("file_ico_load", "file_ico_load_thumb");
gimp_install_procedure ("file_ico_save",
"Saves files in Windows ICO file format",
"Saves files in Windows ICO file format",
@ -168,6 +195,38 @@ run (const gchar *name,
}
}
}
else if (strcmp (name, "file_ico_load_thumb") == 0)
{
if (nparams < 2)
{
status = GIMP_PDB_CALLING_ERROR;
}
else
{
const gchar *filename = param[0].data.d_string;
gint width = param[1].data.d_int32;
gint height = param[1].data.d_int32;
gint32 image_ID;
image_ID = ico_load_thumbnail_image (filename, &width, &height);
if (image_ID != -1)
{
*nreturn_vals = 4;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
values[2].type = GIMP_PDB_INT32;
values[2].data.d_int32 = width;
values[3].type = GIMP_PDB_INT32;
values[3].data.d_int32 = height;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
}
else if (strcmp (name, "file_ico_save") == 0)
{
gchar *file_name;
@ -254,7 +313,6 @@ ico_alloc_map (gint width,
return map;
}
void
ico_cleanup (MsIcon *ico)
{