1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
* XWD reading and writing code Copyright (C) 1996 Peter Kirchgessner
4
4
* (email: peter@kirchgessner.net, WWW: http://www.kirchgessner.net)
48
48
specified as big-endian). Trim magic header
49
49
* V 1.95, PK, 02-Jul-01: Fix problem with 8 bit image
51
static char ident[] = "@(#) GIMP XWD file-plugin v1.95 02-Jul-2001";
53
52
#include "config.h"
58
55
#include <string.h>
57
#include <glib/gstdio.h>
65
59
#include <libgimp/gimp.h>
66
60
#include <libgimp/gimpui.h>
248
static GimpParamDef load_args[] =
247
static const GimpParamDef load_args[] =
250
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
249
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
251
250
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
252
{ GIMP_PDB_STRING, "raw_filename", "The name of the file to load" }
251
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
255
static GimpParamDef load_return_vals[] =
254
static const GimpParamDef load_return_vals[] =
257
256
{ GIMP_PDB_IMAGE, "image", "Output image" }
260
static GimpParamDef save_args[] =
259
static const GimpParamDef save_args[] =
262
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
261
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
263
262
{ GIMP_PDB_IMAGE, "image", "Input image" },
264
263
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
265
264
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
266
{ GIMP_PDB_STRING, "raw_filename", "The name of the file to save the image in" }
265
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" }
269
gimp_install_procedure ("file_xwd_load",
268
gimp_install_procedure (LOAD_PROC,
270
269
"Loads files in the XWD (X Window Dump) format",
271
270
"Loads files in the XWD (X Window Dump) format. "
272
271
"XWD image files are produced by the program xwd. "
281
280
G_N_ELEMENTS (load_return_vals),
282
281
load_args, load_return_vals);
284
gimp_register_file_handler_mime ("file_xwd_load", "image/x-xwindowdump");
285
gimp_register_magic_load_handler ("file_xwd_load",
283
gimp_register_file_handler_mime (LOAD_PROC, "image/x-xwindowdump");
284
gimp_register_magic_load_handler (LOAD_PROC,
288
287
"4,long,0x00000007");
290
gimp_install_procedure ("file_xwd_save",
289
gimp_install_procedure (SAVE_PROC,
291
290
"Saves files in the XWD (X Window Dump) format",
292
291
"XWD saving handles all image types except "
293
292
"those with alpha channels.",
300
299
G_N_ELEMENTS (save_args), 0,
301
300
save_args, NULL);
303
gimp_register_file_handler_mime ("file_xwd_save", "image/x-xwindowdump");
304
gimp_register_save_handler ("file_xwd_save", "xwd", "");
302
gimp_register_file_handler_mime (SAVE_PROC, "image/x-xwindowdump");
303
gimp_register_save_handler (SAVE_PROC, "xwd", "");
329
328
values[0].type = GIMP_PDB_STATUS;
330
329
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
332
if (strcmp (name, "file_xwd_load") == 0)
331
if (strcmp (name, LOAD_PROC) == 0)
334
333
image_ID = load_image (param[1].data.d_string);
344
343
status = GIMP_PDB_EXECUTION_ERROR;
347
else if (strcmp (name, "file_xwd_save") == 0)
346
else if (strcmp (name, SAVE_PROC) == 0)
349
348
image_ID = param[1].data.d_int32;
350
349
drawable_ID = param[2].data.d_int32;
355
354
case GIMP_RUN_INTERACTIVE:
356
355
case GIMP_RUN_WITH_LAST_VALS:
357
gimp_ui_init ("xwd", FALSE);
356
gimp_ui_init (PLUG_IN_BINARY, FALSE);
358
357
export = gimp_export_image (&image_ID, &drawable_ID, "XWD",
359
358
(GIMP_EXPORT_CAN_HANDLE_RGB |
360
359
GIMP_EXPORT_CAN_HANDLE_GRAY |
416
414
L_XWDFILEHEADER xwdhdr;
417
415
L_XWDCOLOR *xwdcolmap = NULL;
419
ifp = fopen (filename, "rb");
417
ifp = g_fopen (filename, "rb");
422
420
g_message (_("Could not open '%s' for reading: %s"),
475
temp = g_strdup_printf (_("Opening '%s'..."),
476
gimp_filename_to_utf8 (filename));
477
gimp_progress_init (temp);
473
gimp_progress_init_printf (_("Opening '%s'"),
474
gimp_filename_to_utf8 (filename));
480
476
depth = xwdhdr.l_pixmap_depth;
481
477
bpp = xwdhdr.l_bits_per_pixel;
523
519
g_free (xwdcolmap);
525
521
if (image_ID == -1)
527
temp = g_strdup_printf (_("XWD-file %s has format %d, depth %d\n"
528
"and bits per pixel %d.\n"
529
"Currently this is not supported."),
530
gimp_filename_to_utf8 (filename),
531
(gint) xwdhdr.l_pixmap_format, depth, bpp);
522
g_message (_("XWD-file %s has format %d, depth %d and bits per pixel %d. "
523
"Currently this is not supported."),
524
gimp_filename_to_utf8 (filename),
525
(gint) xwdhdr.l_pixmap_format, depth, bpp);
573
561
/* Open the output file. */
574
ofp = fopen (filename, "wb");
562
ofp = g_fopen (filename, "wb");
577
565
g_message (_("Could not open '%s' for writing: %s"),
582
temp = g_strdup_printf (_("Saving '%s'..."),
583
gimp_filename_to_utf8 (filename));
584
gimp_progress_init (temp);
570
gimp_progress_init_printf (_("Saving '%s'"),
571
gimp_filename_to_utf8 (filename));
587
573
if (drawable_type == GIMP_INDEXED_IMAGE)
588
574
retval = save_index (ofp, image_ID, drawable_ID, 0);