2003-11-09 08:53:49 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
1999-03-18 07:45:24 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/* WMF loading file filter for the GIMP
|
|
|
|
* -Dom Lachowicz <cinamod@hotmail.com> 2003
|
|
|
|
* -Francis James Franklin <fjf@alinameridon.com>
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* *) image preview
|
|
|
|
*/
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-03-18 07:45:24 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
#include <libwmf/api.h>
|
|
|
|
#include <libwmf/gd.h>
|
2001-09-03 21:03:34 +08:00
|
|
|
|
2000-01-09 04:00:10 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
#include <libgimpmath/gimpmath.h>
|
2000-01-09 04:00:10 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2000-01-16 01:22:19 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
typedef struct
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
gdouble scale;
|
|
|
|
} WmfLoadVals;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static WmfLoadVals load_vals =
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
1.0 /* scale */
|
|
|
|
};
|
1999-03-18 07:45:24 +08:00
|
|
|
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
static gint32 load_image (const gchar *filename,
|
|
|
|
GimpRunMode runmode,
|
|
|
|
gboolean preview);
|
|
|
|
static gboolean load_dialog (const gchar *filename);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
GimpPlugInInfo PLUG_IN_INFO =
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
|
|
|
};
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
MAIN ()
|
1999-03-18 07:45:24 +08:00
|
|
|
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/*
|
|
|
|
* 'query()' - Respond to a plug-in query...
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
query (void)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
static GimpParamDef load_args[] =
|
|
|
|
{
|
|
|
|
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
|
|
|
{ GIMP_PDB_STRING, "raw_filename", "The name of the file to load" },
|
|
|
|
{ GIMP_PDB_FLOAT, "scale", "Scale in which to load image" }
|
|
|
|
};
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static GimpParamDef load_return_vals[] =
|
|
|
|
{
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Output image" }
|
|
|
|
};
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_install_procedure ("file_wmf_load",
|
|
|
|
"Loads files in the WMF file format",
|
|
|
|
"Loads files in the WMF file format",
|
|
|
|
"Dom Lachowicz <cinamod@hotmail.com>",
|
|
|
|
"Dom Lachowicz <cinamod@hotmail.com>",
|
|
|
|
"(c) 2003 - Version 0.3.0",
|
|
|
|
"<Load>/WMF",
|
|
|
|
NULL,
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (load_args),
|
|
|
|
G_N_ELEMENTS (load_return_vals),
|
|
|
|
load_args, load_return_vals);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_register_magic_load_handler ("file_wmf_load",
|
|
|
|
"wmf,apm", "",
|
|
|
|
"0,string,\\327\\315\\306\\232,0,string,\\1\\0\\11\\0");
|
|
|
|
}
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/*
|
|
|
|
* 'run()' - Run the plug-in...
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
static GimpParam values[2];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
gint32 image_ID;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
INIT_I18N ();
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (strcmp (name, "file_wmf_load") == 0)
|
|
|
|
{
|
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
gimp_get_data ("file_wmf_load", &load_vals);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (!load_dialog (param[1].data.d_string))
|
|
|
|
status = GIMP_PDB_CANCEL;
|
|
|
|
break;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
gimp_get_data ("file_wmf_load", &load_vals);
|
|
|
|
break;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
gimp_get_data ("file_wmf_load", &load_vals);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
load_vals.scale = CLAMP (load_vals.scale, 0.01, 100.0);
|
|
|
|
|
|
|
|
image_ID = load_image (param[1].data.d_string, run_mode, FALSE);
|
|
|
|
gimp_set_data ("file_wmf_load", &load_vals, sizeof (load_vals));
|
|
|
|
|
|
|
|
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
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static gboolean
|
|
|
|
load_dialog (const gchar *filename)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
GtkWidget *dialog;
|
1999-03-18 07:45:24 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
2003-11-09 08:53:49 +08:00
|
|
|
GtkObject *scale;
|
|
|
|
gboolean run = FALSE;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
gimp_ui_init ("wmf", FALSE);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
dialog = gimp_dialog_new (_("Load Windows Metafile"), "wmf",
|
|
|
|
NULL, 0,
|
|
|
|
gimp_standard_help_func, "wmf",
|
2002-01-16 02:35:29 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
2000-01-09 04:00:10 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
NULL);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
|
|
|
/* Rendering */
|
2003-11-09 08:53:49 +08:00
|
|
|
frame = gtk_frame_new (g_strdup_printf (_("Rendering %s"), filename));
|
2000-01-09 04:00:10 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
|
1999-03-18 07:45:24 +08:00
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
2003-11-09 08:53:49 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
|
2000-01-09 04:00:10 +08:00
|
|
|
TRUE, TRUE, 0);
|
2003-11-09 18:50:36 +08:00
|
|
|
gtk_widget_show (frame);
|
2000-01-09 04:00:10 +08:00
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 4);
|
2000-08-28 08:42:32 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
|
1999-03-18 07:45:24 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
2003-11-09 18:50:36 +08:00
|
|
|
gtk_widget_show (vbox);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
|
|
|
/* Scale label */
|
2003-11-09 18:50:36 +08:00
|
|
|
table = gtk_table_new (1, 3, FALSE);
|
2000-01-09 04:00:10 +08:00
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
1999-03-18 07:45:24 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
/* Scale slider */
|
2003-11-09 18:50:36 +08:00
|
|
|
scale = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Scale (log 2):"), -1, -1,
|
|
|
|
0.0, -2.0, 2.0,
|
|
|
|
0.1, 0.5, 1,
|
|
|
|
TRUE, 0.0, 0.0,
|
|
|
|
NULL, NULL);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gtk_widget_show (dialog);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
load_vals.scale = pow (2,
|
|
|
|
gtk_adjustment_get_value (GTK_ADJUSTMENT (scale)));
|
|
|
|
run = TRUE;
|
|
|
|
}
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static guchar *
|
|
|
|
pixbuf_gd_convert (gint *gd_pixels,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
guchar *pixels = NULL;
|
|
|
|
guchar *px_ptr = NULL;
|
|
|
|
int *gd_ptr = gd_pixels;
|
|
|
|
gint i = 0;
|
|
|
|
gint j = 0;
|
|
|
|
gsize alloc_size = width * height * sizeof (guchar) * 4;
|
|
|
|
guint pixel;
|
|
|
|
guchar r,g,b,a;
|
2003-03-26 00:38:19 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
pixels = (guchar *) g_try_malloc (alloc_size);
|
|
|
|
if (! pixels)
|
|
|
|
return NULL;
|
2002-01-16 02:35:29 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
px_ptr = pixels;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
for (j = 0; j < width; j++)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
pixel = (guint) (*gd_ptr++);
|
|
|
|
|
|
|
|
b = (guchar) (pixel & 0xff);
|
|
|
|
pixel >>= 8;
|
|
|
|
g = (guchar) (pixel & 0xff);
|
|
|
|
pixel >>= 8;
|
|
|
|
r = (guchar) (pixel & 0xff);
|
|
|
|
pixel >>= 7;
|
|
|
|
a = (guchar) (pixel & 0xfe);
|
|
|
|
a ^= 0xff;
|
|
|
|
|
|
|
|
*px_ptr++ = r;
|
|
|
|
*px_ptr++ = g;
|
|
|
|
*px_ptr++ = b;
|
|
|
|
*px_ptr++ = a;
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
2003-11-09 08:53:49 +08:00
|
|
|
return pixels;
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
static guchar *
|
|
|
|
wmf_load_file (const gchar *filename,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
guchar *pixels = NULL;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/* the bits we need to decode the WMF via libwmf2's GD layer */
|
|
|
|
wmf_error_t err;
|
|
|
|
gulong flags;
|
|
|
|
wmf_gd_t *ddata = NULL;
|
|
|
|
wmfAPI *API = NULL;
|
|
|
|
wmfAPI_Options api_options;
|
|
|
|
wmfD_Rect bbox;
|
|
|
|
gint *gd_pixels = NULL;
|
|
|
|
gdouble resolution_x;
|
|
|
|
gdouble resolution_y;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
resolution_x = resolution_y = 72.0;
|
|
|
|
*width = *height = -1;
|
2003-11-01 03:24:36 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
flags = WMF_OPT_IGNORE_NONFATAL | WMF_OPT_FUNCTION;
|
|
|
|
api_options.function = wmf_gd_function;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
err = wmf_api_create (&API, flags, &api_options);
|
|
|
|
if (err != wmf_E_None)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
ddata = WMF_GD_GetData (API);
|
|
|
|
ddata->type = wmf_gd_image;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
err = wmf_file_open (API, filename);
|
|
|
|
if (err != wmf_E_None)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
err = wmf_scan (API, 0, &bbox);
|
|
|
|
if (err != wmf_E_None)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
err = wmf_display_size (API, width, height, resolution_x, resolution_y);
|
|
|
|
if (err != wmf_E_None || *width <= 0 || *height <= 0)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
*width *= load_vals.scale;
|
|
|
|
*height *= load_vals.scale;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
ddata->bbox = bbox;
|
|
|
|
ddata->width = *width;
|
|
|
|
ddata->height = *height;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
err = wmf_play (API, 0, &bbox);
|
|
|
|
if (err != wmf_E_None)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
wmf_file_close (API);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (ddata->gd_image != NULL)
|
|
|
|
gd_pixels = wmf_gd_image_pixels (ddata->gd_image);
|
|
|
|
if (gd_pixels == NULL)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
pixels = pixbuf_gd_convert (gd_pixels, *width, *height);
|
|
|
|
if (pixels == NULL)
|
|
|
|
goto _wmf_error;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
wmf_api_destroy (API);
|
|
|
|
API = NULL;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
_wmf_error:
|
|
|
|
if (API)
|
|
|
|
wmf_api_destroy (API);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
return pixels;
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/*
|
|
|
|
* 'load_image()' - Load a WMF image into a new image window.
|
|
|
|
*/
|
1999-03-18 07:45:24 +08:00
|
|
|
static gint32
|
2003-11-09 08:53:49 +08:00
|
|
|
load_image (const gchar *filename,
|
|
|
|
GimpRunMode runmode,
|
|
|
|
gboolean preview)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
gint32 image;
|
|
|
|
gint32 layer;
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpDrawable *drawable;
|
2003-11-09 08:53:49 +08:00
|
|
|
GimpPixelRgn pixel_rgn;
|
|
|
|
gchar *status;
|
|
|
|
gint i, rowstride;
|
|
|
|
|
|
|
|
guchar *pixels, *buf;
|
|
|
|
gint width, height;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
pixels = buf = wmf_load_file (filename, &width, &height);
|
|
|
|
rowstride = width * 4;
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (!pixels)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
g_message (_("Can't open '%s'"), filename);
|
|
|
|
gimp_quit ();
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
status = g_strdup_printf (_("Loading %s:"), filename);
|
|
|
|
gimp_progress_init (status);
|
|
|
|
g_free (status);
|
2003-09-09 19:35:27 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
image = gimp_image_new (width, height, GIMP_RGB);
|
|
|
|
|
|
|
|
if (image == -1)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
g_message ("Can't allocate new image: %s\n", filename);
|
|
|
|
gimp_quit ();
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_image_set_filename (image, filename);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
layer = gimp_layer_new (image, _("Rendered WMF"),
|
|
|
|
width, height, GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
drawable = gimp_drawable_get (layer);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_tile_cache_ntiles ((width / gimp_tile_width ()) + 1);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
|
|
|
|
drawable->width, drawable->height, TRUE, FALSE);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
for (i = 0; i < height; i++)
|
1999-03-18 07:45:24 +08:00
|
|
|
{
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_pixel_rgn_set_row (&pixel_rgn, buf, 0, i, width);
|
|
|
|
buf += rowstride;
|
2003-11-01 03:24:36 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
if (i % 100 == 0)
|
|
|
|
gimp_progress_update ((gdouble) i / (gdouble) height);
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
g_free (pixels);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
1999-03-18 07:45:24 +08:00
|
|
|
|
2003-11-09 08:53:49 +08:00
|
|
|
/* Tell the GIMP to display the image.
|
|
|
|
*/
|
|
|
|
gimp_image_add_layer (image, layer, 0);
|
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
|
|
|
|
return image;
|
1999-03-18 07:45:24 +08:00
|
|
|
}
|