mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-20 11:37:14 +00:00
ExportMania !!
--Sven
This commit is contained in:
parent
1840e704c1
commit
1d60957401
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Sat Oct 9 21:03:08 *EST 1999 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/Makefile.am
|
||||
* plug-ins/common/gicon.c
|
||||
* plug-ins/common/header.c
|
||||
* plug-ins/common/hrz.c
|
||||
* plug-ins/common/pat.c
|
||||
* plug-ins/common/pcx.c
|
||||
* plug-ins/common/plugin-defs.pl: more file plug-ins that make use
|
||||
of the export functionality
|
||||
|
||||
Sat Oct 9 15:34:12 MEST 1999 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* gimprc.5.in
|
||||
|
|
|
@ -492,6 +492,7 @@ gicon_SOURCES = \
|
|||
gicon.c
|
||||
|
||||
gicon_LDADD = \
|
||||
$(top_builddir)/libgimp/libgimpui.la \
|
||||
$(top_builddir)/libgimp/libgimp.la \
|
||||
$(GTK_LIBS) \
|
||||
$(INTLLIBS)
|
||||
|
@ -583,8 +584,9 @@ header_SOURCES = \
|
|||
header.c
|
||||
|
||||
header_LDADD = \
|
||||
$(top_builddir)/libgimp/libgimpui.la \
|
||||
$(top_builddir)/libgimp/libgimp.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTK_LIBS) \
|
||||
$(INTLLIBS)
|
||||
|
||||
hot_SOURCES = \
|
||||
|
@ -600,6 +602,7 @@ hrz_SOURCES = \
|
|||
hrz.c
|
||||
|
||||
hrz_LDADD = \
|
||||
$(top_builddir)/libgimp/libgimpui.la \
|
||||
$(top_builddir)/libgimp/libgimp.la \
|
||||
$(GTK_LIBS) \
|
||||
$(INTLLIBS)
|
||||
|
@ -757,6 +760,7 @@ pat_SOURCES = \
|
|||
pat.c
|
||||
|
||||
pat_LDADD = \
|
||||
$(top_builddir)/libgimp/libgimpui.la \
|
||||
$(top_builddir)/libgimp/libgimp.la \
|
||||
$(GTK_LIBS) \
|
||||
$(INTLLIBS)
|
||||
|
@ -765,8 +769,9 @@ pcx_SOURCES = \
|
|||
pcx.c
|
||||
|
||||
pcx_LDADD = \
|
||||
$(top_builddir)/libgimp/libgimpui.la \
|
||||
$(top_builddir)/libgimp/libgimp.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTK_LIBS) \
|
||||
$(INTLLIBS)
|
||||
|
||||
pix_SOURCES = \
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <math.h>
|
||||
#include "gtk/gtk.h"
|
||||
#include "libgimp/gimp.h"
|
||||
#include "libgimp/gimpui.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
|
@ -49,17 +50,18 @@ typedef struct
|
|||
|
||||
/* Declare some local functions.
|
||||
*/
|
||||
static void query (void);
|
||||
static void run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static gint32 load_image (char *filename);
|
||||
static gint save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
static void query (void);
|
||||
static void run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static gint32 load_image (char *filename);
|
||||
static gint save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
|
||||
static void init_gtk (void);
|
||||
static gint save_dialog (void);
|
||||
|
||||
static void close_callback (GtkWidget *widget,
|
||||
|
@ -154,7 +156,9 @@ run (char *name,
|
|||
static GParam values[2];
|
||||
GRunModeType run_mode;
|
||||
gint32 image_ID;
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
gint32 drawable_ID;
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
GimpExportReturnType export = EXPORT_CANCEL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
|
@ -181,6 +185,27 @@ run (char *name,
|
|||
}
|
||||
else if (strcmp (name, "file_gicon_save") == 0)
|
||||
{
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
/* eventually export the image */
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
case RUN_WITH_LAST_VALS:
|
||||
init_gtk ();
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "GIcon",
|
||||
(CAN_HANDLE_GRAY | CAN_HANDLE_ALPHA));
|
||||
if (export == EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
|
@ -209,9 +234,8 @@ run (char *name,
|
|||
break;
|
||||
}
|
||||
|
||||
if (save_image (param[3].data.d_string,
|
||||
param[1].data.d_int32,
|
||||
param[2].data.d_int32))
|
||||
*nreturn_vals = 1;
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
{
|
||||
/* Store persistent data */
|
||||
gimp_set_data ("file_gicon_save", &givals, sizeof (GIconSaveVals));
|
||||
|
@ -220,7 +244,9 @@ run (char *name,
|
|||
}
|
||||
else
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
*nreturn_vals = 1;
|
||||
|
||||
if (export == EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -378,24 +404,28 @@ save_image (char *filename,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
init_gtk ()
|
||||
{
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("gicon");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
}
|
||||
|
||||
static gint
|
||||
save_dialog()
|
||||
save_dialog ()
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *button;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *table;
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new(gchar *, 1);
|
||||
argv[0] = g_strdup("gicon");
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
|
||||
dlg = gtk_dialog_new();
|
||||
gtk_window_set_title(GTK_WINDOW(dlg), "Save As GIcon");
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "gtk/gtk.h"
|
||||
#include "libgimp/gimp.h"
|
||||
#include "libgimp/gimpui.h"
|
||||
|
||||
/* Declare some local functions.
|
||||
*/
|
||||
|
@ -11,6 +13,7 @@ static void run (char *name,
|
|||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static void init_gtk (void);
|
||||
static int save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
|
@ -18,10 +21,10 @@ static int save_image (char *filename,
|
|||
|
||||
GPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
query, /* query_proc */
|
||||
run, /* run_proc */
|
||||
run, /* run_proc */
|
||||
};
|
||||
|
||||
|
||||
|
@ -47,7 +50,7 @@ query ()
|
|||
"Spencer Kimball & Peter Mattis",
|
||||
"1997",
|
||||
"<Save>/Header",
|
||||
"INDEXED*, RGB*",
|
||||
"INDEXED, RGB",
|
||||
PROC_PLUG_IN,
|
||||
nsave_args, 0,
|
||||
save_args, NULL);
|
||||
|
@ -64,6 +67,9 @@ run (char *name,
|
|||
{
|
||||
static GParam values[2];
|
||||
GRunModeType run_mode;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturnType export = EXPORT_CANCEL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
|
@ -75,13 +81,51 @@ run (char *name,
|
|||
if (strcmp (name, "file_header_save") == 0)
|
||||
{
|
||||
*nreturn_vals = 1;
|
||||
if (save_image (param[3].data.d_string, param[1].data.d_int32, param[2].data.d_int32))
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
/* eventually export the image */
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
case RUN_WITH_LAST_VALS:
|
||||
init_gtk ();
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "Header",
|
||||
(CAN_HANDLE_RGB | CAN_HANDLE_INDEXED));
|
||||
if (export == EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
else
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
|
||||
if (export == EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_gtk ()
|
||||
{
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("header");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
}
|
||||
|
||||
static int
|
||||
save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
|
@ -96,7 +140,7 @@ save_image (char *filename,
|
|||
gchar *quote = "\\\"";
|
||||
gchar *newline = "\"\n\t\"";
|
||||
gchar buf[4];
|
||||
guchar *d;
|
||||
guchar *d = NULL;
|
||||
guchar *data;
|
||||
unsigned char *cmap;
|
||||
int colors;
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
|
||||
#include "gtk/gtk.h"
|
||||
#include "libgimp/gimp.h"
|
||||
#include "libgimp/gimpui.h"
|
||||
|
||||
|
||||
/* Declare local data types
|
||||
|
@ -75,18 +76,19 @@ typedef struct
|
|||
|
||||
/* Declare some local functions.
|
||||
*/
|
||||
static void query (void);
|
||||
static void run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static gint32 load_image (char *filename);
|
||||
static gint save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
static void query (void);
|
||||
static void run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static gint32 load_image (char *filename);
|
||||
static gint save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
|
||||
static gint save_dialog ();
|
||||
static void init_gtk (void);
|
||||
static gint save_dialog (void);
|
||||
|
||||
static void save_close_callback (GtkWidget *widget, gpointer data);
|
||||
static void save_ok_callback (GtkWidget *widget,
|
||||
|
@ -166,7 +168,7 @@ query ()
|
|||
"Albert Cahalan",
|
||||
"1997",
|
||||
"<Save>/HRZ",
|
||||
"RGB*, GRAY*, INDEXED*",
|
||||
"RGB, GRAY",
|
||||
PROC_PLUG_IN,
|
||||
nsave_args, 0,
|
||||
save_args, NULL);
|
||||
|
@ -186,6 +188,8 @@ run (char *name,
|
|||
GRunModeType run_mode;
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturnType export = EXPORT_CANCEL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
|
@ -212,6 +216,27 @@ run (char *name,
|
|||
}
|
||||
else if (strcmp (name, "file_hrz_save") == 0)
|
||||
{
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
/* eventually export the image */
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
case RUN_WITH_LAST_VALS:
|
||||
init_gtk ();
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "HRZ",
|
||||
(CAN_HANDLE_RGB | CAN_HANDLE_GRAY));
|
||||
if (export == EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
|
@ -234,12 +259,15 @@ run (char *name,
|
|||
}
|
||||
|
||||
*nreturn_vals = 1;
|
||||
if (save_image (param[3].data.d_string, param[1].data.d_int32, param[2].data.d_int32))
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
{
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
|
||||
if (export == EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,21 +493,27 @@ save_image (char *filename,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
init_gtk ()
|
||||
{
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("hrz");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
}
|
||||
|
||||
/*********** Save dialog ************/
|
||||
static gint
|
||||
save_dialog ()
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *button;
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("save");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
|
||||
dlg = gtk_dialog_new ();
|
||||
gtk_window_set_title (GTK_WINDOW (dlg), "Save as HRZ");
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libgimp/gimp.h>
|
||||
#include <libgimp/gimpui.h>
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include <io.h>
|
||||
|
@ -51,10 +52,11 @@ static gint save_image (char *filename,
|
|||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
|
||||
static gint save_dialog ();
|
||||
static void close_callback(GtkWidget * widget, gpointer data);
|
||||
static void ok_callback(GtkWidget * widget, gpointer data);
|
||||
static void entry_callback(GtkWidget * widget, gpointer data);
|
||||
static void init_gtk (void);
|
||||
static gint save_dialog (void);
|
||||
static void close_callback (GtkWidget * widget, gpointer data);
|
||||
static void ok_callback (GtkWidget * widget, gpointer data);
|
||||
static void entry_callback (GtkWidget * widget, gpointer data);
|
||||
|
||||
GPlugInInfo PLUG_IN_INFO =
|
||||
{
|
||||
|
@ -132,7 +134,9 @@ run (char *name,
|
|||
static GParam values[2];
|
||||
GRunModeType run_mode;
|
||||
gint32 image_ID;
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturnType export = EXPORT_CANCEL;
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
|
@ -142,281 +146,334 @@ run (char *name,
|
|||
values[1].type = PARAM_IMAGE;
|
||||
values[1].data.d_image = -1;
|
||||
|
||||
if (strcmp (name, "file_pat_load") == 0) {
|
||||
image_ID = load_image (param[1].data.d_string);
|
||||
|
||||
if (image_ID != -1) {
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
values[1].data.d_image = image_ID;
|
||||
} else {
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
}
|
||||
*nreturn_vals = 2;
|
||||
if (strcmp (name, "file_pat_load") == 0)
|
||||
{
|
||||
image_ID = load_image (param[1].data.d_string);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
values[1].data.d_image = image_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
}
|
||||
else if (strcmp (name, "file_pat_save") == 0) {
|
||||
switch (run_mode) {
|
||||
case RUN_INTERACTIVE:
|
||||
/* Possibly retrieve data */
|
||||
gimp_get_data("file_pat_save", description);
|
||||
if (!save_dialog())
|
||||
return;
|
||||
break;
|
||||
case RUN_NONINTERACTIVE:
|
||||
if (nparams != 6)
|
||||
status = STATUS_CALLING_ERROR;
|
||||
else
|
||||
strcpy(description, param[5].data.d_string);
|
||||
case RUN_WITH_LAST_VALS:
|
||||
gimp_get_data ("file_pat_save", description);
|
||||
break;
|
||||
}
|
||||
*nreturn_vals = 2;
|
||||
}
|
||||
else if (strcmp (name, "file_pat_save") == 0)
|
||||
{
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
if (save_image (param[3].data.d_string, param[1].data.d_int32,
|
||||
param[2].data.d_int32)) {
|
||||
gimp_set_data ("file_pat_save", description, 256);
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
} else
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
*nreturn_vals = 1;
|
||||
/* eventually export the image */
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
case RUN_WITH_LAST_VALS:
|
||||
init_gtk ();
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "PAT",
|
||||
(CAN_HANDLE_RGB | CAN_HANDLE_GRAY | CAN_HANDLE_ALPHA));
|
||||
if (export == EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
/* Possibly retrieve data */
|
||||
gimp_get_data("file_pat_save", description);
|
||||
if (!save_dialog())
|
||||
return;
|
||||
break;
|
||||
case RUN_NONINTERACTIVE:
|
||||
if (nparams != 6)
|
||||
status = STATUS_CALLING_ERROR;
|
||||
else
|
||||
strcpy(description, param[5].data.d_string);
|
||||
case RUN_WITH_LAST_VALS:
|
||||
gimp_get_data ("file_pat_save", description);
|
||||
break;
|
||||
}
|
||||
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
{
|
||||
gimp_set_data ("file_pat_save", description, 256);
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
|
||||
*nreturn_vals = 1;
|
||||
|
||||
if (export == EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
}
|
||||
|
||||
static gint32 load_image (char *filename) {
|
||||
char *temp;
|
||||
int fd;
|
||||
PatternHeader ph;
|
||||
guchar *buffer;
|
||||
gint32 image_ID, layer_ID;
|
||||
GDrawable *drawable;
|
||||
gint line;
|
||||
GPixelRgn pixel_rgn;
|
||||
static gint32
|
||||
load_image (char *filename)
|
||||
{
|
||||
char *temp;
|
||||
int fd;
|
||||
PatternHeader ph;
|
||||
guchar *buffer;
|
||||
gint32 image_ID, layer_ID;
|
||||
GDrawable *drawable;
|
||||
gint line;
|
||||
GPixelRgn pixel_rgn;
|
||||
|
||||
temp = g_malloc(strlen (filename) + 11);
|
||||
sprintf(temp, "Loading %s:", filename);
|
||||
gimp_progress_init(temp);
|
||||
g_free (temp);
|
||||
temp = g_malloc (strlen (filename) + 11);
|
||||
sprintf (temp, "Loading %s:", filename);
|
||||
gimp_progress_init (temp);
|
||||
g_free (temp);
|
||||
|
||||
fd = open (filename, O_RDONLY | _O_BINARY);
|
||||
|
||||
fd = open(filename, O_RDONLY | _O_BINARY);
|
||||
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (read(fd, &ph, sizeof(ph)) != sizeof(ph)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
if (read(fd, &ph, sizeof(ph)) != sizeof(ph))
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* rearrange the bytes in each unsigned int */
|
||||
ph.header_size = g_ntohl(ph.header_size);
|
||||
ph.version = g_ntohl(ph.version);
|
||||
ph.width = g_ntohl(ph.width);
|
||||
ph.height = g_ntohl(ph.height);
|
||||
ph.bytes = g_ntohl(ph.bytes);
|
||||
ph.magic_number = g_ntohl(ph.magic_number);
|
||||
ph.header_size = g_ntohl (ph.header_size);
|
||||
ph.version = g_ntohl (ph.version);
|
||||
ph.width = g_ntohl (ph.width);
|
||||
ph.height = g_ntohl (ph.height);
|
||||
ph.bytes = g_ntohl (ph.bytes);
|
||||
ph.magic_number = g_ntohl (ph.magic_number);
|
||||
|
||||
if (ph.magic_number != GPATTERN_MAGIC || ph.version != 1 ||
|
||||
ph.header_size <= sizeof(ph)) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lseek(fd, ph.header_size - sizeof(ph), SEEK_CUR) !=
|
||||
ph.header_size) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Now there's just raw data left. */
|
||||
if (ph.magic_number != GPATTERN_MAGIC || ph.version != 1 || ph.header_size <= sizeof(ph))
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lseek(fd, ph.header_size - sizeof(ph), SEEK_CUR) != ph.header_size)
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Now there's just raw data left. */
|
||||
|
||||
/*
|
||||
* Create a new image of the proper size and associate the filename with it.
|
||||
* Create a new image of the proper size and associate the filename with it.
|
||||
*/
|
||||
image_ID = gimp_image_new(ph.width, ph.height, (ph.bytes >= 3) ? RGB : GRAY);
|
||||
gimp_image_set_filename(image_ID, filename);
|
||||
|
||||
|
||||
layer_ID = gimp_layer_new(image_ID, "Background", ph.width, ph.height,
|
||||
(ph.bytes >= 3) ? RGB_IMAGE : GRAY_IMAGE, 100, NORMAL_MODE);
|
||||
gimp_image_add_layer(image_ID, layer_ID, 0);
|
||||
|
||||
(ph.bytes >= 3) ? RGB_IMAGE : GRAY_IMAGE, 100, NORMAL_MODE);
|
||||
gimp_image_add_layer(image_ID, layer_ID, 0);
|
||||
|
||||
drawable = gimp_drawable_get(layer_ID);
|
||||
gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width,
|
||||
drawable->height, TRUE, FALSE);
|
||||
|
||||
buffer = g_malloc(ph.width * ph.bytes);
|
||||
|
||||
for (line = 0; line < ph.height; line++) {
|
||||
if (read(fd, buffer, ph.width * ph.bytes) != ph.width * ph.bytes) {
|
||||
close(fd);
|
||||
g_free(buffer);
|
||||
return -1;
|
||||
}
|
||||
gimp_pixel_rgn_set_row(&pixel_rgn, buffer, 0, line, ph.width);
|
||||
gimp_progress_update((double) line / (double) ph.height);
|
||||
}
|
||||
|
||||
gimp_drawable_flush(drawable);
|
||||
|
||||
return image_ID;
|
||||
}
|
||||
|
||||
static gint save_image (char *filename, gint32 image_ID, gint32 drawable_ID) {
|
||||
int fd;
|
||||
PatternHeader ph;
|
||||
unsigned char *buffer;
|
||||
GDrawable *drawable;
|
||||
gint line;
|
||||
GPixelRgn pixel_rgn;
|
||||
char *temp;
|
||||
|
||||
temp = g_malloc(strlen (filename) + 10);
|
||||
sprintf(temp, "Saving %s:", filename);
|
||||
gimp_progress_init(temp);
|
||||
g_free(temp);
|
||||
|
||||
drawable = gimp_drawable_get(drawable_ID);
|
||||
gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width,
|
||||
drawable->height, FALSE, FALSE);
|
||||
|
||||
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | _O_BINARY, 0644);
|
||||
|
||||
if (fd == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ph.header_size = g_htonl(sizeof(ph) + strlen(description) + 1);
|
||||
ph.version = g_htonl(1);
|
||||
ph.width = g_htonl(drawable->width);
|
||||
ph.height = g_htonl(drawable->height);
|
||||
ph.bytes = g_htonl(drawable->bpp);
|
||||
ph.magic_number = g_htonl(GPATTERN_MAGIC);
|
||||
|
||||
if (write(fd, &ph, sizeof(ph)) != sizeof(ph)) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (write(fd, description, strlen(description) + 1) !=
|
||||
strlen(description) + 1) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer = g_malloc(drawable->width * drawable->bpp);
|
||||
if (buffer == NULL) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
for (line = 0; line < drawable->height; line++) {
|
||||
gimp_pixel_rgn_get_row(&pixel_rgn, buffer, 0, line, drawable->width);
|
||||
if (write(fd, buffer, drawable->width * drawable->bpp) !=
|
||||
drawable->width * drawable->bpp) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
gimp_progress_update((double) line / (double) drawable->height);
|
||||
}
|
||||
g_free(buffer);
|
||||
|
||||
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height,
|
||||
TRUE, FALSE);
|
||||
|
||||
buffer = g_malloc(ph.width * ph.bytes);
|
||||
|
||||
for (line = 0; line < ph.height; line++)
|
||||
{
|
||||
if (read(fd, buffer, ph.width * ph.bytes) != ph.width * ph.bytes) {
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
g_free(buffer);
|
||||
return -1;
|
||||
}
|
||||
gimp_pixel_rgn_set_row (&pixel_rgn, buffer, 0, line, ph.width);
|
||||
gimp_progress_update ((double) line / (double) ph.height);
|
||||
}
|
||||
|
||||
gimp_drawable_flush (drawable);
|
||||
|
||||
return image_ID;
|
||||
}
|
||||
|
||||
|
||||
static gint save_dialog()
|
||||
static gint
|
||||
save_image (char *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID)
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *button;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *table;
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
int fd;
|
||||
PatternHeader ph;
|
||||
unsigned char *buffer;
|
||||
GDrawable *drawable;
|
||||
gint line;
|
||||
GPixelRgn pixel_rgn;
|
||||
char *temp;
|
||||
|
||||
temp = g_malloc (strlen (filename) + 10);
|
||||
sprintf(temp, "Saving %s:", filename);
|
||||
gimp_progress_init (temp);
|
||||
g_free (temp);
|
||||
|
||||
drawable = gimp_drawable_get (drawable_ID);
|
||||
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width,
|
||||
drawable->height, FALSE, FALSE);
|
||||
|
||||
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | _O_BINARY, 0644);
|
||||
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new(gchar *, 1);
|
||||
argv[0] = g_strdup("plasma");
|
||||
ph.header_size = g_htonl (sizeof (ph) + strlen (description) + 1);
|
||||
ph.version = g_htonl (1);
|
||||
ph.width = g_htonl (drawable->width);
|
||||
ph.height = g_htonl (drawable->height);
|
||||
ph.bytes = g_htonl (drawable->bpp);
|
||||
ph.magic_number = g_htonl (GPATTERN_MAGIC);
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
if (write(fd, &ph, sizeof (ph)) != sizeof(ph))
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dlg = gtk_dialog_new();
|
||||
gtk_window_set_title(GTK_WINDOW(dlg), "Save As Pattern");
|
||||
gtk_window_position(GTK_WINDOW(dlg), GTK_WIN_POS_MOUSE);
|
||||
gtk_signal_connect(GTK_OBJECT(dlg), "destroy",
|
||||
(GtkSignalFunc) close_callback, NULL);
|
||||
if (write (fd, description, strlen (description) + 1) != strlen (description) + 1)
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Action area */
|
||||
button = gtk_button_new_with_label("OK");
|
||||
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
||||
gtk_signal_connect(GTK_OBJECT(button), "clicked",
|
||||
(GtkSignalFunc) ok_callback,
|
||||
dlg);
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, TRUE, TRUE, 0);
|
||||
gtk_widget_grab_default(button);
|
||||
gtk_widget_show(button);
|
||||
|
||||
button = gtk_button_new_with_label("Cancel");
|
||||
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
||||
gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
|
||||
(GtkSignalFunc) gtk_widget_destroy,
|
||||
GTK_OBJECT(dlg));
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, TRUE, TRUE, 0);
|
||||
gtk_widget_show(button);
|
||||
|
||||
/* The main table */
|
||||
/* Set its size (y, x) */
|
||||
table = gtk_table_new(1, 2, FALSE);
|
||||
gtk_container_border_width(GTK_CONTAINER(table), 10);
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), table, TRUE, TRUE, 0);
|
||||
gtk_widget_show(table);
|
||||
|
||||
gtk_table_set_row_spacings(GTK_TABLE(table), 10);
|
||||
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
|
||||
|
||||
/**********************
|
||||
* label
|
||||
**********************/
|
||||
label = gtk_label_new("Description:");
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0,
|
||||
0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
/************************
|
||||
* The entry
|
||||
************************/
|
||||
entry = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL,
|
||||
GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
gtk_widget_set_usize(entry, 200, 0);
|
||||
gtk_entry_set_text(GTK_ENTRY(entry), description);
|
||||
gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
||||
(GtkSignalFunc) entry_callback, description);
|
||||
gtk_widget_show(entry);
|
||||
|
||||
gtk_widget_show(dlg);
|
||||
|
||||
gtk_main();
|
||||
gdk_flush();
|
||||
|
||||
return run_flag;
|
||||
buffer = g_malloc (drawable->width * drawable->bpp);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (line = 0; line < drawable->height; line++)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&pixel_rgn, buffer, 0, line, drawable->width);
|
||||
if (write (fd, buffer, drawable->width * drawable->bpp) !=
|
||||
drawable->width * drawable->bpp)
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
gimp_progress_update ((double) line / (double) drawable->height);
|
||||
}
|
||||
|
||||
g_free (buffer);
|
||||
close (fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void close_callback(GtkWidget * widget, gpointer data)
|
||||
static void
|
||||
init_gtk ()
|
||||
{
|
||||
gtk_main_quit();
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("pat");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
}
|
||||
|
||||
static void ok_callback(GtkWidget * widget, gpointer data)
|
||||
static gint
|
||||
save_dialog ()
|
||||
{
|
||||
run_flag = 1;
|
||||
gtk_widget_destroy(GTK_WIDGET(data));
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *button;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *table;
|
||||
|
||||
dlg = gtk_dialog_new();
|
||||
gtk_window_set_title(GTK_WINDOW(dlg), "Save As Pattern");
|
||||
gtk_window_position(GTK_WINDOW(dlg), GTK_WIN_POS_MOUSE);
|
||||
gtk_signal_connect(GTK_OBJECT(dlg), "destroy",
|
||||
(GtkSignalFunc) close_callback, NULL);
|
||||
|
||||
/* Action area */
|
||||
button = gtk_button_new_with_label("OK");
|
||||
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
||||
gtk_signal_connect(GTK_OBJECT(button), "clicked",
|
||||
(GtkSignalFunc) ok_callback,
|
||||
dlg);
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, TRUE, TRUE, 0);
|
||||
gtk_widget_grab_default(button);
|
||||
gtk_widget_show(button);
|
||||
|
||||
button = gtk_button_new_with_label("Cancel");
|
||||
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
|
||||
gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
|
||||
(GtkSignalFunc) gtk_widget_destroy,
|
||||
GTK_OBJECT(dlg));
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, TRUE, TRUE, 0);
|
||||
gtk_widget_show(button);
|
||||
|
||||
/* The main table */
|
||||
/* Set its size (y, x) */
|
||||
table = gtk_table_new(1, 2, FALSE);
|
||||
gtk_container_border_width(GTK_CONTAINER(table), 10);
|
||||
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), table, TRUE, TRUE, 0);
|
||||
gtk_widget_show(table);
|
||||
|
||||
gtk_table_set_row_spacings(GTK_TABLE(table), 10);
|
||||
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
|
||||
|
||||
/**********************
|
||||
* label
|
||||
**********************/
|
||||
label = gtk_label_new("Description:");
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
/************************
|
||||
* The entry
|
||||
************************/
|
||||
entry = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL,
|
||||
GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
gtk_widget_set_usize(entry, 200, 0);
|
||||
gtk_entry_set_text(GTK_ENTRY(entry), description);
|
||||
gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
||||
(GtkSignalFunc) entry_callback, description);
|
||||
gtk_widget_show(entry);
|
||||
|
||||
gtk_widget_show(dlg);
|
||||
|
||||
gtk_main();
|
||||
gdk_flush();
|
||||
|
||||
return run_flag;
|
||||
}
|
||||
|
||||
static void entry_callback(GtkWidget * widget, gpointer data)
|
||||
static void
|
||||
close_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
if (data == description)
|
||||
strncpy(description, gtk_entry_get_text(GTK_ENTRY(widget)), 256);
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
ok_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
run_flag = 1;
|
||||
gtk_widget_destroy(GTK_WIDGET(data));
|
||||
}
|
||||
|
||||
static void
|
||||
entry_callback (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
if (data == description)
|
||||
strncpy(description, gtk_entry_get_text(GTK_ENTRY(widget)), 256);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gtk/gtk.h"
|
||||
#include "libgimp/gimp.h"
|
||||
#include "libgimp/gimpui.h"
|
||||
|
||||
/* Declare plug-in functions. */
|
||||
|
||||
static void query (void);
|
||||
static void run (char *name, int nparams, GParam *param, int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
static void run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals);
|
||||
|
||||
#if defined(_BIG_ENDIAN) || defined(sparc) || defined (__sgi)
|
||||
#define qtohl(x) \
|
||||
|
@ -100,26 +105,35 @@ static void query () {
|
|||
|
||||
/* Declare internal functions. */
|
||||
|
||||
static gint32 load_image (char *filename);
|
||||
static void load_1(FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_4(FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_8(FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_24(FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void readline(FILE *fp, guchar* buffer, int bytes);
|
||||
static void init_gtk (void);
|
||||
|
||||
static gint save_image (char *filename, gint32 image, gint32 layer);
|
||||
static void save_8(FILE *fp, int width, int height, guchar *buffer);
|
||||
static void save_24(FILE *fp, int width, int height, guchar *buffer);
|
||||
static void writeline(FILE *fp, guchar *buffer, int bytes);
|
||||
static gint32 load_image (char *filename);
|
||||
static void load_1 (FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_4 (FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_8 (FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void load_24 (FILE *fp, int width, int height, char *buffer, int bytes);
|
||||
static void readline (FILE *fp, guchar* buffer, int bytes);
|
||||
|
||||
static gint save_image (char *filename, gint32 image, gint32 layer);
|
||||
static void save_8 (FILE *fp, int width, int height, guchar *buffer);
|
||||
static void save_24 (FILE *fp, int width, int height, guchar *buffer);
|
||||
static void writeline (FILE *fp, guchar *buffer, int bytes);
|
||||
|
||||
/* Plug-in implementation */
|
||||
|
||||
static void run (char *name, int nparams, GParam *param, int *nreturn_vals,
|
||||
GParam **return_vals) {
|
||||
static void
|
||||
run (char *name,
|
||||
int nparams,
|
||||
GParam *param,
|
||||
int *nreturn_vals,
|
||||
GParam **return_vals)
|
||||
{
|
||||
static GParam values[2];
|
||||
GStatusType status = STATUS_SUCCESS;
|
||||
GRunModeType run_mode;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturnType export = EXPORT_CANCEL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
|
@ -142,6 +156,27 @@ static void run (char *name, int nparams, GParam *param, int *nreturn_vals,
|
|||
}
|
||||
else if (strcmp (name, "file_pcx_save") == 0)
|
||||
{
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
/* eventually export the image */
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
case RUN_WITH_LAST_VALS:
|
||||
init_gtk ();
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "PCX",
|
||||
(CAN_HANDLE_RGB | CAN_HANDLE_GRAY | CAN_HANDLE_INDEXED));
|
||||
if (export == EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case RUN_INTERACTIVE:
|
||||
|
@ -160,15 +195,34 @@ static void run (char *name, int nparams, GParam *param, int *nreturn_vals,
|
|||
}
|
||||
|
||||
*nreturn_vals = 1;
|
||||
if (save_image (param[3].data.d_string, param[1].data.d_int32,
|
||||
param[2].data.d_int32)) {
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
} else {
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
}
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
{
|
||||
values[0].data.d_status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
values[0].data.d_status = STATUS_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
if (export == EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_gtk ()
|
||||
{
|
||||
gchar **argv;
|
||||
gint argc;
|
||||
|
||||
argc = 1;
|
||||
argv = g_new (gchar *, 1);
|
||||
argv[0] = g_strdup ("pcx");
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
gtk_rc_parse (gimp_gtkrc ());
|
||||
}
|
||||
|
||||
guchar mono[6]= {0, 0, 0, 255, 255, 255};
|
||||
|
||||
static struct {
|
||||
|
@ -188,7 +242,9 @@ static struct {
|
|||
guint8 filler[58];
|
||||
} pcx_header;
|
||||
|
||||
static gint32 load_image (char *filename) {
|
||||
static gint32
|
||||
load_image (char *filename)
|
||||
{
|
||||
FILE *fd;
|
||||
GDrawable *drawable;
|
||||
GPixelRgn pixel_rgn;
|
||||
|
@ -270,100 +326,149 @@ static gint32 load_image (char *filename) {
|
|||
return image;
|
||||
}
|
||||
|
||||
static void load_8(FILE *fp, int width, int height, char *buffer, int bytes) {
|
||||
static void
|
||||
load_8 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
char *buffer,
|
||||
int bytes)
|
||||
{
|
||||
int row;
|
||||
guchar *line;
|
||||
line= (guchar *) g_malloc(bytes);
|
||||
|
||||
for (row= 0; row < height; buffer+= width, ++row) {
|
||||
readline(fp, line, bytes);
|
||||
memcpy(buffer, line, width);
|
||||
gimp_progress_update ((double) row / (double) height);
|
||||
}
|
||||
for (row= 0; row < height; buffer+= width, ++row)
|
||||
{
|
||||
readline(fp, line, bytes);
|
||||
memcpy(buffer, line, width);
|
||||
gimp_progress_update ((double) row / (double) height);
|
||||
}
|
||||
|
||||
g_free(line);
|
||||
}
|
||||
|
||||
static void load_24(FILE *fp, int width, int height, char *buffer, int bytes) {
|
||||
static void
|
||||
load_24 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
char *buffer,
|
||||
int bytes)
|
||||
{
|
||||
int x, y, c;
|
||||
guchar *line;
|
||||
line= (guchar *) g_malloc(bytes * 3);
|
||||
|
||||
for (y= 0; y < height; buffer+= width * 3, ++y) {
|
||||
for (c= 0; c < 3; ++c) {
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x) {
|
||||
buffer[x * 3 + c]= line[x];
|
||||
}
|
||||
for (y= 0; y < height; buffer+= width * 3, ++y)
|
||||
{
|
||||
for (c= 0; c < 3; ++c)
|
||||
{
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x)
|
||||
{
|
||||
buffer[x * 3 + c]= line[x];
|
||||
}
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
|
||||
|
||||
g_free(line);
|
||||
}
|
||||
|
||||
static void load_1(FILE *fp, int width, int height, char *buffer, int bytes) {
|
||||
static void
|
||||
load_1 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
char *buffer,
|
||||
int bytes)
|
||||
{
|
||||
int x, y;
|
||||
guchar *line;
|
||||
line= (guchar *) g_malloc(bytes);
|
||||
|
||||
for (y= 0; y < height; buffer+= width, ++y) {
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x) {
|
||||
if (line[x / 8] & (128 >> (x % 8)))
|
||||
buffer[x]= 1;
|
||||
else
|
||||
buffer[x]= 0;
|
||||
for (y= 0; y < height; buffer+= width, ++y)
|
||||
{
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x)
|
||||
{
|
||||
if (line[x / 8] & (128 >> (x % 8)))
|
||||
buffer[x]= 1;
|
||||
else
|
||||
buffer[x]= 0;
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
|
||||
|
||||
g_free(line);
|
||||
}
|
||||
|
||||
static void load_4(FILE *fp, int width, int height, char *buffer, int bytes) {
|
||||
static void
|
||||
load_4 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
char *buffer,
|
||||
int bytes)
|
||||
{
|
||||
int x, y, c;
|
||||
guchar *line;
|
||||
line= (guchar *) g_malloc(bytes);
|
||||
|
||||
for (y= 0; y < height; buffer+= width, ++y) {
|
||||
for (x= 0; x < width; ++x) buffer[x]= 0;
|
||||
for (c= 0; c < 4; ++c) {
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x) {
|
||||
if (line[x / 8] & (128 >> (x % 8)))
|
||||
buffer[x]+= (1 << c);
|
||||
}
|
||||
for (y= 0; y < height; buffer+= width, ++y)
|
||||
{
|
||||
for (x= 0; x < width; ++x) buffer[x]= 0;
|
||||
for (c= 0; c < 4; ++c)
|
||||
{
|
||||
readline(fp, line, bytes);
|
||||
for (x= 0; x < width; ++x)
|
||||
{
|
||||
if (line[x / 8] & (128 >> (x % 8)))
|
||||
buffer[x]+= (1 << c);
|
||||
}
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
gimp_progress_update ((double) y / (double) height);
|
||||
}
|
||||
|
||||
g_free(line);
|
||||
}
|
||||
|
||||
static void readline(FILE *fp, guchar *buffer, int bytes) {
|
||||
static void
|
||||
readline (FILE *fp,
|
||||
guchar *buffer,
|
||||
int bytes)
|
||||
{
|
||||
static guchar count= 0, value= 0;
|
||||
|
||||
if (pcx_header.compression) {
|
||||
while (bytes--) {
|
||||
if (count == 0) {
|
||||
value= fgetc(fp);
|
||||
if (value < 0xc0) {
|
||||
count= 1;
|
||||
} else {
|
||||
count= value - 0xc0;
|
||||
value= fgetc(fp);
|
||||
}
|
||||
}
|
||||
count--;
|
||||
*(buffer++)= value;
|
||||
if (pcx_header.compression)
|
||||
{
|
||||
while (bytes--)
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
value= fgetc(fp);
|
||||
if (value < 0xc0)
|
||||
{
|
||||
count= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
count= value - 0xc0;
|
||||
value= fgetc(fp);
|
||||
}
|
||||
}
|
||||
count--;
|
||||
*(buffer++)= value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fread(buffer, bytes, 1, fp);
|
||||
}
|
||||
} else {
|
||||
fread(buffer, bytes, 1, fp);
|
||||
}
|
||||
}
|
||||
|
||||
gint save_image (char *filename, gint32 image, gint32 layer) {
|
||||
static gint
|
||||
save_image (char *filename,
|
||||
gint32 image,
|
||||
gint32 layer)
|
||||
{
|
||||
FILE *fp;
|
||||
GPixelRgn pixel_rgn;
|
||||
GDrawable *drawable;
|
||||
|
@ -389,7 +494,8 @@ gint save_image (char *filename, gint32 image, gint32 layer) {
|
|||
pcx_header.version = 5;
|
||||
pcx_header.compression = 1;
|
||||
|
||||
switch(drawable_type) {
|
||||
switch(drawable_type)
|
||||
{
|
||||
case INDEXED_IMAGE:
|
||||
cmap= gimp_image_get_cmap(image, &colors);
|
||||
pcx_header.bpp = 8;
|
||||
|
@ -418,10 +524,11 @@ gint save_image (char *filename, gint32 image, gint32 layer) {
|
|||
break;
|
||||
}
|
||||
|
||||
if ((fp = fopen(filename, "wb")) == NULL) {
|
||||
g_message("PCX Can't open \n%s", filename);
|
||||
return -1;
|
||||
}
|
||||
if ((fp = fopen(filename, "wb")) == NULL)
|
||||
{
|
||||
g_message("PCX Can't open \n%s", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pixels= (guchar *) g_malloc(width * height * pcx_header.planes);
|
||||
gimp_pixel_rgn_get_rect(&pixel_rgn, pixels, 0, 0, width, height);
|
||||
|
@ -437,14 +544,16 @@ gint save_image (char *filename, gint32 image, gint32 layer) {
|
|||
|
||||
fwrite(&pcx_header, 128, 1, fp);
|
||||
|
||||
switch(drawable_type) {
|
||||
switch(drawable_type)
|
||||
{
|
||||
case INDEXED_IMAGE:
|
||||
save_8(fp, width, height, pixels);
|
||||
fputc(0x0c, fp);
|
||||
fwrite(cmap, colors, 3, fp);
|
||||
for (i= colors; i < 256; i++) {
|
||||
fputc(0, fp); fputc(0, fp); fputc(0, fp);
|
||||
}
|
||||
for (i= colors; i < 256; i++)
|
||||
{
|
||||
fputc(0, fp); fputc(0, fp); fputc(0, fp);
|
||||
}
|
||||
break;
|
||||
case RGB_IMAGE:
|
||||
save_24(fp, width, height, pixels);
|
||||
|
@ -452,9 +561,10 @@ gint save_image (char *filename, gint32 image, gint32 layer) {
|
|||
case GRAY_IMAGE:
|
||||
save_8(fp, width, height, pixels);
|
||||
fputc(0x0c, fp);
|
||||
for (i= 0; i < 256; i++) {
|
||||
fputc((guchar) i, fp); fputc((guchar) i, fp); fputc((guchar) i, fp);
|
||||
}
|
||||
for (i= 0; i < 256; i++)
|
||||
{
|
||||
fputc((guchar) i, fp); fputc((guchar) i, fp); fputc((guchar) i, fp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_message("Can't save this image as PCX\nFlatten your image");
|
||||
|
@ -469,51 +579,74 @@ gint save_image (char *filename, gint32 image, gint32 layer) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void save_8(FILE *fp, int width, int height, guchar *buffer) {
|
||||
static void
|
||||
save_8 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
guchar *buffer)
|
||||
{
|
||||
int row;
|
||||
|
||||
for (row= 0; row < height; ++row) {
|
||||
writeline(fp, buffer, width);
|
||||
buffer+= width;
|
||||
gimp_progress_update((double) row / (double) height);
|
||||
}
|
||||
for (row= 0; row < height; ++row)
|
||||
{
|
||||
writeline(fp, buffer, width);
|
||||
buffer+= width;
|
||||
gimp_progress_update((double) row / (double) height);
|
||||
}
|
||||
}
|
||||
|
||||
static void save_24(FILE *fp, int width, int height, guchar *buffer) {
|
||||
static void
|
||||
save_24 (FILE *fp,
|
||||
int width,
|
||||
int height,
|
||||
guchar *buffer)
|
||||
{
|
||||
int x, y, c;
|
||||
guchar *line;
|
||||
line= (guchar *) g_malloc(width);
|
||||
|
||||
for (y= 0; y < height; ++y) {
|
||||
for (c= 0; c < 3; ++c) {
|
||||
for (x= 0; x < width; ++x) {
|
||||
line[x]= buffer[(3*x) + c];
|
||||
}
|
||||
writeline(fp, line, width);
|
||||
}
|
||||
buffer+= width * 3;
|
||||
for (y= 0; y < height; ++y)
|
||||
{
|
||||
for (c= 0; c < 3; ++c)
|
||||
{
|
||||
for (x= 0; x < width; ++x)
|
||||
{
|
||||
line[x]= buffer[(3*x) + c];
|
||||
}
|
||||
writeline(fp, line, width);
|
||||
}
|
||||
buffer+= width * 3;
|
||||
gimp_progress_update((double) y / (double) height);
|
||||
}
|
||||
}
|
||||
g_free (line);
|
||||
}
|
||||
|
||||
static void writeline(FILE *fp, guchar *buffer, int bytes) {
|
||||
static void
|
||||
writeline (FILE *fp,
|
||||
guchar *buffer,
|
||||
int bytes)
|
||||
{
|
||||
guchar value, count;
|
||||
guchar *finish= buffer+ bytes;
|
||||
|
||||
while (buffer < finish) {
|
||||
value= *(buffer++);
|
||||
count= 1;
|
||||
while (buffer < finish)
|
||||
{
|
||||
value= *(buffer++);
|
||||
count= 1;
|
||||
|
||||
while (buffer < finish && count < 63 && *buffer == value)
|
||||
{
|
||||
count++; buffer++;
|
||||
}
|
||||
|
||||
while (buffer < finish && count < 63 && *buffer == value) {
|
||||
count++; buffer++;
|
||||
if (value < 0xc0 && count == 1)
|
||||
{
|
||||
fputc(value, fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputc(0xc0 + count, fp);
|
||||
fputc(value, fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (value < 0xc0 && count == 1) {
|
||||
fputc(value, fp);
|
||||
} else {
|
||||
fputc(0xc0 + count, fp);
|
||||
fputc(value, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
'gbr' => { libdep => 'gtk', ui => 1 },
|
||||
'gpb' => { libdep => 'gtk', ui => 1 },
|
||||
'gee' => { libdep => 'gtk' },
|
||||
'gicon' => { libdep => 'gtk' },
|
||||
'gicon' => { libdep => 'gtk', ui => 1 },
|
||||
'gif' => { libdep => 'gtk', ui => 1 },
|
||||
'gifload' => { libdep => 'gtk' },
|
||||
'glasstile' => { libdep => 'gtk' },
|
||||
|
@ -50,9 +50,9 @@
|
|||
'gtm' => { libdep => 'gtk' },
|
||||
'guillotine' => { libdep => 'glib' },
|
||||
'gz' => { libdep => 'glib' },
|
||||
'header' => { libdep => 'glib' },
|
||||
'header' => { libdep => 'gtk', ui => 1 },
|
||||
'hot' => { libdep => 'gtk', libsupp => 'megawidget' },
|
||||
'hrz' => { libdep => 'gtk' },
|
||||
'hrz' => { libdep => 'gtk', ui => 1 },
|
||||
'illusion' => { libdep => 'gtk' },
|
||||
'iwarp' => { libdep => 'gtk' },
|
||||
'jigsaw' => { libdep => 'gtk' },
|
||||
|
@ -71,8 +71,8 @@
|
|||
'nova' => { libdep => 'gtk' },
|
||||
'oilify' => { libdep => 'gtk' },
|
||||
'papertile' => { libdep => 'gtk' },
|
||||
'pat' => { libdep => 'gtk' },
|
||||
'pcx' => { libdep => 'glib' },
|
||||
'pat' => { libdep => 'gtk', ui => 1 },
|
||||
'pcx' => { libdep => 'gtk', ui => 1 },
|
||||
'pix' => { libdep => 'glib' },
|
||||
'pixelize' => { libdep => 'gtk' },
|
||||
'plasma' => { libdep => 'gtk' },
|
||||
|
|
Loading…
Reference in a new issue