mirror of https://github.com/GNOME/gimp.git
added new plug-in
plug-ins/animationplay/animationplay.c: fix sigsegv on close -Yosh
This commit is contained in:
parent
f73afe16f1
commit
3f2f4b5c3f
|
@ -1,3 +1,9 @@
|
||||||
|
Sun Apr 19 20:18:29 PDT 1998 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
|
* added screenshot plug-in
|
||||||
|
|
||||||
|
* plug-ins/animationplay/animationplay.c: fix sigsegv on close
|
||||||
|
|
||||||
Sun Apr 19 14:16:44 MEST 1998 Sven Neumann <sven@gimp.org>
|
Sun Apr 19 14:16:44 MEST 1998 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* app/app_procs.c: truncate labels in the splash screen if they
|
* app/app_procs.c: truncate labels in the splash screen if they
|
||||||
|
|
|
@ -441,6 +441,7 @@ plug-ins/hot/Makefile
|
||||||
plug-ins/gz/Makefile
|
plug-ins/gz/Makefile
|
||||||
plug-ins/header/Makefile
|
plug-ins/header/Makefile
|
||||||
plug-ins/grid/Makefile
|
plug-ins/grid/Makefile
|
||||||
|
plug-ins/gee/Makefile
|
||||||
plug-ins/gradmap/Makefile
|
plug-ins/gradmap/Makefile
|
||||||
plug-ins/gqbist/Makefile
|
plug-ins/gqbist/Makefile
|
||||||
plug-ins/gif/Makefile
|
plug-ins/gif/Makefile
|
||||||
|
@ -543,6 +544,7 @@ plug-ins/libgck/gck/Makefile
|
||||||
plug-ins/MapObject/Makefile
|
plug-ins/MapObject/Makefile
|
||||||
plug-ins/gfig/Makefile
|
plug-ins/gfig/Makefile
|
||||||
plug-ins/gfig/gfig-examples/Makefile
|
plug-ins/gfig/gfig-examples/Makefile
|
||||||
|
plug-ins/screenshot/Makefile
|
||||||
app/Makefile
|
app/Makefile
|
||||||
docs/Makefile
|
docs/Makefile
|
||||||
data/Makefile
|
data/Makefile
|
||||||
|
|
|
@ -55,6 +55,7 @@ SUBDIRS = \
|
||||||
gauss_iir \
|
gauss_iir \
|
||||||
gauss_rle \
|
gauss_rle \
|
||||||
gbr \
|
gbr \
|
||||||
|
gee \
|
||||||
gfig \
|
gfig \
|
||||||
gfli \
|
gfli \
|
||||||
gicon \
|
gicon \
|
||||||
|
@ -99,6 +100,7 @@ SUBDIRS = \
|
||||||
rotate \
|
rotate \
|
||||||
rotators \
|
rotators \
|
||||||
scatter_hsv \
|
scatter_hsv \
|
||||||
|
screenshot \
|
||||||
semiflatten \
|
semiflatten \
|
||||||
sgi \
|
sgi \
|
||||||
shift \
|
shift \
|
||||||
|
|
|
@ -66,8 +66,6 @@
|
||||||
* the contents are frozen). Starvation of GTK's redrawing thread?
|
* the contents are frozen). Starvation of GTK's redrawing thread?
|
||||||
* How do I fix this?
|
* How do I fix this?
|
||||||
*
|
*
|
||||||
* Often segfaults on exit. GTK stuff. Help.
|
|
||||||
*
|
|
||||||
* Any more? Let me know!
|
* Any more? Let me know!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -112,6 +110,9 @@ static void do_playback (void);
|
||||||
static int parse_ms_tag (char *str);
|
static int parse_ms_tag (char *str);
|
||||||
static DisposeType parse_disposal_tag (char *str);
|
static DisposeType parse_disposal_tag (char *str);
|
||||||
|
|
||||||
|
static gint window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data);
|
||||||
static void window_close_callback (GtkWidget *widget,
|
static void window_close_callback (GtkWidget *widget,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static void playstop_callback (GtkWidget *widget,
|
static void playstop_callback (GtkWidget *widget,
|
||||||
|
@ -411,7 +412,7 @@ shape_motion (GtkWidget *widget,
|
||||||
|
|
||||||
gdk_window_get_pointer (root_win, &xp, &yp, &mask);
|
gdk_window_get_pointer (root_win, &xp, &yp, &mask);
|
||||||
|
|
||||||
// printf("%u %d\n", mask, event->state);fflush(stdout);
|
/* printf("%u %d\n", mask, event->state);fflush(stdout); */
|
||||||
|
|
||||||
/* if a button is still held by the time we process this event... */
|
/* if a button is still held by the time we process this event... */
|
||||||
if (mask & (GDK_BUTTON1_MASK|
|
if (mask & (GDK_BUTTON1_MASK|
|
||||||
|
@ -520,9 +521,9 @@ build_dialog(GImageType basetype,
|
||||||
gtk_window_set_title (GTK_WINDOW (dlg), windowname);
|
gtk_window_set_title (GTK_WINDOW (dlg), windowname);
|
||||||
g_free(windowname);
|
g_free(windowname);
|
||||||
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
||||||
gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
|
gtk_signal_connect (GTK_OBJECT (dlg), "delete_event",
|
||||||
(GtkSignalFunc) window_close_callback,
|
(GtkSignalFunc) window_delete_callback,
|
||||||
GTK_OBJECT (dlg));
|
NULL);
|
||||||
|
|
||||||
|
|
||||||
/* Action area - 'close' button only. */
|
/* Action area - 'close' button only. */
|
||||||
|
@ -1398,6 +1399,23 @@ get_frame_disposal (guint whichframe)
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
if (playing)
|
||||||
|
playstop_callback(NULL, NULL);
|
||||||
|
|
||||||
|
if (shape_window)
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(shape_window));
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
gtk_main_quit();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_close_callback (GtkWidget *widget,
|
window_close_callback (GtkWidget *widget,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
|
@ -1405,22 +1423,7 @@ window_close_callback (GtkWidget *widget,
|
||||||
if (data)
|
if (data)
|
||||||
gtk_widget_destroy(GTK_WIDGET(data));
|
gtk_widget_destroy(GTK_WIDGET(data));
|
||||||
|
|
||||||
if (shape_window)
|
window_delete_callback (NULL, NULL, NULL);
|
||||||
gtk_widget_destroy(GTK_WIDGET(shape_window));
|
|
||||||
|
|
||||||
if (playing)
|
|
||||||
playstop_callback(NULL, NULL);
|
|
||||||
|
|
||||||
gdk_flush();
|
|
||||||
|
|
||||||
/* catch up on outstanding events, or gtk_main_quit won't quit (!?) */
|
|
||||||
/* sleep(1);*/
|
|
||||||
while (gtk_events_pending())
|
|
||||||
gtk_main_iteration_do(TRUE);
|
|
||||||
|
|
||||||
/* FIXME: Why are we segfaulting? */
|
|
||||||
|
|
||||||
gtk_main_quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
|
|
@ -66,8 +66,6 @@
|
||||||
* the contents are frozen). Starvation of GTK's redrawing thread?
|
* the contents are frozen). Starvation of GTK's redrawing thread?
|
||||||
* How do I fix this?
|
* How do I fix this?
|
||||||
*
|
*
|
||||||
* Often segfaults on exit. GTK stuff. Help.
|
|
||||||
*
|
|
||||||
* Any more? Let me know!
|
* Any more? Let me know!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -112,6 +110,9 @@ static void do_playback (void);
|
||||||
static int parse_ms_tag (char *str);
|
static int parse_ms_tag (char *str);
|
||||||
static DisposeType parse_disposal_tag (char *str);
|
static DisposeType parse_disposal_tag (char *str);
|
||||||
|
|
||||||
|
static gint window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data);
|
||||||
static void window_close_callback (GtkWidget *widget,
|
static void window_close_callback (GtkWidget *widget,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static void playstop_callback (GtkWidget *widget,
|
static void playstop_callback (GtkWidget *widget,
|
||||||
|
@ -411,7 +412,7 @@ shape_motion (GtkWidget *widget,
|
||||||
|
|
||||||
gdk_window_get_pointer (root_win, &xp, &yp, &mask);
|
gdk_window_get_pointer (root_win, &xp, &yp, &mask);
|
||||||
|
|
||||||
// printf("%u %d\n", mask, event->state);fflush(stdout);
|
/* printf("%u %d\n", mask, event->state);fflush(stdout); */
|
||||||
|
|
||||||
/* if a button is still held by the time we process this event... */
|
/* if a button is still held by the time we process this event... */
|
||||||
if (mask & (GDK_BUTTON1_MASK|
|
if (mask & (GDK_BUTTON1_MASK|
|
||||||
|
@ -520,9 +521,9 @@ build_dialog(GImageType basetype,
|
||||||
gtk_window_set_title (GTK_WINDOW (dlg), windowname);
|
gtk_window_set_title (GTK_WINDOW (dlg), windowname);
|
||||||
g_free(windowname);
|
g_free(windowname);
|
||||||
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
||||||
gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
|
gtk_signal_connect (GTK_OBJECT (dlg), "delete_event",
|
||||||
(GtkSignalFunc) window_close_callback,
|
(GtkSignalFunc) window_delete_callback,
|
||||||
GTK_OBJECT (dlg));
|
NULL);
|
||||||
|
|
||||||
|
|
||||||
/* Action area - 'close' button only. */
|
/* Action area - 'close' button only. */
|
||||||
|
@ -1398,6 +1399,23 @@ get_frame_disposal (guint whichframe)
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
if (playing)
|
||||||
|
playstop_callback(NULL, NULL);
|
||||||
|
|
||||||
|
if (shape_window)
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(shape_window));
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
gtk_main_quit();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_close_callback (GtkWidget *widget,
|
window_close_callback (GtkWidget *widget,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
|
@ -1405,22 +1423,7 @@ window_close_callback (GtkWidget *widget,
|
||||||
if (data)
|
if (data)
|
||||||
gtk_widget_destroy(GTK_WIDGET(data));
|
gtk_widget_destroy(GTK_WIDGET(data));
|
||||||
|
|
||||||
if (shape_window)
|
window_delete_callback (NULL, NULL, NULL);
|
||||||
gtk_widget_destroy(GTK_WIDGET(shape_window));
|
|
||||||
|
|
||||||
if (playing)
|
|
||||||
playstop_callback(NULL, NULL);
|
|
||||||
|
|
||||||
gdk_flush();
|
|
||||||
|
|
||||||
/* catch up on outstanding events, or gtk_main_quit won't quit (!?) */
|
|
||||||
/* sleep(1);*/
|
|
||||||
while (gtk_events_pending())
|
|
||||||
gtk_main_iteration_do(TRUE);
|
|
||||||
|
|
||||||
/* FIXME: Why are we segfaulting? */
|
|
||||||
|
|
||||||
gtk_main_quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
|
|
@ -0,0 +1,772 @@
|
||||||
|
/*
|
||||||
|
* Adam D. Moss : 1998 : adam@gimp.org : adam@foxbox.org
|
||||||
|
*
|
||||||
|
* This is part of the GIMP package and is released under the GNU
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Version 1.01 : 98.04.19
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
#include "libgimp/gimp.h"
|
||||||
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Declare local functions. */
|
||||||
|
static void query(void);
|
||||||
|
static void run(char *name,
|
||||||
|
int nparams,
|
||||||
|
GParam * param,
|
||||||
|
int *nreturn_vals,
|
||||||
|
GParam ** return_vals);
|
||||||
|
|
||||||
|
static void do_playback (void);
|
||||||
|
|
||||||
|
static gint window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data);
|
||||||
|
static void window_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static gint step_callback (gpointer data);
|
||||||
|
static void toggle_feedbacktype (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
|
static void render_frame (void);
|
||||||
|
static void show_frame (void);
|
||||||
|
static void init_preview_misc (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GPlugInInfo PLUG_IN_INFO =
|
||||||
|
{
|
||||||
|
NULL, /* init_proc */
|
||||||
|
NULL, /* quit_proc */
|
||||||
|
query, /* query_proc */
|
||||||
|
run, /* run_proc */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const guint width = 256;
|
||||||
|
static const guint height = 256;
|
||||||
|
|
||||||
|
|
||||||
|
/* Global widgets'n'stuff */
|
||||||
|
static guchar* seed_data;
|
||||||
|
static guchar* preview_data1;
|
||||||
|
static guchar* preview_data2;
|
||||||
|
static GtkPreview* preview = NULL;
|
||||||
|
static gint32 image_id;
|
||||||
|
static gint32 total_frames;
|
||||||
|
static gint32* layers;
|
||||||
|
static GDrawable* drawable;
|
||||||
|
static GImageType imagetype;
|
||||||
|
static guchar* palette;
|
||||||
|
static gint ncolours;
|
||||||
|
|
||||||
|
static gint idle_tag;
|
||||||
|
static GtkWidget* eventbox;
|
||||||
|
static gboolean feedbacktype = FALSE;
|
||||||
|
static gboolean rgb_mode;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MAIN()
|
||||||
|
|
||||||
|
static void query()
|
||||||
|
{
|
||||||
|
static GParamDef args[] =
|
||||||
|
{
|
||||||
|
{PARAM_INT32, "run_mode", "Always interactive"},
|
||||||
|
{PARAM_IMAGE, "image", "Input Image"},
|
||||||
|
{PARAM_DRAWABLE, "drawable", "Input Drawable"},
|
||||||
|
};
|
||||||
|
static GParamDef *return_vals = NULL;
|
||||||
|
static int nargs = sizeof(args) / sizeof(args[0]);
|
||||||
|
static int nreturn_vals = 0;
|
||||||
|
|
||||||
|
gimp_install_procedure("plug_in_the_egg",
|
||||||
|
"A big hello from the GIMP team!",
|
||||||
|
"",
|
||||||
|
"Adam D. Moss <adam@gimp.org>",
|
||||||
|
"Adam D. Moss <adam@gimp.org>",
|
||||||
|
"1998",
|
||||||
|
/*"<Image>/Filters/Animation/The Egg",*/
|
||||||
|
NULL,
|
||||||
|
"RGB*, INDEXED*, GRAY*",
|
||||||
|
PROC_PLUG_IN,
|
||||||
|
nargs, nreturn_vals,
|
||||||
|
args, return_vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run(char *name, int n_params, GParam * param, int *nreturn_vals,
|
||||||
|
GParam ** return_vals)
|
||||||
|
{
|
||||||
|
static GParam values[1];
|
||||||
|
GRunModeType run_mode;
|
||||||
|
GStatusType status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
*nreturn_vals = 1;
|
||||||
|
*return_vals = values;
|
||||||
|
|
||||||
|
SRAND_FUNC (time(0));
|
||||||
|
|
||||||
|
run_mode = param[0].data.d_int32;
|
||||||
|
|
||||||
|
/* if (run_mode == RUN_NONINTERACTIVE) {*/
|
||||||
|
if (n_params != 3)
|
||||||
|
{
|
||||||
|
status = STATUS_CALLING_ERROR;
|
||||||
|
}
|
||||||
|
/* }*/
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
||||||
|
image_id = param[1].data.d_image;
|
||||||
|
|
||||||
|
do_playback();
|
||||||
|
/* if (run_mode != RUN_NONINTERACTIVE)
|
||||||
|
gimp_displays_flush();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
values[0].type = PARAM_STATUS;
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
build_dialog(GImageType basetype,
|
||||||
|
char* imagename)
|
||||||
|
{
|
||||||
|
gchar** argv;
|
||||||
|
gint argc;
|
||||||
|
|
||||||
|
GtkWidget* dlg;
|
||||||
|
GtkWidget* button;
|
||||||
|
GtkWidget* frame;
|
||||||
|
GtkWidget* frame2;
|
||||||
|
GtkWidget* vbox;
|
||||||
|
GtkWidget* hbox;
|
||||||
|
GtkWidget* hbox2;
|
||||||
|
guchar* color_cube;
|
||||||
|
|
||||||
|
argc = 1;
|
||||||
|
argv = g_new (gchar *, 1);
|
||||||
|
argv[0] = g_strdup ("gee");
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
gtk_rc_parse (gimp_gtkrc ());
|
||||||
|
gdk_set_use_xshm (gimp_use_xshm ());
|
||||||
|
gtk_preview_set_gamma (gimp_gamma ());
|
||||||
|
gtk_preview_set_install_cmap (gimp_install_cmap ());
|
||||||
|
color_cube = gimp_color_cube ();
|
||||||
|
gtk_preview_set_color_cube (color_cube[0], color_cube[1],
|
||||||
|
color_cube[2], color_cube[3]);
|
||||||
|
gtk_widget_set_default_visual (gtk_preview_get_visual ());
|
||||||
|
gtk_widget_set_default_colormap (gtk_preview_get_cmap ());
|
||||||
|
|
||||||
|
|
||||||
|
dlg = gtk_dialog_new ();
|
||||||
|
gtk_window_set_title (GTK_WINDOW (dlg), "GEE! The GIMP E'er Egg!");
|
||||||
|
|
||||||
|
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (dlg), "delete_event",
|
||||||
|
(GtkSignalFunc) window_delete_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* Action area - 'close' button only. */
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label ("** Thank you for choosing GIMP **");
|
||||||
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||||
|
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
||||||
|
(GtkSignalFunc) window_close_callback,
|
||||||
|
GTK_OBJECT (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);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
/* The 'playback' half of the dialog */
|
||||||
|
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 3);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
hbox = gtk_hbox_new (FALSE, 5);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox), 3);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
||||||
|
|
||||||
|
{
|
||||||
|
vbox = gtk_vbox_new (FALSE, 5);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (vbox), 3);
|
||||||
|
gtk_container_add (GTK_CONTAINER (hbox), vbox);
|
||||||
|
|
||||||
|
{
|
||||||
|
hbox2 = gtk_hbox_new (TRUE, 0);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox2), 0);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
|
||||||
|
{
|
||||||
|
frame2 = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox2), frame2, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
eventbox = gtk_event_box_new();
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame2), GTK_WIDGET (eventbox));
|
||||||
|
|
||||||
|
{
|
||||||
|
preview =
|
||||||
|
GTK_PREVIEW (gtk_preview_new (rgb_mode?
|
||||||
|
GTK_PREVIEW_COLOR:
|
||||||
|
GTK_PREVIEW_GRAYSCALE));
|
||||||
|
gtk_preview_size (preview, width, height);
|
||||||
|
gtk_container_add (GTK_CONTAINER (eventbox),
|
||||||
|
GTK_WIDGET (preview));
|
||||||
|
gtk_widget_show(GTK_WIDGET (preview));
|
||||||
|
}
|
||||||
|
gtk_widget_show(eventbox);
|
||||||
|
gtk_widget_set_events (eventbox,
|
||||||
|
gtk_widget_get_events (eventbox)
|
||||||
|
| GDK_BUTTON_PRESS_MASK);
|
||||||
|
}
|
||||||
|
gtk_widget_show(frame2);
|
||||||
|
}
|
||||||
|
gtk_widget_show(hbox2);
|
||||||
|
}
|
||||||
|
gtk_widget_show(vbox);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(hbox);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(dlg);
|
||||||
|
|
||||||
|
|
||||||
|
idle_tag = gtk_idle_add_priority (
|
||||||
|
GTK_PRIORITY_LOW,
|
||||||
|
(GtkFunction) step_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event",
|
||||||
|
GTK_SIGNAL_FUNC (toggle_feedbacktype), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void do_playback()
|
||||||
|
{
|
||||||
|
layers = gimp_image_get_layers (image_id, &total_frames);
|
||||||
|
imagetype = gimp_image_base_type(image_id);
|
||||||
|
|
||||||
|
if (imagetype == INDEXED)
|
||||||
|
palette = gimp_image_get_cmap(image_id, &ncolours);
|
||||||
|
|
||||||
|
/* cache hint */
|
||||||
|
gimp_tile_cache_ntiles (MAX(drawable->width,drawable->height)/
|
||||||
|
MIN(gimp_tile_width(),gimp_tile_height())
|
||||||
|
+1);
|
||||||
|
|
||||||
|
init_preview_misc();
|
||||||
|
build_dialog(gimp_image_base_type(image_id),
|
||||||
|
gimp_image_get_filename(image_id));
|
||||||
|
|
||||||
|
|
||||||
|
render_frame();
|
||||||
|
show_frame();
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
gdk_flush ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Rendering Functions */
|
||||||
|
|
||||||
|
/* Adam's silly algorithm. */
|
||||||
|
void domap1(unsigned char *src, unsigned char *dest,
|
||||||
|
int bx, int by, int cx, int cy)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int dy __attribute__ ((aligned));
|
||||||
|
signed int bycxmcybx __attribute__ ((aligned));
|
||||||
|
signed int bx2,by2 __attribute__ ((aligned));
|
||||||
|
signed int cx2,cy2 __attribute__ ((aligned));
|
||||||
|
unsigned int __attribute__ ((aligned)) basesx;
|
||||||
|
unsigned int __attribute__ ((aligned)) basesy;
|
||||||
|
#else
|
||||||
|
unsigned int dy;
|
||||||
|
signed int bycxmcybx;
|
||||||
|
signed int bx2,by2;
|
||||||
|
signed int cx2,cy2;
|
||||||
|
unsigned int basesx;
|
||||||
|
unsigned int basesy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bycxmcybx = (by*cx-cy*bx);
|
||||||
|
|
||||||
|
/* A little sub-pixel jitter to liven things up. */
|
||||||
|
basesx = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cx+bx)))<<11);
|
||||||
|
basesy = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cy+by)))<<11);
|
||||||
|
|
||||||
|
bx2 = ((bx)<<19)/bycxmcybx;
|
||||||
|
cx2 = ((cx)<<19)/bycxmcybx;
|
||||||
|
by2 = ((by)<<19)/bycxmcybx;
|
||||||
|
cy2 = ((cy)<<19)/bycxmcybx;
|
||||||
|
|
||||||
|
for (dy=0;dy<256;dy++)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int __attribute__ ((aligned)) sx;
|
||||||
|
unsigned int __attribute__ ((aligned)) sy;
|
||||||
|
unsigned int __attribute__ ((aligned)) dx;
|
||||||
|
#else
|
||||||
|
unsigned int sx;
|
||||||
|
unsigned int sy;
|
||||||
|
unsigned int dx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sx = (basesx-=bx2);
|
||||||
|
sy = (basesy+=cx2);
|
||||||
|
|
||||||
|
dx = 256;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*dest++ = (*(src +
|
||||||
|
(
|
||||||
|
(
|
||||||
|
((255&(
|
||||||
|
(sx>>11)
|
||||||
|
)))
|
||||||
|
|
|
||||||
|
((((255&(
|
||||||
|
(sy>>11)
|
||||||
|
))<<8)))
|
||||||
|
)
|
||||||
|
)));
|
||||||
|
;
|
||||||
|
sx += by2;
|
||||||
|
sy -= cy2;
|
||||||
|
}
|
||||||
|
while (--dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3bypp variant */
|
||||||
|
void domap3(unsigned char *src, unsigned char *dest,
|
||||||
|
int bx, int by, int cx, int cy)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int dy __attribute__ ((aligned));
|
||||||
|
signed int bycxmcybx __attribute__ ((aligned));
|
||||||
|
signed int bx2,by2 __attribute__ ((aligned));
|
||||||
|
signed int cx2,cy2 __attribute__ ((aligned));
|
||||||
|
unsigned int __attribute__ ((aligned)) basesx;
|
||||||
|
unsigned int __attribute__ ((aligned)) basesy;
|
||||||
|
#else
|
||||||
|
unsigned int dy;
|
||||||
|
signed int bycxmcybx;
|
||||||
|
signed int bx2,by2;
|
||||||
|
signed int cx2,cy2;
|
||||||
|
unsigned int basesx;
|
||||||
|
unsigned int basesy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bycxmcybx = (by*cx-cy*bx);
|
||||||
|
|
||||||
|
/* A little sub-pixel jitter to liven things up. */
|
||||||
|
basesx = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cx+bx)))<<11);
|
||||||
|
basesy = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cy+by)))<<11);
|
||||||
|
|
||||||
|
bx2 = ((bx)<<19)/bycxmcybx;
|
||||||
|
cx2 = ((cx)<<19)/bycxmcybx;
|
||||||
|
by2 = ((by)<<19)/bycxmcybx;
|
||||||
|
cy2 = ((cy)<<19)/bycxmcybx;
|
||||||
|
|
||||||
|
for (dy=0;dy<256;dy++)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int __attribute__ ((aligned)) sx;
|
||||||
|
unsigned int __attribute__ ((aligned)) sy;
|
||||||
|
unsigned int __attribute__ ((aligned)) dx;
|
||||||
|
#else
|
||||||
|
unsigned int sx;
|
||||||
|
unsigned int sy;
|
||||||
|
unsigned int dx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sx = (basesx-=bx2);
|
||||||
|
sy = (basesy+=cx2);
|
||||||
|
|
||||||
|
dx = 256;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
unsigned char* addr;
|
||||||
|
|
||||||
|
addr = src + 3*
|
||||||
|
(
|
||||||
|
(
|
||||||
|
((255&(
|
||||||
|
(sx>>11)
|
||||||
|
)))
|
||||||
|
|
|
||||||
|
((((255&(
|
||||||
|
(sy>>11)
|
||||||
|
))<<8)))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
*dest++ = *(addr);
|
||||||
|
*dest++ = *(addr+1);
|
||||||
|
*dest++ = *(addr+2);
|
||||||
|
|
||||||
|
sx += by2;
|
||||||
|
sy -= cy2;
|
||||||
|
}
|
||||||
|
while (--dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_frame(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
static int frame = 0;
|
||||||
|
unsigned char* tmp;
|
||||||
|
static gint xp=128, yp=128;
|
||||||
|
gint rxp, ryp;
|
||||||
|
GdkModifierType mask;
|
||||||
|
gint pixels;
|
||||||
|
|
||||||
|
pixels = width*height*(rgb_mode?3:1);
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
|
||||||
|
tmp = preview_data2;
|
||||||
|
preview_data2 = preview_data1;
|
||||||
|
preview_data1 = tmp;
|
||||||
|
|
||||||
|
if (frame==0)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data2[i] =
|
||||||
|
preview_data1[i] =
|
||||||
|
seed_data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_window_get_pointer (eventbox->window, &rxp, &ryp, &mask);
|
||||||
|
|
||||||
|
if ((abs(rxp)>60)||(abs(ryp)>60))
|
||||||
|
{
|
||||||
|
xp = rxp;
|
||||||
|
yp = ryp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgb_mode)
|
||||||
|
{
|
||||||
|
domap3(preview_data2, preview_data1,
|
||||||
|
-(yp-xp)/2, xp+yp
|
||||||
|
,
|
||||||
|
xp+yp, (yp-xp)/2
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i=0;i<height;i++)
|
||||||
|
{
|
||||||
|
gtk_preview_draw_row (preview,
|
||||||
|
&preview_data1[i*width*3],
|
||||||
|
0, i, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame != 0)
|
||||||
|
{
|
||||||
|
if (feedbacktype)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
t = preview_data1[i] + seed_data[i] - 128;
|
||||||
|
preview_data1[i] = CLAMP(t,0,255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data1[i] = (preview_data1[i]*2 + seed_data[i]) /3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* GRAYSCALE */
|
||||||
|
{
|
||||||
|
domap1(preview_data2, preview_data1,
|
||||||
|
-(yp-xp)/2, xp+yp
|
||||||
|
,
|
||||||
|
xp+yp, (yp-xp)/2
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i=0;i<height;i++)
|
||||||
|
{
|
||||||
|
gtk_preview_draw_row (preview,
|
||||||
|
&preview_data1[i*width],
|
||||||
|
0, i, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame != 0)
|
||||||
|
{
|
||||||
|
if (feedbacktype)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
t = preview_data1[i] + seed_data[i] - 128;
|
||||||
|
preview_data1[i] = CLAMP(t,0,255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data1[i] = (preview_data1[i]*2 + seed_data[i]) /3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_frame(void)
|
||||||
|
{
|
||||||
|
/* Tell GTK to physically draw the preview */
|
||||||
|
gtk_widget_draw (GTK_WIDGET (preview), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_preview_misc(void)
|
||||||
|
{
|
||||||
|
GPixelRgn pixel_rgn;
|
||||||
|
int i;
|
||||||
|
gboolean has_alpha;
|
||||||
|
|
||||||
|
if ((imagetype == RGB)||(imagetype == INDEXED))
|
||||||
|
rgb_mode = TRUE;
|
||||||
|
else
|
||||||
|
rgb_mode = FALSE;
|
||||||
|
|
||||||
|
has_alpha = gimp_drawable_has_alpha(drawable->id);
|
||||||
|
|
||||||
|
seed_data = g_malloc(width*height*4);
|
||||||
|
preview_data1 = g_malloc(width*height*(rgb_mode?3:1));
|
||||||
|
preview_data2 = g_malloc(width*height*(rgb_mode?3:1));
|
||||||
|
|
||||||
|
if ((drawable->width<256) || (drawable->height<256))
|
||||||
|
{
|
||||||
|
for (i=0;i<256;i++)
|
||||||
|
{
|
||||||
|
if (i < drawable->height)
|
||||||
|
{
|
||||||
|
gimp_pixel_rgn_init (&pixel_rgn,
|
||||||
|
drawable,
|
||||||
|
drawable->width>256?
|
||||||
|
(drawable->width/2-128):0,
|
||||||
|
(drawable->height>256?
|
||||||
|
(drawable->height/2-128):0)+i,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
1,
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
gimp_pixel_rgn_get_rect (&pixel_rgn,
|
||||||
|
&seed_data[(256*i +
|
||||||
|
(
|
||||||
|
(
|
||||||
|
drawable->width<256 ?
|
||||||
|
(256-drawable->width)/2 :
|
||||||
|
0
|
||||||
|
)
|
||||||
|
+
|
||||||
|
(
|
||||||
|
drawable->height<256 ?
|
||||||
|
(256-drawable->height)/2 :
|
||||||
|
0
|
||||||
|
) * 256
|
||||||
|
)) *
|
||||||
|
gimp_drawable_bpp
|
||||||
|
(drawable->id)
|
||||||
|
],
|
||||||
|
drawable->width>256?
|
||||||
|
(drawable->width/2-128):0,
|
||||||
|
(drawable->height>256?
|
||||||
|
(drawable->height/2-128):0)+i,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_pixel_rgn_init (&pixel_rgn,
|
||||||
|
drawable,
|
||||||
|
drawable->width>256?(drawable->width/2-128):0,
|
||||||
|
drawable->height>256?(drawable->height/2-128):0,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
MIN(256,drawable->height),
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
gimp_pixel_rgn_get_rect (&pixel_rgn,
|
||||||
|
seed_data,
|
||||||
|
drawable->width>256?(drawable->width/2-128):0,
|
||||||
|
drawable->height>256?(drawable->height/2-128):0,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
MIN(256,drawable->height));
|
||||||
|
}
|
||||||
|
|
||||||
|
gimp_drawable_detach(drawable);
|
||||||
|
|
||||||
|
|
||||||
|
/* convert the image data of varying types into flat grey or rgb. */
|
||||||
|
switch (imagetype)
|
||||||
|
{
|
||||||
|
case INDEXED:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=width*height;i>0;i--)
|
||||||
|
{
|
||||||
|
seed_data[3*(i-1)+2] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+2]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[3*(i-1)+1] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+1]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[3*(i-1)+0] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+0]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=width*height;i>0;i--)
|
||||||
|
{
|
||||||
|
seed_data[3*(i-1)+2] = palette[3*(seed_data[i-1])+2];
|
||||||
|
seed_data[3*(i-1)+1] = palette[3*(seed_data[i-1])+1];
|
||||||
|
seed_data[3*(i-1)+0] = palette[3*(seed_data[i-1])+0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GRAY:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=0;i<width*height;i++)
|
||||||
|
{
|
||||||
|
seed_data[i] =
|
||||||
|
(seed_data[i*2]*seed_data[i*2+1])/255
|
||||||
|
+ ((255-seed_data[i*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RGB:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=0;i<width*height;i++)
|
||||||
|
{
|
||||||
|
seed_data[i*3+2] =
|
||||||
|
(seed_data[i*4+2]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[i*3+1] =
|
||||||
|
(seed_data[i*4+1]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[i*3+0] =
|
||||||
|
(seed_data[i*4+0]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Util. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_step(void)
|
||||||
|
{
|
||||||
|
render_frame();
|
||||||
|
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Callbacks */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
gtk_idle_remove (idle_tag);
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
gtk_main_quit();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(data));
|
||||||
|
|
||||||
|
window_delete_callback (NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
toggle_feedbacktype (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
feedbacktype = !feedbacktype;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gint
|
||||||
|
step_callback (gpointer data)
|
||||||
|
{
|
||||||
|
do_step();
|
||||||
|
show_frame();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,506 @@
|
||||||
|
/*
|
||||||
|
* ScreenShot plug-in v0.6 by Sven Neumann, neumanns@uni-duesseldorf.de
|
||||||
|
* 1998/04/18
|
||||||
|
*
|
||||||
|
* Any suggestions, bug-reports or patches are very welcome.
|
||||||
|
*
|
||||||
|
* This plug-in uses the X-utility xwd to grab an image from the screen
|
||||||
|
* and the xwd-plug-in created by Peter Kirchgessner (pkirchg@aol.com)
|
||||||
|
* to load this image into the gimp.
|
||||||
|
* Hence its nothing but a simple frontend to those utilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The GIMP -- an image manipulation program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Revision history
|
||||||
|
* (98/02/18) v0.1 first development release
|
||||||
|
* (98/02/19) v0.2 small bugfix
|
||||||
|
* (98/03/09) v0.3 another one
|
||||||
|
* (98/03/13) v0.4 cosmetic changes to the dialog
|
||||||
|
* (98/04/02) v0.5 it works non-interactively now and registers
|
||||||
|
* itself correctly as extension
|
||||||
|
* (98/04/18) v0.6 cosmetic change to the dialog
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "gtk/gtk.h"
|
||||||
|
#include "libgimp/gimp.h"
|
||||||
|
|
||||||
|
/* Defines */
|
||||||
|
#define PLUG_IN_NAME "extension_screenshot"
|
||||||
|
#define PLUG_IN_PRINT_NAME "Screen Shot"
|
||||||
|
#define PLUG_IN_VERSION "v0.6 (98/04/18)"
|
||||||
|
#define PLUG_IN_MENU_PATH "<Toolbox>/Xtns/Screen Shot"
|
||||||
|
#define PLUG_IN_AUTHOR "Sven Neumann (neumanns@uni-duesseldorf.de)"
|
||||||
|
#define PLUG_IN_COPYRIGHT "Sven Neumann"
|
||||||
|
#define PLUG_IN_DESCRIBTION "Create a screenshot of a single window or the whole screen"
|
||||||
|
#define PLUG_IN_HELP "This extension serves as a simple frontend to the X-window utility xwd and the xwd-file-plug-in. After specifying some options, xwd is called, the user selects a window, and the resulting image is loaded into the gimp. When called non-interactively it may grab the root window or use the window-id passed as a parameter."
|
||||||
|
|
||||||
|
#define NUMBER_IN_ARGS 3
|
||||||
|
#define IN_ARGS { PARAM_INT32, "run_mode", "Interactive, non-interactive" },\
|
||||||
|
{ PARAM_INT32, "root", "Root window { TRUE, FALSE }" },\
|
||||||
|
{ PARAM_STRING, "window_id", "Window id" }
|
||||||
|
|
||||||
|
#define NUMBER_OUT_ARGS 1
|
||||||
|
#define OUT_ARGS { PARAM_IMAGE, "image", "Output image" }
|
||||||
|
|
||||||
|
#ifndef XWD
|
||||||
|
#define XWD "xwd"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
gint root;
|
||||||
|
gchar *window_id;
|
||||||
|
gint decor;
|
||||||
|
} ScreenShotValues;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GtkWidget *decor_button;
|
||||||
|
GtkWidget *single_button;
|
||||||
|
GtkWidget *root_button;
|
||||||
|
gint run;
|
||||||
|
} ScreenShotInterface;
|
||||||
|
|
||||||
|
static ScreenShotValues shootvals =
|
||||||
|
{
|
||||||
|
FALSE, /* default to window */
|
||||||
|
NULL,
|
||||||
|
TRUE /* default to decorations */
|
||||||
|
};
|
||||||
|
|
||||||
|
static ScreenShotInterface shootint =
|
||||||
|
{
|
||||||
|
FALSE /* run */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void query (void);
|
||||||
|
static void run (gchar *name,
|
||||||
|
gint nparams, /* number of parameters passed in */
|
||||||
|
GParam * param, /* parameters passed in */
|
||||||
|
gint *nreturn_vals, /* number of parameters returned */
|
||||||
|
GParam ** return_vals); /* parameters to be returned */
|
||||||
|
static void shoot (void);
|
||||||
|
static gint shoot_dialog (void);
|
||||||
|
static void shoot_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static void shoot_ok_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static void shoot_toggle_update (GtkWidget *widget,
|
||||||
|
gpointer radio_button);
|
||||||
|
static void shoot_display_image (gint32 image);
|
||||||
|
|
||||||
|
/* Global Variables */
|
||||||
|
GPlugInInfo PLUG_IN_INFO =
|
||||||
|
{
|
||||||
|
NULL, /* init_proc */
|
||||||
|
NULL, /* quit_proc */
|
||||||
|
query, /* query_proc */
|
||||||
|
run /* run_proc */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* the image that will be returned */
|
||||||
|
gint32 image_ID = -1;
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
|
||||||
|
MAIN ()
|
||||||
|
|
||||||
|
static void query (void)
|
||||||
|
{
|
||||||
|
static GParamDef args[] = { IN_ARGS };
|
||||||
|
static gint nargs = NUMBER_IN_ARGS;
|
||||||
|
static GParamDef return_vals[] = { OUT_ARGS };
|
||||||
|
static gint nreturn_vals = NUMBER_OUT_ARGS;
|
||||||
|
|
||||||
|
/* the actual installation of the plugin */
|
||||||
|
gimp_install_procedure (PLUG_IN_NAME,
|
||||||
|
PLUG_IN_DESCRIBTION,
|
||||||
|
PLUG_IN_HELP,
|
||||||
|
PLUG_IN_AUTHOR,
|
||||||
|
PLUG_IN_COPYRIGHT,
|
||||||
|
PLUG_IN_VERSION,
|
||||||
|
PLUG_IN_MENU_PATH,
|
||||||
|
NULL,
|
||||||
|
PROC_EXTENSION,
|
||||||
|
nargs,
|
||||||
|
nreturn_vals,
|
||||||
|
args,
|
||||||
|
return_vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run (gchar *name, /* name of plugin */
|
||||||
|
gint nparams, /* number of in-paramters */
|
||||||
|
GParam * param, /* in-parameters */
|
||||||
|
gint *nreturn_vals, /* number of out-parameters */
|
||||||
|
GParam ** return_vals) /* out-parameters */
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Get the runmode from the in-parameters */
|
||||||
|
GRunModeType run_mode = param[0].data.d_int32;
|
||||||
|
|
||||||
|
/* status variable, use it to check for errors in invocation usualy only
|
||||||
|
during non-interactive calling */
|
||||||
|
GStatusType status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
/*always return at least the status to the caller. */
|
||||||
|
static GParam values[1];
|
||||||
|
|
||||||
|
/* initialize the return of the status */
|
||||||
|
values[0].type = PARAM_STATUS;
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
*nreturn_vals = 1;
|
||||||
|
*return_vals = values;
|
||||||
|
|
||||||
|
/*how are we running today? */
|
||||||
|
switch (run_mode)
|
||||||
|
{
|
||||||
|
case RUN_INTERACTIVE:
|
||||||
|
/* Possibly retrieve data from a previous run */
|
||||||
|
gimp_get_data (PLUG_IN_NAME, &shootvals);
|
||||||
|
shootvals.window_id = NULL;
|
||||||
|
|
||||||
|
/* Get information from the dialog */
|
||||||
|
if (!shoot_dialog())
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUN_NONINTERACTIVE:
|
||||||
|
if (nparams == NUMBER_IN_ARGS)
|
||||||
|
{
|
||||||
|
shootvals.root = (gint) param[1].data.d_int32;
|
||||||
|
shootvals.window_id = (gchar*) param[2].data.d_string;
|
||||||
|
shootvals.decor = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
status = STATUS_CALLING_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUN_WITH_LAST_VALS:
|
||||||
|
/* Possibly retrieve data from a previous run */
|
||||||
|
gimp_get_data (PLUG_IN_NAME, &shootvals);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
} /* switch */
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Run the main function */
|
||||||
|
shoot();
|
||||||
|
|
||||||
|
/* Store variable states for next run */
|
||||||
|
if (run_mode == RUN_INTERACTIVE)
|
||||||
|
gimp_set_data (PLUG_IN_NAME, &shootvals, sizeof (ScreenShotValues));
|
||||||
|
}
|
||||||
|
|
||||||
|
status = (image_ID != -1) ? STATUS_SUCCESS : STATUS_EXECUTION_ERROR;
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
if (run_mode == RUN_INTERACTIVE)
|
||||||
|
{
|
||||||
|
/* display the image */
|
||||||
|
shoot_display_image (image_ID);
|
||||||
|
}
|
||||||
|
/* set return values */
|
||||||
|
*nreturn_vals = 2;
|
||||||
|
values[1].type = PARAM_IMAGE;
|
||||||
|
values[1].data.d_image = image_ID;
|
||||||
|
}
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The main ScreenShot function */
|
||||||
|
static void
|
||||||
|
shoot (void)
|
||||||
|
{
|
||||||
|
GParam *params;
|
||||||
|
gint retvals;
|
||||||
|
char *tmpname;
|
||||||
|
char *xwdargv[7]; /* only need a maximum of 7 arguments to xwd */
|
||||||
|
gint pid;
|
||||||
|
gint status;
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
|
/* get a temp name with the right extension and save into it. */
|
||||||
|
params = gimp_run_procedure ("gimp_temp_name",
|
||||||
|
&retvals,
|
||||||
|
PARAM_STRING, "xwd",
|
||||||
|
PARAM_END);
|
||||||
|
tmpname = params[1].data.d_string;
|
||||||
|
|
||||||
|
/* construct the xwd arguments */
|
||||||
|
xwdargv[i++] = XWD;
|
||||||
|
xwdargv[i++] = "-out";
|
||||||
|
xwdargv[i++] = tmpname;
|
||||||
|
if ( shootvals.root == TRUE )
|
||||||
|
xwdargv[i++] = "-root";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (shootvals.decor == TRUE )
|
||||||
|
xwdargv[i++] = "-frame";
|
||||||
|
if (shootvals.window_id != NULL)
|
||||||
|
{
|
||||||
|
xwdargv[i++] = "-id";
|
||||||
|
xwdargv[i++] = shootvals.window_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xwdargv[i] = NULL;
|
||||||
|
|
||||||
|
/* fork off a xwd process */
|
||||||
|
if ((pid = fork ()) < 0)
|
||||||
|
{
|
||||||
|
g_warning ("screenshot: fork failed: %s\n", g_strerror (errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (pid == 0)
|
||||||
|
{
|
||||||
|
execvp (XWD, xwdargv);
|
||||||
|
/* What are we doing here? exec must have failed */
|
||||||
|
g_warning ("screenshot: exec failed: xwd: %s\n", g_strerror (errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waitpid (pid, &status, 0);
|
||||||
|
|
||||||
|
if (!WIFEXITED (status))
|
||||||
|
{
|
||||||
|
g_warning ("screenshot: xwd didn't work\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now load the tmpfile using the xwd-plug-in */
|
||||||
|
params = gimp_run_procedure ("file_xwd_load",
|
||||||
|
&retvals,
|
||||||
|
PARAM_INT32, 1,
|
||||||
|
PARAM_STRING, tmpname,
|
||||||
|
PARAM_STRING, tmpname,
|
||||||
|
PARAM_END);
|
||||||
|
image_ID = params[1].data.d_image;
|
||||||
|
|
||||||
|
/* get rid of the tmpfile */
|
||||||
|
unlink (tmpname);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ScreenShot dialog */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
shoot_dialog (void)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkWidget *frame;
|
||||||
|
GtkWidget *vbox;
|
||||||
|
GtkWidget *button;
|
||||||
|
GtkWidget *hbox;
|
||||||
|
GtkWidget *radio_label;
|
||||||
|
GSList *radio_group = NULL;
|
||||||
|
gint radio_pressed[2];
|
||||||
|
gint decorations;
|
||||||
|
gint argc = 1;
|
||||||
|
gchar **argv = g_new (gchar *, 1);
|
||||||
|
argv[0] = g_strdup ("ScreenShot");
|
||||||
|
|
||||||
|
radio_pressed[0] = (shootvals.root == FALSE);
|
||||||
|
radio_pressed[1] = (shootvals.root == TRUE);
|
||||||
|
decorations = shootvals.decor;
|
||||||
|
|
||||||
|
/* Init GTK */
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
gtk_rc_parse (gimp_gtkrc ());
|
||||||
|
|
||||||
|
gdk_set_use_xshm (gimp_use_xshm ());
|
||||||
|
|
||||||
|
/* Main Dialog */
|
||||||
|
dialog = gtk_dialog_new ();
|
||||||
|
gtk_window_set_title (GTK_WINDOW (dialog), PLUG_IN_PRINT_NAME);
|
||||||
|
gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
|
||||||
|
(GtkSignalFunc) shoot_close_callback,
|
||||||
|
NULL);
|
||||||
|
/* Action area */
|
||||||
|
button = gtk_button_new_with_label ("Grab");
|
||||||
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||||
|
(GtkSignalFunc) shoot_ok_callback,
|
||||||
|
dialog);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->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 (dialog));
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
|
||||||
|
button, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (button);
|
||||||
|
|
||||||
|
/* Single Window */
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
vbox = gtk_vbox_new (FALSE, 4);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (vbox), 4);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox),
|
||||||
|
hbox, TRUE, TRUE, 0);
|
||||||
|
shootint.single_button = gtk_radio_button_new ( radio_group );
|
||||||
|
radio_group = gtk_radio_button_group ( GTK_RADIO_BUTTON (shootint.single_button) );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox),
|
||||||
|
shootint.single_button, TRUE, TRUE, 0);
|
||||||
|
gtk_signal_connect ( GTK_OBJECT (shootint.single_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&radio_pressed[0]);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.single_button),
|
||||||
|
radio_pressed[0]);
|
||||||
|
gtk_widget_show (shootint.single_button);
|
||||||
|
radio_label = gtk_label_new ( "Grab a single window" );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox),
|
||||||
|
radio_label, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (radio_label);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
|
/* with decorations */
|
||||||
|
hbox = gtk_hbox_new (FALSE, 0);
|
||||||
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
|
||||||
|
shootint.decor_button = gtk_check_button_new_with_label ("Include decorations");
|
||||||
|
gtk_signal_connect (GTK_OBJECT (shootint.decor_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&decorations);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.decor_button),
|
||||||
|
decorations);
|
||||||
|
gtk_box_pack_end (GTK_BOX (hbox), shootint.decor_button, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_set_sensitive (shootint.decor_button, radio_pressed[0]);
|
||||||
|
gtk_widget_show (shootint.decor_button);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
|
gtk_widget_show (vbox);
|
||||||
|
gtk_widget_show (frame);
|
||||||
|
|
||||||
|
/* Root Window */
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 4);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox), 4);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
||||||
|
|
||||||
|
shootint.root_button = gtk_radio_button_new ( radio_group );
|
||||||
|
radio_group = gtk_radio_button_group ( GTK_RADIO_BUTTON (shootint.root_button) );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), shootint.root_button, TRUE, TRUE, 0);
|
||||||
|
gtk_signal_connect ( GTK_OBJECT (shootint.root_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&radio_pressed[1]);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.root_button),
|
||||||
|
radio_pressed[1]);
|
||||||
|
gtk_widget_show (shootint.root_button);
|
||||||
|
|
||||||
|
radio_label = gtk_label_new ( "Grab the whole screen" );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), radio_label, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (radio_label);
|
||||||
|
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
gtk_widget_show (frame);
|
||||||
|
|
||||||
|
gtk_widget_show (dialog);
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
gdk_flush ();
|
||||||
|
|
||||||
|
shootvals.root = radio_pressed[1];
|
||||||
|
shootvals.decor = decorations;
|
||||||
|
|
||||||
|
return shootint.run;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ScreenShot interface functions */
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
gtk_main_quit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_ok_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
shootint.run = TRUE;
|
||||||
|
gtk_widget_destroy (GTK_WIDGET (data));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_toggle_update (GtkWidget *widget,
|
||||||
|
gpointer radio_button)
|
||||||
|
{
|
||||||
|
gint *toggle_val;
|
||||||
|
|
||||||
|
toggle_val = (gint *) radio_button;
|
||||||
|
|
||||||
|
if (GTK_TOGGLE_BUTTON (widget)->active)
|
||||||
|
*toggle_val = TRUE;
|
||||||
|
else
|
||||||
|
*toggle_val = FALSE;
|
||||||
|
|
||||||
|
if (widget == shootint.single_button)
|
||||||
|
gtk_widget_set_sensitive (shootint.decor_button, *toggle_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display function */
|
||||||
|
|
||||||
|
void
|
||||||
|
shoot_display_image (gint32 image)
|
||||||
|
{
|
||||||
|
GParam *params;
|
||||||
|
gint retvals;
|
||||||
|
|
||||||
|
params = gimp_run_procedure ("gimp_display_new",
|
||||||
|
&retvals,
|
||||||
|
PARAM_IMAGE, image,
|
||||||
|
PARAM_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
Makefile.in
|
||||||
|
Makefile
|
||||||
|
.deps
|
||||||
|
_libs
|
||||||
|
.libs
|
||||||
|
gee
|
|
@ -0,0 +1,39 @@
|
||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
pluginlibdir = $(gimpplugindir)/plug-ins
|
||||||
|
|
||||||
|
pluginlib_PROGRAMS = gee
|
||||||
|
|
||||||
|
gee_SOURCES = \
|
||||||
|
gee.c
|
||||||
|
|
||||||
|
INCLUDES = \
|
||||||
|
$(X_CFLAGS) \
|
||||||
|
-I$(top_srcdir) \
|
||||||
|
-I$(includedir)
|
||||||
|
|
||||||
|
LDADD = \
|
||||||
|
$(top_builddir)/libgimp/libgimpui.la \
|
||||||
|
$(top_builddir)/libgimp/libgimp.la \
|
||||||
|
$(X_LIBS) \
|
||||||
|
\
|
||||||
|
-lc
|
||||||
|
|
||||||
|
DEPS = \
|
||||||
|
$(top_builddir)/libgimp/libgimpui.la \
|
||||||
|
$(top_builddir)/libgimp/libgimp.la
|
||||||
|
|
||||||
|
gee_DEPENDENCIES = $(DEPS)
|
||||||
|
|
||||||
|
.PHONY: files
|
||||||
|
|
||||||
|
files:
|
||||||
|
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
|
||||||
|
echo $$p; \
|
||||||
|
done
|
||||||
|
@for subdir in $(SUBDIRS); do \
|
||||||
|
files=`cd $$subdir; $(MAKE) files | grep -v "make\[[1-9]\]"`; \
|
||||||
|
for file in $$files; do \
|
||||||
|
echo $$subdir/$$file; \
|
||||||
|
done; \
|
||||||
|
done
|
|
@ -0,0 +1,772 @@
|
||||||
|
/*
|
||||||
|
* Adam D. Moss : 1998 : adam@gimp.org : adam@foxbox.org
|
||||||
|
*
|
||||||
|
* This is part of the GIMP package and is released under the GNU
|
||||||
|
* Public License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Version 1.01 : 98.04.19
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "glib.h"
|
||||||
|
#include "libgimp/gimp.h"
|
||||||
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Declare local functions. */
|
||||||
|
static void query(void);
|
||||||
|
static void run(char *name,
|
||||||
|
int nparams,
|
||||||
|
GParam * param,
|
||||||
|
int *nreturn_vals,
|
||||||
|
GParam ** return_vals);
|
||||||
|
|
||||||
|
static void do_playback (void);
|
||||||
|
|
||||||
|
static gint window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data);
|
||||||
|
static void window_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static gint step_callback (gpointer data);
|
||||||
|
static void toggle_feedbacktype (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
|
static void render_frame (void);
|
||||||
|
static void show_frame (void);
|
||||||
|
static void init_preview_misc (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GPlugInInfo PLUG_IN_INFO =
|
||||||
|
{
|
||||||
|
NULL, /* init_proc */
|
||||||
|
NULL, /* quit_proc */
|
||||||
|
query, /* query_proc */
|
||||||
|
run, /* run_proc */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static const guint width = 256;
|
||||||
|
static const guint height = 256;
|
||||||
|
|
||||||
|
|
||||||
|
/* Global widgets'n'stuff */
|
||||||
|
static guchar* seed_data;
|
||||||
|
static guchar* preview_data1;
|
||||||
|
static guchar* preview_data2;
|
||||||
|
static GtkPreview* preview = NULL;
|
||||||
|
static gint32 image_id;
|
||||||
|
static gint32 total_frames;
|
||||||
|
static gint32* layers;
|
||||||
|
static GDrawable* drawable;
|
||||||
|
static GImageType imagetype;
|
||||||
|
static guchar* palette;
|
||||||
|
static gint ncolours;
|
||||||
|
|
||||||
|
static gint idle_tag;
|
||||||
|
static GtkWidget* eventbox;
|
||||||
|
static gboolean feedbacktype = FALSE;
|
||||||
|
static gboolean rgb_mode;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MAIN()
|
||||||
|
|
||||||
|
static void query()
|
||||||
|
{
|
||||||
|
static GParamDef args[] =
|
||||||
|
{
|
||||||
|
{PARAM_INT32, "run_mode", "Always interactive"},
|
||||||
|
{PARAM_IMAGE, "image", "Input Image"},
|
||||||
|
{PARAM_DRAWABLE, "drawable", "Input Drawable"},
|
||||||
|
};
|
||||||
|
static GParamDef *return_vals = NULL;
|
||||||
|
static int nargs = sizeof(args) / sizeof(args[0]);
|
||||||
|
static int nreturn_vals = 0;
|
||||||
|
|
||||||
|
gimp_install_procedure("plug_in_the_egg",
|
||||||
|
"A big hello from the GIMP team!",
|
||||||
|
"",
|
||||||
|
"Adam D. Moss <adam@gimp.org>",
|
||||||
|
"Adam D. Moss <adam@gimp.org>",
|
||||||
|
"1998",
|
||||||
|
/*"<Image>/Filters/Animation/The Egg",*/
|
||||||
|
NULL,
|
||||||
|
"RGB*, INDEXED*, GRAY*",
|
||||||
|
PROC_PLUG_IN,
|
||||||
|
nargs, nreturn_vals,
|
||||||
|
args, return_vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void run(char *name, int n_params, GParam * param, int *nreturn_vals,
|
||||||
|
GParam ** return_vals)
|
||||||
|
{
|
||||||
|
static GParam values[1];
|
||||||
|
GRunModeType run_mode;
|
||||||
|
GStatusType status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
*nreturn_vals = 1;
|
||||||
|
*return_vals = values;
|
||||||
|
|
||||||
|
SRAND_FUNC (time(0));
|
||||||
|
|
||||||
|
run_mode = param[0].data.d_int32;
|
||||||
|
|
||||||
|
/* if (run_mode == RUN_NONINTERACTIVE) {*/
|
||||||
|
if (n_params != 3)
|
||||||
|
{
|
||||||
|
status = STATUS_CALLING_ERROR;
|
||||||
|
}
|
||||||
|
/* }*/
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
||||||
|
image_id = param[1].data.d_image;
|
||||||
|
|
||||||
|
do_playback();
|
||||||
|
/* if (run_mode != RUN_NONINTERACTIVE)
|
||||||
|
gimp_displays_flush();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
values[0].type = PARAM_STATUS;
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
build_dialog(GImageType basetype,
|
||||||
|
char* imagename)
|
||||||
|
{
|
||||||
|
gchar** argv;
|
||||||
|
gint argc;
|
||||||
|
|
||||||
|
GtkWidget* dlg;
|
||||||
|
GtkWidget* button;
|
||||||
|
GtkWidget* frame;
|
||||||
|
GtkWidget* frame2;
|
||||||
|
GtkWidget* vbox;
|
||||||
|
GtkWidget* hbox;
|
||||||
|
GtkWidget* hbox2;
|
||||||
|
guchar* color_cube;
|
||||||
|
|
||||||
|
argc = 1;
|
||||||
|
argv = g_new (gchar *, 1);
|
||||||
|
argv[0] = g_strdup ("gee");
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
gtk_rc_parse (gimp_gtkrc ());
|
||||||
|
gdk_set_use_xshm (gimp_use_xshm ());
|
||||||
|
gtk_preview_set_gamma (gimp_gamma ());
|
||||||
|
gtk_preview_set_install_cmap (gimp_install_cmap ());
|
||||||
|
color_cube = gimp_color_cube ();
|
||||||
|
gtk_preview_set_color_cube (color_cube[0], color_cube[1],
|
||||||
|
color_cube[2], color_cube[3]);
|
||||||
|
gtk_widget_set_default_visual (gtk_preview_get_visual ());
|
||||||
|
gtk_widget_set_default_colormap (gtk_preview_get_cmap ());
|
||||||
|
|
||||||
|
|
||||||
|
dlg = gtk_dialog_new ();
|
||||||
|
gtk_window_set_title (GTK_WINDOW (dlg), "GEE! The GIMP E'er Egg!");
|
||||||
|
|
||||||
|
gtk_window_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (dlg), "delete_event",
|
||||||
|
(GtkSignalFunc) window_delete_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* Action area - 'close' button only. */
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label ("** Thank you for choosing GIMP **");
|
||||||
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||||
|
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
|
||||||
|
(GtkSignalFunc) window_close_callback,
|
||||||
|
GTK_OBJECT (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);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
/* The 'playback' half of the dialog */
|
||||||
|
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 3);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
hbox = gtk_hbox_new (FALSE, 5);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox), 3);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
||||||
|
|
||||||
|
{
|
||||||
|
vbox = gtk_vbox_new (FALSE, 5);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (vbox), 3);
|
||||||
|
gtk_container_add (GTK_CONTAINER (hbox), vbox);
|
||||||
|
|
||||||
|
{
|
||||||
|
hbox2 = gtk_hbox_new (TRUE, 0);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox2), 0);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
|
||||||
|
{
|
||||||
|
frame2 = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox2), frame2, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
eventbox = gtk_event_box_new();
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame2), GTK_WIDGET (eventbox));
|
||||||
|
|
||||||
|
{
|
||||||
|
preview =
|
||||||
|
GTK_PREVIEW (gtk_preview_new (rgb_mode?
|
||||||
|
GTK_PREVIEW_COLOR:
|
||||||
|
GTK_PREVIEW_GRAYSCALE));
|
||||||
|
gtk_preview_size (preview, width, height);
|
||||||
|
gtk_container_add (GTK_CONTAINER (eventbox),
|
||||||
|
GTK_WIDGET (preview));
|
||||||
|
gtk_widget_show(GTK_WIDGET (preview));
|
||||||
|
}
|
||||||
|
gtk_widget_show(eventbox);
|
||||||
|
gtk_widget_set_events (eventbox,
|
||||||
|
gtk_widget_get_events (eventbox)
|
||||||
|
| GDK_BUTTON_PRESS_MASK);
|
||||||
|
}
|
||||||
|
gtk_widget_show(frame2);
|
||||||
|
}
|
||||||
|
gtk_widget_show(hbox2);
|
||||||
|
}
|
||||||
|
gtk_widget_show(vbox);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(hbox);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(frame);
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_show(dlg);
|
||||||
|
|
||||||
|
|
||||||
|
idle_tag = gtk_idle_add_priority (
|
||||||
|
GTK_PRIORITY_LOW,
|
||||||
|
(GtkFunction) step_callback,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event",
|
||||||
|
GTK_SIGNAL_FUNC (toggle_feedbacktype), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void do_playback()
|
||||||
|
{
|
||||||
|
layers = gimp_image_get_layers (image_id, &total_frames);
|
||||||
|
imagetype = gimp_image_base_type(image_id);
|
||||||
|
|
||||||
|
if (imagetype == INDEXED)
|
||||||
|
palette = gimp_image_get_cmap(image_id, &ncolours);
|
||||||
|
|
||||||
|
/* cache hint */
|
||||||
|
gimp_tile_cache_ntiles (MAX(drawable->width,drawable->height)/
|
||||||
|
MIN(gimp_tile_width(),gimp_tile_height())
|
||||||
|
+1);
|
||||||
|
|
||||||
|
init_preview_misc();
|
||||||
|
build_dialog(gimp_image_base_type(image_id),
|
||||||
|
gimp_image_get_filename(image_id));
|
||||||
|
|
||||||
|
|
||||||
|
render_frame();
|
||||||
|
show_frame();
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
gdk_flush ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Rendering Functions */
|
||||||
|
|
||||||
|
/* Adam's silly algorithm. */
|
||||||
|
void domap1(unsigned char *src, unsigned char *dest,
|
||||||
|
int bx, int by, int cx, int cy)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int dy __attribute__ ((aligned));
|
||||||
|
signed int bycxmcybx __attribute__ ((aligned));
|
||||||
|
signed int bx2,by2 __attribute__ ((aligned));
|
||||||
|
signed int cx2,cy2 __attribute__ ((aligned));
|
||||||
|
unsigned int __attribute__ ((aligned)) basesx;
|
||||||
|
unsigned int __attribute__ ((aligned)) basesy;
|
||||||
|
#else
|
||||||
|
unsigned int dy;
|
||||||
|
signed int bycxmcybx;
|
||||||
|
signed int bx2,by2;
|
||||||
|
signed int cx2,cy2;
|
||||||
|
unsigned int basesx;
|
||||||
|
unsigned int basesy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bycxmcybx = (by*cx-cy*bx);
|
||||||
|
|
||||||
|
/* A little sub-pixel jitter to liven things up. */
|
||||||
|
basesx = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cx+bx)))<<11);
|
||||||
|
basesy = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cy+by)))<<11);
|
||||||
|
|
||||||
|
bx2 = ((bx)<<19)/bycxmcybx;
|
||||||
|
cx2 = ((cx)<<19)/bycxmcybx;
|
||||||
|
by2 = ((by)<<19)/bycxmcybx;
|
||||||
|
cy2 = ((cy)<<19)/bycxmcybx;
|
||||||
|
|
||||||
|
for (dy=0;dy<256;dy++)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int __attribute__ ((aligned)) sx;
|
||||||
|
unsigned int __attribute__ ((aligned)) sy;
|
||||||
|
unsigned int __attribute__ ((aligned)) dx;
|
||||||
|
#else
|
||||||
|
unsigned int sx;
|
||||||
|
unsigned int sy;
|
||||||
|
unsigned int dx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sx = (basesx-=bx2);
|
||||||
|
sy = (basesy+=cx2);
|
||||||
|
|
||||||
|
dx = 256;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*dest++ = (*(src +
|
||||||
|
(
|
||||||
|
(
|
||||||
|
((255&(
|
||||||
|
(sx>>11)
|
||||||
|
)))
|
||||||
|
|
|
||||||
|
((((255&(
|
||||||
|
(sy>>11)
|
||||||
|
))<<8)))
|
||||||
|
)
|
||||||
|
)));
|
||||||
|
;
|
||||||
|
sx += by2;
|
||||||
|
sy -= cy2;
|
||||||
|
}
|
||||||
|
while (--dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3bypp variant */
|
||||||
|
void domap3(unsigned char *src, unsigned char *dest,
|
||||||
|
int bx, int by, int cx, int cy)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int dy __attribute__ ((aligned));
|
||||||
|
signed int bycxmcybx __attribute__ ((aligned));
|
||||||
|
signed int bx2,by2 __attribute__ ((aligned));
|
||||||
|
signed int cx2,cy2 __attribute__ ((aligned));
|
||||||
|
unsigned int __attribute__ ((aligned)) basesx;
|
||||||
|
unsigned int __attribute__ ((aligned)) basesy;
|
||||||
|
#else
|
||||||
|
unsigned int dy;
|
||||||
|
signed int bycxmcybx;
|
||||||
|
signed int bx2,by2;
|
||||||
|
signed int cx2,cy2;
|
||||||
|
unsigned int basesx;
|
||||||
|
unsigned int basesy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bycxmcybx = (by*cx-cy*bx);
|
||||||
|
|
||||||
|
/* A little sub-pixel jitter to liven things up. */
|
||||||
|
basesx = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cx+bx)))<<11);
|
||||||
|
basesy = (((RAND_FUNC ()%89)<<19)/bycxmcybx) + ((-128-((128*256)/(cy+by)))<<11);
|
||||||
|
|
||||||
|
bx2 = ((bx)<<19)/bycxmcybx;
|
||||||
|
cx2 = ((cx)<<19)/bycxmcybx;
|
||||||
|
by2 = ((by)<<19)/bycxmcybx;
|
||||||
|
cy2 = ((cy)<<19)/bycxmcybx;
|
||||||
|
|
||||||
|
for (dy=0;dy<256;dy++)
|
||||||
|
{
|
||||||
|
#ifdef __GNUC__
|
||||||
|
unsigned int __attribute__ ((aligned)) sx;
|
||||||
|
unsigned int __attribute__ ((aligned)) sy;
|
||||||
|
unsigned int __attribute__ ((aligned)) dx;
|
||||||
|
#else
|
||||||
|
unsigned int sx;
|
||||||
|
unsigned int sy;
|
||||||
|
unsigned int dx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sx = (basesx-=bx2);
|
||||||
|
sy = (basesy+=cx2);
|
||||||
|
|
||||||
|
dx = 256;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
unsigned char* addr;
|
||||||
|
|
||||||
|
addr = src + 3*
|
||||||
|
(
|
||||||
|
(
|
||||||
|
((255&(
|
||||||
|
(sx>>11)
|
||||||
|
)))
|
||||||
|
|
|
||||||
|
((((255&(
|
||||||
|
(sy>>11)
|
||||||
|
))<<8)))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
*dest++ = *(addr);
|
||||||
|
*dest++ = *(addr+1);
|
||||||
|
*dest++ = *(addr+2);
|
||||||
|
|
||||||
|
sx += by2;
|
||||||
|
sy -= cy2;
|
||||||
|
}
|
||||||
|
while (--dx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_frame(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
static int frame = 0;
|
||||||
|
unsigned char* tmp;
|
||||||
|
static gint xp=128, yp=128;
|
||||||
|
gint rxp, ryp;
|
||||||
|
GdkModifierType mask;
|
||||||
|
gint pixels;
|
||||||
|
|
||||||
|
pixels = width*height*(rgb_mode?3:1);
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
|
||||||
|
tmp = preview_data2;
|
||||||
|
preview_data2 = preview_data1;
|
||||||
|
preview_data1 = tmp;
|
||||||
|
|
||||||
|
if (frame==0)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data2[i] =
|
||||||
|
preview_data1[i] =
|
||||||
|
seed_data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_window_get_pointer (eventbox->window, &rxp, &ryp, &mask);
|
||||||
|
|
||||||
|
if ((abs(rxp)>60)||(abs(ryp)>60))
|
||||||
|
{
|
||||||
|
xp = rxp;
|
||||||
|
yp = ryp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgb_mode)
|
||||||
|
{
|
||||||
|
domap3(preview_data2, preview_data1,
|
||||||
|
-(yp-xp)/2, xp+yp
|
||||||
|
,
|
||||||
|
xp+yp, (yp-xp)/2
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i=0;i<height;i++)
|
||||||
|
{
|
||||||
|
gtk_preview_draw_row (preview,
|
||||||
|
&preview_data1[i*width*3],
|
||||||
|
0, i, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame != 0)
|
||||||
|
{
|
||||||
|
if (feedbacktype)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
t = preview_data1[i] + seed_data[i] - 128;
|
||||||
|
preview_data1[i] = CLAMP(t,0,255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data1[i] = (preview_data1[i]*2 + seed_data[i]) /3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* GRAYSCALE */
|
||||||
|
{
|
||||||
|
domap1(preview_data2, preview_data1,
|
||||||
|
-(yp-xp)/2, xp+yp
|
||||||
|
,
|
||||||
|
xp+yp, (yp-xp)/2
|
||||||
|
);
|
||||||
|
|
||||||
|
for (i=0;i<height;i++)
|
||||||
|
{
|
||||||
|
gtk_preview_draw_row (preview,
|
||||||
|
&preview_data1[i*width],
|
||||||
|
0, i, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame != 0)
|
||||||
|
{
|
||||||
|
if (feedbacktype)
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
t = preview_data1[i] + seed_data[i] - 128;
|
||||||
|
preview_data1[i] = CLAMP(t,0,255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=0;i<pixels;i++)
|
||||||
|
{
|
||||||
|
preview_data1[i] = (preview_data1[i]*2 + seed_data[i]) /3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_frame(void)
|
||||||
|
{
|
||||||
|
/* Tell GTK to physically draw the preview */
|
||||||
|
gtk_widget_draw (GTK_WIDGET (preview), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_preview_misc(void)
|
||||||
|
{
|
||||||
|
GPixelRgn pixel_rgn;
|
||||||
|
int i;
|
||||||
|
gboolean has_alpha;
|
||||||
|
|
||||||
|
if ((imagetype == RGB)||(imagetype == INDEXED))
|
||||||
|
rgb_mode = TRUE;
|
||||||
|
else
|
||||||
|
rgb_mode = FALSE;
|
||||||
|
|
||||||
|
has_alpha = gimp_drawable_has_alpha(drawable->id);
|
||||||
|
|
||||||
|
seed_data = g_malloc(width*height*4);
|
||||||
|
preview_data1 = g_malloc(width*height*(rgb_mode?3:1));
|
||||||
|
preview_data2 = g_malloc(width*height*(rgb_mode?3:1));
|
||||||
|
|
||||||
|
if ((drawable->width<256) || (drawable->height<256))
|
||||||
|
{
|
||||||
|
for (i=0;i<256;i++)
|
||||||
|
{
|
||||||
|
if (i < drawable->height)
|
||||||
|
{
|
||||||
|
gimp_pixel_rgn_init (&pixel_rgn,
|
||||||
|
drawable,
|
||||||
|
drawable->width>256?
|
||||||
|
(drawable->width/2-128):0,
|
||||||
|
(drawable->height>256?
|
||||||
|
(drawable->height/2-128):0)+i,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
1,
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
gimp_pixel_rgn_get_rect (&pixel_rgn,
|
||||||
|
&seed_data[(256*i +
|
||||||
|
(
|
||||||
|
(
|
||||||
|
drawable->width<256 ?
|
||||||
|
(256-drawable->width)/2 :
|
||||||
|
0
|
||||||
|
)
|
||||||
|
+
|
||||||
|
(
|
||||||
|
drawable->height<256 ?
|
||||||
|
(256-drawable->height)/2 :
|
||||||
|
0
|
||||||
|
) * 256
|
||||||
|
)) *
|
||||||
|
gimp_drawable_bpp
|
||||||
|
(drawable->id)
|
||||||
|
],
|
||||||
|
drawable->width>256?
|
||||||
|
(drawable->width/2-128):0,
|
||||||
|
(drawable->height>256?
|
||||||
|
(drawable->height/2-128):0)+i,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_pixel_rgn_init (&pixel_rgn,
|
||||||
|
drawable,
|
||||||
|
drawable->width>256?(drawable->width/2-128):0,
|
||||||
|
drawable->height>256?(drawable->height/2-128):0,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
MIN(256,drawable->height),
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
gimp_pixel_rgn_get_rect (&pixel_rgn,
|
||||||
|
seed_data,
|
||||||
|
drawable->width>256?(drawable->width/2-128):0,
|
||||||
|
drawable->height>256?(drawable->height/2-128):0,
|
||||||
|
MIN(256,drawable->width),
|
||||||
|
MIN(256,drawable->height));
|
||||||
|
}
|
||||||
|
|
||||||
|
gimp_drawable_detach(drawable);
|
||||||
|
|
||||||
|
|
||||||
|
/* convert the image data of varying types into flat grey or rgb. */
|
||||||
|
switch (imagetype)
|
||||||
|
{
|
||||||
|
case INDEXED:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=width*height;i>0;i--)
|
||||||
|
{
|
||||||
|
seed_data[3*(i-1)+2] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+2]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[3*(i-1)+1] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+1]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[3*(i-1)+0] =
|
||||||
|
((palette[3*(seed_data[(i-1)*2])+0]*seed_data[(i-1)*2+1])/255)
|
||||||
|
+ ((255-seed_data[(i-1)*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=width*height;i>0;i--)
|
||||||
|
{
|
||||||
|
seed_data[3*(i-1)+2] = palette[3*(seed_data[i-1])+2];
|
||||||
|
seed_data[3*(i-1)+1] = palette[3*(seed_data[i-1])+1];
|
||||||
|
seed_data[3*(i-1)+0] = palette[3*(seed_data[i-1])+0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GRAY:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=0;i<width*height;i++)
|
||||||
|
{
|
||||||
|
seed_data[i] =
|
||||||
|
(seed_data[i*2]*seed_data[i*2+1])/255
|
||||||
|
+ ((255-seed_data[i*2+1])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RGB:
|
||||||
|
if (has_alpha)
|
||||||
|
{
|
||||||
|
for (i=0;i<width*height;i++)
|
||||||
|
{
|
||||||
|
seed_data[i*3+2] =
|
||||||
|
(seed_data[i*4+2]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[i*3+1] =
|
||||||
|
(seed_data[i*4+1]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
seed_data[i*3+0] =
|
||||||
|
(seed_data[i*4+0]*seed_data[i*4+3])/255
|
||||||
|
+ ((255-seed_data[i*4+3])*(RAND_FUNC ()%256))/255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Util. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_step(void)
|
||||||
|
{
|
||||||
|
render_frame();
|
||||||
|
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Callbacks */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
window_delete_callback (GtkWidget *widget,
|
||||||
|
GdkEvent *event,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
gtk_idle_remove (idle_tag);
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
gtk_main_quit();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
window_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
gtk_widget_destroy(GTK_WIDGET(data));
|
||||||
|
|
||||||
|
window_delete_callback (NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
toggle_feedbacktype (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
feedbacktype = !feedbacktype;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gint
|
||||||
|
step_callback (gpointer data)
|
||||||
|
{
|
||||||
|
do_step();
|
||||||
|
show_frame();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
Makefile.in
|
||||||
|
Makefile
|
||||||
|
.deps
|
||||||
|
_libs
|
||||||
|
.libs
|
||||||
|
screenshot
|
|
@ -0,0 +1,39 @@
|
||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
pluginlibdir = $(gimpplugindir)/plug-ins
|
||||||
|
|
||||||
|
pluginlib_PROGRAMS = screenshot
|
||||||
|
|
||||||
|
screenshot_SOURCES = \
|
||||||
|
screenshot.c
|
||||||
|
|
||||||
|
INCLUDES = \
|
||||||
|
$(X_CFLAGS) \
|
||||||
|
-I$(top_srcdir) \
|
||||||
|
-I$(includedir)
|
||||||
|
|
||||||
|
LDADD = \
|
||||||
|
$(top_builddir)/libgimp/libgimpui.la \
|
||||||
|
$(top_builddir)/libgimp/libgimp.la \
|
||||||
|
$(X_LIBS) \
|
||||||
|
\
|
||||||
|
-lc
|
||||||
|
|
||||||
|
DEPS = \
|
||||||
|
$(top_builddir)/libgimp/libgimpui.la \
|
||||||
|
$(top_builddir)/libgimp/libgimp.la
|
||||||
|
|
||||||
|
screenshot_DEPENDENCIES = $(DEPS)
|
||||||
|
|
||||||
|
.PHONY: files
|
||||||
|
|
||||||
|
files:
|
||||||
|
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
|
||||||
|
echo $$p; \
|
||||||
|
done
|
||||||
|
@for subdir in $(SUBDIRS); do \
|
||||||
|
files=`cd $$subdir; $(MAKE) files | grep -v "make\[[1-9]\]"`; \
|
||||||
|
for file in $$files; do \
|
||||||
|
echo $$subdir/$$file; \
|
||||||
|
done; \
|
||||||
|
done
|
|
@ -0,0 +1,506 @@
|
||||||
|
/*
|
||||||
|
* ScreenShot plug-in v0.6 by Sven Neumann, neumanns@uni-duesseldorf.de
|
||||||
|
* 1998/04/18
|
||||||
|
*
|
||||||
|
* Any suggestions, bug-reports or patches are very welcome.
|
||||||
|
*
|
||||||
|
* This plug-in uses the X-utility xwd to grab an image from the screen
|
||||||
|
* and the xwd-plug-in created by Peter Kirchgessner (pkirchg@aol.com)
|
||||||
|
* to load this image into the gimp.
|
||||||
|
* Hence its nothing but a simple frontend to those utilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The GIMP -- an image manipulation program
|
||||||
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||||
|
*
|
||||||
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Revision history
|
||||||
|
* (98/02/18) v0.1 first development release
|
||||||
|
* (98/02/19) v0.2 small bugfix
|
||||||
|
* (98/03/09) v0.3 another one
|
||||||
|
* (98/03/13) v0.4 cosmetic changes to the dialog
|
||||||
|
* (98/04/02) v0.5 it works non-interactively now and registers
|
||||||
|
* itself correctly as extension
|
||||||
|
* (98/04/18) v0.6 cosmetic change to the dialog
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "gtk/gtk.h"
|
||||||
|
#include "libgimp/gimp.h"
|
||||||
|
|
||||||
|
/* Defines */
|
||||||
|
#define PLUG_IN_NAME "extension_screenshot"
|
||||||
|
#define PLUG_IN_PRINT_NAME "Screen Shot"
|
||||||
|
#define PLUG_IN_VERSION "v0.6 (98/04/18)"
|
||||||
|
#define PLUG_IN_MENU_PATH "<Toolbox>/Xtns/Screen Shot"
|
||||||
|
#define PLUG_IN_AUTHOR "Sven Neumann (neumanns@uni-duesseldorf.de)"
|
||||||
|
#define PLUG_IN_COPYRIGHT "Sven Neumann"
|
||||||
|
#define PLUG_IN_DESCRIBTION "Create a screenshot of a single window or the whole screen"
|
||||||
|
#define PLUG_IN_HELP "This extension serves as a simple frontend to the X-window utility xwd and the xwd-file-plug-in. After specifying some options, xwd is called, the user selects a window, and the resulting image is loaded into the gimp. When called non-interactively it may grab the root window or use the window-id passed as a parameter."
|
||||||
|
|
||||||
|
#define NUMBER_IN_ARGS 3
|
||||||
|
#define IN_ARGS { PARAM_INT32, "run_mode", "Interactive, non-interactive" },\
|
||||||
|
{ PARAM_INT32, "root", "Root window { TRUE, FALSE }" },\
|
||||||
|
{ PARAM_STRING, "window_id", "Window id" }
|
||||||
|
|
||||||
|
#define NUMBER_OUT_ARGS 1
|
||||||
|
#define OUT_ARGS { PARAM_IMAGE, "image", "Output image" }
|
||||||
|
|
||||||
|
#ifndef XWD
|
||||||
|
#define XWD "xwd"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
gint root;
|
||||||
|
gchar *window_id;
|
||||||
|
gint decor;
|
||||||
|
} ScreenShotValues;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GtkWidget *decor_button;
|
||||||
|
GtkWidget *single_button;
|
||||||
|
GtkWidget *root_button;
|
||||||
|
gint run;
|
||||||
|
} ScreenShotInterface;
|
||||||
|
|
||||||
|
static ScreenShotValues shootvals =
|
||||||
|
{
|
||||||
|
FALSE, /* default to window */
|
||||||
|
NULL,
|
||||||
|
TRUE /* default to decorations */
|
||||||
|
};
|
||||||
|
|
||||||
|
static ScreenShotInterface shootint =
|
||||||
|
{
|
||||||
|
FALSE /* run */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void query (void);
|
||||||
|
static void run (gchar *name,
|
||||||
|
gint nparams, /* number of parameters passed in */
|
||||||
|
GParam * param, /* parameters passed in */
|
||||||
|
gint *nreturn_vals, /* number of parameters returned */
|
||||||
|
GParam ** return_vals); /* parameters to be returned */
|
||||||
|
static void shoot (void);
|
||||||
|
static gint shoot_dialog (void);
|
||||||
|
static void shoot_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static void shoot_ok_callback (GtkWidget *widget,
|
||||||
|
gpointer data);
|
||||||
|
static void shoot_toggle_update (GtkWidget *widget,
|
||||||
|
gpointer radio_button);
|
||||||
|
static void shoot_display_image (gint32 image);
|
||||||
|
|
||||||
|
/* Global Variables */
|
||||||
|
GPlugInInfo PLUG_IN_INFO =
|
||||||
|
{
|
||||||
|
NULL, /* init_proc */
|
||||||
|
NULL, /* quit_proc */
|
||||||
|
query, /* query_proc */
|
||||||
|
run /* run_proc */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* the image that will be returned */
|
||||||
|
gint32 image_ID = -1;
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
|
||||||
|
MAIN ()
|
||||||
|
|
||||||
|
static void query (void)
|
||||||
|
{
|
||||||
|
static GParamDef args[] = { IN_ARGS };
|
||||||
|
static gint nargs = NUMBER_IN_ARGS;
|
||||||
|
static GParamDef return_vals[] = { OUT_ARGS };
|
||||||
|
static gint nreturn_vals = NUMBER_OUT_ARGS;
|
||||||
|
|
||||||
|
/* the actual installation of the plugin */
|
||||||
|
gimp_install_procedure (PLUG_IN_NAME,
|
||||||
|
PLUG_IN_DESCRIBTION,
|
||||||
|
PLUG_IN_HELP,
|
||||||
|
PLUG_IN_AUTHOR,
|
||||||
|
PLUG_IN_COPYRIGHT,
|
||||||
|
PLUG_IN_VERSION,
|
||||||
|
PLUG_IN_MENU_PATH,
|
||||||
|
NULL,
|
||||||
|
PROC_EXTENSION,
|
||||||
|
nargs,
|
||||||
|
nreturn_vals,
|
||||||
|
args,
|
||||||
|
return_vals);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run (gchar *name, /* name of plugin */
|
||||||
|
gint nparams, /* number of in-paramters */
|
||||||
|
GParam * param, /* in-parameters */
|
||||||
|
gint *nreturn_vals, /* number of out-parameters */
|
||||||
|
GParam ** return_vals) /* out-parameters */
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Get the runmode from the in-parameters */
|
||||||
|
GRunModeType run_mode = param[0].data.d_int32;
|
||||||
|
|
||||||
|
/* status variable, use it to check for errors in invocation usualy only
|
||||||
|
during non-interactive calling */
|
||||||
|
GStatusType status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
/*always return at least the status to the caller. */
|
||||||
|
static GParam values[1];
|
||||||
|
|
||||||
|
/* initialize the return of the status */
|
||||||
|
values[0].type = PARAM_STATUS;
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
*nreturn_vals = 1;
|
||||||
|
*return_vals = values;
|
||||||
|
|
||||||
|
/*how are we running today? */
|
||||||
|
switch (run_mode)
|
||||||
|
{
|
||||||
|
case RUN_INTERACTIVE:
|
||||||
|
/* Possibly retrieve data from a previous run */
|
||||||
|
gimp_get_data (PLUG_IN_NAME, &shootvals);
|
||||||
|
shootvals.window_id = NULL;
|
||||||
|
|
||||||
|
/* Get information from the dialog */
|
||||||
|
if (!shoot_dialog())
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUN_NONINTERACTIVE:
|
||||||
|
if (nparams == NUMBER_IN_ARGS)
|
||||||
|
{
|
||||||
|
shootvals.root = (gint) param[1].data.d_int32;
|
||||||
|
shootvals.window_id = (gchar*) param[2].data.d_string;
|
||||||
|
shootvals.decor = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
status = STATUS_CALLING_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUN_WITH_LAST_VALS:
|
||||||
|
/* Possibly retrieve data from a previous run */
|
||||||
|
gimp_get_data (PLUG_IN_NAME, &shootvals);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
} /* switch */
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Run the main function */
|
||||||
|
shoot();
|
||||||
|
|
||||||
|
/* Store variable states for next run */
|
||||||
|
if (run_mode == RUN_INTERACTIVE)
|
||||||
|
gimp_set_data (PLUG_IN_NAME, &shootvals, sizeof (ScreenShotValues));
|
||||||
|
}
|
||||||
|
|
||||||
|
status = (image_ID != -1) ? STATUS_SUCCESS : STATUS_EXECUTION_ERROR;
|
||||||
|
|
||||||
|
if (status == STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
if (run_mode == RUN_INTERACTIVE)
|
||||||
|
{
|
||||||
|
/* display the image */
|
||||||
|
shoot_display_image (image_ID);
|
||||||
|
}
|
||||||
|
/* set return values */
|
||||||
|
*nreturn_vals = 2;
|
||||||
|
values[1].type = PARAM_IMAGE;
|
||||||
|
values[1].data.d_image = image_ID;
|
||||||
|
}
|
||||||
|
values[0].data.d_status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The main ScreenShot function */
|
||||||
|
static void
|
||||||
|
shoot (void)
|
||||||
|
{
|
||||||
|
GParam *params;
|
||||||
|
gint retvals;
|
||||||
|
char *tmpname;
|
||||||
|
char *xwdargv[7]; /* only need a maximum of 7 arguments to xwd */
|
||||||
|
gint pid;
|
||||||
|
gint status;
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
|
/* get a temp name with the right extension and save into it. */
|
||||||
|
params = gimp_run_procedure ("gimp_temp_name",
|
||||||
|
&retvals,
|
||||||
|
PARAM_STRING, "xwd",
|
||||||
|
PARAM_END);
|
||||||
|
tmpname = params[1].data.d_string;
|
||||||
|
|
||||||
|
/* construct the xwd arguments */
|
||||||
|
xwdargv[i++] = XWD;
|
||||||
|
xwdargv[i++] = "-out";
|
||||||
|
xwdargv[i++] = tmpname;
|
||||||
|
if ( shootvals.root == TRUE )
|
||||||
|
xwdargv[i++] = "-root";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (shootvals.decor == TRUE )
|
||||||
|
xwdargv[i++] = "-frame";
|
||||||
|
if (shootvals.window_id != NULL)
|
||||||
|
{
|
||||||
|
xwdargv[i++] = "-id";
|
||||||
|
xwdargv[i++] = shootvals.window_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xwdargv[i] = NULL;
|
||||||
|
|
||||||
|
/* fork off a xwd process */
|
||||||
|
if ((pid = fork ()) < 0)
|
||||||
|
{
|
||||||
|
g_warning ("screenshot: fork failed: %s\n", g_strerror (errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (pid == 0)
|
||||||
|
{
|
||||||
|
execvp (XWD, xwdargv);
|
||||||
|
/* What are we doing here? exec must have failed */
|
||||||
|
g_warning ("screenshot: exec failed: xwd: %s\n", g_strerror (errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waitpid (pid, &status, 0);
|
||||||
|
|
||||||
|
if (!WIFEXITED (status))
|
||||||
|
{
|
||||||
|
g_warning ("screenshot: xwd didn't work\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now load the tmpfile using the xwd-plug-in */
|
||||||
|
params = gimp_run_procedure ("file_xwd_load",
|
||||||
|
&retvals,
|
||||||
|
PARAM_INT32, 1,
|
||||||
|
PARAM_STRING, tmpname,
|
||||||
|
PARAM_STRING, tmpname,
|
||||||
|
PARAM_END);
|
||||||
|
image_ID = params[1].data.d_image;
|
||||||
|
|
||||||
|
/* get rid of the tmpfile */
|
||||||
|
unlink (tmpname);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ScreenShot dialog */
|
||||||
|
|
||||||
|
static gint
|
||||||
|
shoot_dialog (void)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog;
|
||||||
|
GtkWidget *frame;
|
||||||
|
GtkWidget *vbox;
|
||||||
|
GtkWidget *button;
|
||||||
|
GtkWidget *hbox;
|
||||||
|
GtkWidget *radio_label;
|
||||||
|
GSList *radio_group = NULL;
|
||||||
|
gint radio_pressed[2];
|
||||||
|
gint decorations;
|
||||||
|
gint argc = 1;
|
||||||
|
gchar **argv = g_new (gchar *, 1);
|
||||||
|
argv[0] = g_strdup ("ScreenShot");
|
||||||
|
|
||||||
|
radio_pressed[0] = (shootvals.root == FALSE);
|
||||||
|
radio_pressed[1] = (shootvals.root == TRUE);
|
||||||
|
decorations = shootvals.decor;
|
||||||
|
|
||||||
|
/* Init GTK */
|
||||||
|
gtk_init (&argc, &argv);
|
||||||
|
gtk_rc_parse (gimp_gtkrc ());
|
||||||
|
|
||||||
|
gdk_set_use_xshm (gimp_use_xshm ());
|
||||||
|
|
||||||
|
/* Main Dialog */
|
||||||
|
dialog = gtk_dialog_new ();
|
||||||
|
gtk_window_set_title (GTK_WINDOW (dialog), PLUG_IN_PRINT_NAME);
|
||||||
|
gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
|
||||||
|
(GtkSignalFunc) shoot_close_callback,
|
||||||
|
NULL);
|
||||||
|
/* Action area */
|
||||||
|
button = gtk_button_new_with_label ("Grab");
|
||||||
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||||
|
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||||
|
(GtkSignalFunc) shoot_ok_callback,
|
||||||
|
dialog);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->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 (dialog));
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
|
||||||
|
button, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (button);
|
||||||
|
|
||||||
|
/* Single Window */
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
vbox = gtk_vbox_new (FALSE, 4);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (vbox), 4);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (vbox),
|
||||||
|
hbox, TRUE, TRUE, 0);
|
||||||
|
shootint.single_button = gtk_radio_button_new ( radio_group );
|
||||||
|
radio_group = gtk_radio_button_group ( GTK_RADIO_BUTTON (shootint.single_button) );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox),
|
||||||
|
shootint.single_button, TRUE, TRUE, 0);
|
||||||
|
gtk_signal_connect ( GTK_OBJECT (shootint.single_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&radio_pressed[0]);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.single_button),
|
||||||
|
radio_pressed[0]);
|
||||||
|
gtk_widget_show (shootint.single_button);
|
||||||
|
radio_label = gtk_label_new ( "Grab a single window" );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox),
|
||||||
|
radio_label, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (radio_label);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
|
/* with decorations */
|
||||||
|
hbox = gtk_hbox_new (FALSE, 0);
|
||||||
|
gtk_box_pack_end (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
|
||||||
|
shootint.decor_button = gtk_check_button_new_with_label ("Include decorations");
|
||||||
|
gtk_signal_connect (GTK_OBJECT (shootint.decor_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&decorations);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.decor_button),
|
||||||
|
decorations);
|
||||||
|
gtk_box_pack_end (GTK_BOX (hbox), shootint.decor_button, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_set_sensitive (shootint.decor_button, radio_pressed[0]);
|
||||||
|
gtk_widget_show (shootint.decor_button);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
|
gtk_widget_show (vbox);
|
||||||
|
gtk_widget_show (frame);
|
||||||
|
|
||||||
|
/* Root Window */
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (frame), 4);
|
||||||
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
|
||||||
|
frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 4);
|
||||||
|
gtk_container_border_width (GTK_CONTAINER (hbox), 4);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
||||||
|
|
||||||
|
shootint.root_button = gtk_radio_button_new ( radio_group );
|
||||||
|
radio_group = gtk_radio_button_group ( GTK_RADIO_BUTTON (shootint.root_button) );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), shootint.root_button, TRUE, TRUE, 0);
|
||||||
|
gtk_signal_connect ( GTK_OBJECT (shootint.root_button), "toggled",
|
||||||
|
(GtkSignalFunc) shoot_toggle_update,
|
||||||
|
&radio_pressed[1]);
|
||||||
|
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (shootint.root_button),
|
||||||
|
radio_pressed[1]);
|
||||||
|
gtk_widget_show (shootint.root_button);
|
||||||
|
|
||||||
|
radio_label = gtk_label_new ( "Grab the whole screen" );
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), radio_label, TRUE, TRUE, 0);
|
||||||
|
gtk_widget_show (radio_label);
|
||||||
|
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
gtk_widget_show (frame);
|
||||||
|
|
||||||
|
gtk_widget_show (dialog);
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
gdk_flush ();
|
||||||
|
|
||||||
|
shootvals.root = radio_pressed[1];
|
||||||
|
shootvals.decor = decorations;
|
||||||
|
|
||||||
|
return shootint.run;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ScreenShot interface functions */
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_close_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
gtk_main_quit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_ok_callback (GtkWidget *widget,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
shootint.run = TRUE;
|
||||||
|
gtk_widget_destroy (GTK_WIDGET (data));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shoot_toggle_update (GtkWidget *widget,
|
||||||
|
gpointer radio_button)
|
||||||
|
{
|
||||||
|
gint *toggle_val;
|
||||||
|
|
||||||
|
toggle_val = (gint *) radio_button;
|
||||||
|
|
||||||
|
if (GTK_TOGGLE_BUTTON (widget)->active)
|
||||||
|
*toggle_val = TRUE;
|
||||||
|
else
|
||||||
|
*toggle_val = FALSE;
|
||||||
|
|
||||||
|
if (widget == shootint.single_button)
|
||||||
|
gtk_widget_set_sensitive (shootint.decor_button, *toggle_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display function */
|
||||||
|
|
||||||
|
void
|
||||||
|
shoot_display_image (gint32 image)
|
||||||
|
{
|
||||||
|
GParam *params;
|
||||||
|
gint retvals;
|
||||||
|
|
||||||
|
params = gimp_run_procedure ("gimp_display_new",
|
||||||
|
&retvals,
|
||||||
|
PARAM_IMAGE, image,
|
||||||
|
PARAM_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,7 @@ script_fu_add_script (LISP a)
|
||||||
int i;
|
int i;
|
||||||
gdouble color[3];
|
gdouble color[3];
|
||||||
LISP color_list;
|
LISP color_list;
|
||||||
|
gchar *menu_path = NULL;
|
||||||
|
|
||||||
/* Check the length of a */
|
/* Check the length of a */
|
||||||
if (nlength (a) < 7)
|
if (nlength (a) < 7)
|
||||||
|
@ -293,6 +294,10 @@ script_fu_add_script (LISP a)
|
||||||
script->description = g_strdup (val);
|
script->description = g_strdup (val);
|
||||||
a = cdr (a);
|
a = cdr (a);
|
||||||
|
|
||||||
|
/* Allow scripts with no menus */
|
||||||
|
if (strncmp(val, "<None>", 6) != 0)
|
||||||
|
menu_path = script->description;
|
||||||
|
|
||||||
/* Find the script help */
|
/* Find the script help */
|
||||||
val = get_c_string (car (a));
|
val = get_c_string (car (a));
|
||||||
script->help = g_strdup (val);
|
script->help = g_strdup (val);
|
||||||
|
@ -458,7 +463,7 @@ script_fu_add_script (LISP a)
|
||||||
script->author,
|
script->author,
|
||||||
script->copyright,
|
script->copyright,
|
||||||
script->date,
|
script->date,
|
||||||
script->description,
|
menu_path,
|
||||||
script->img_types,
|
script->img_types,
|
||||||
PROC_TEMPORARY,
|
PROC_TEMPORARY,
|
||||||
script->num_args + 1, 0,
|
script->num_args + 1, 0,
|
||||||
|
|
|
@ -275,6 +275,7 @@ script_fu_add_script (LISP a)
|
||||||
int i;
|
int i;
|
||||||
gdouble color[3];
|
gdouble color[3];
|
||||||
LISP color_list;
|
LISP color_list;
|
||||||
|
gchar *menu_path = NULL;
|
||||||
|
|
||||||
/* Check the length of a */
|
/* Check the length of a */
|
||||||
if (nlength (a) < 7)
|
if (nlength (a) < 7)
|
||||||
|
@ -293,6 +294,10 @@ script_fu_add_script (LISP a)
|
||||||
script->description = g_strdup (val);
|
script->description = g_strdup (val);
|
||||||
a = cdr (a);
|
a = cdr (a);
|
||||||
|
|
||||||
|
/* Allow scripts with no menus */
|
||||||
|
if (strncmp(val, "<None>", 6) != 0)
|
||||||
|
menu_path = script->description;
|
||||||
|
|
||||||
/* Find the script help */
|
/* Find the script help */
|
||||||
val = get_c_string (car (a));
|
val = get_c_string (car (a));
|
||||||
script->help = g_strdup (val);
|
script->help = g_strdup (val);
|
||||||
|
@ -458,7 +463,7 @@ script_fu_add_script (LISP a)
|
||||||
script->author,
|
script->author,
|
||||||
script->copyright,
|
script->copyright,
|
||||||
script->date,
|
script->date,
|
||||||
script->description,
|
menu_path,
|
||||||
script->img_types,
|
script->img_types,
|
||||||
PROC_TEMPORARY,
|
PROC_TEMPORARY,
|
||||||
script->num_args + 1, 0,
|
script->num_args + 1, 0,
|
||||||
|
|
Loading…
Reference in New Issue