1997-11-25 06:05:25 +08:00
|
|
|
/*
|
2009-11-20 17:23:13 +08:00
|
|
|
* Animation Playback plug-in version 0.99.1
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2000-01-14 04:47:30 +08:00
|
|
|
* (c) Adam D. Moss : 1997-2000 : adam@gimp.org : adam@foxbox.org
|
2009-11-20 17:23:13 +08:00
|
|
|
* (c) Mircea Purdea : 2009 : someone_else@exhalus.net
|
1997-11-25 06:05:25 +08:00
|
|
|
*
|
2006-12-10 05:33:38 +08:00
|
|
|
* GIMP - The GNU Image Manipulation Program
|
2004-05-26 04:16:07 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
1998-04-19 02:42:24 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-05-26 04:16:07 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-05-26 04:16:07 +08:00
|
|
|
* (at your option) any later version.
|
1998-04-19 02:42:24 +08:00
|
|
|
*
|
2004-05-26 04:16:07 +08:00
|
|
|
* 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.
|
1998-04-19 02:42:24 +08:00
|
|
|
*
|
2004-05-26 04:16:07 +08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* pdb interface - should we bother?
|
1998-04-19 02:42:24 +08:00
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
* speedups (caching? most bottlenecks seem to be in pixelrgns)
|
1998-04-19 02:42:24 +08:00
|
|
|
* -> do pixelrgns properly!
|
|
|
|
*
|
2009-11-20 17:23:13 +08:00
|
|
|
* write other half of the user interface (zoom, disposal &c)
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-18 00:50:00 +08:00
|
|
|
|
1999-10-03 08:43:05 +08:00
|
|
|
#include "config.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
1999-10-03 08:43:05 +08:00
|
|
|
|
2000-01-13 23:39:26 +08:00
|
|
|
#include <libgimp/gimp.h>
|
2011-04-15 03:16:40 +08:00
|
|
|
#undef GDK_DISABLE_DEPRECATED
|
2000-01-13 23:39:26 +08:00
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1999-09-26 13:16:19 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
#define PLUG_IN_PROC "plug-in-animationplay"
|
2008-03-24 23:29:55 +08:00
|
|
|
#define PLUG_IN_BINARY "animation-play"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-animation-play"
|
2005-08-14 02:29:14 +08:00
|
|
|
#define DITHERTYPE GDK_RGB_DITHER_NORMAL
|
|
|
|
|
1998-07-19 20:02:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DISPOSE_UNDEFINED = 0x00,
|
|
|
|
DISPOSE_COMBINE = 0x01,
|
|
|
|
DISPOSE_REPLACE = 0x02
|
|
|
|
} DisposeType;
|
|
|
|
|
|
|
|
|
|
|
|
/* Declare local functions. */
|
2006-04-19 20:11:00 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
static void do_playback (void);
|
|
|
|
|
|
|
|
static void window_destroy (GtkWidget *widget);
|
|
|
|
static void play_callback (GtkToggleAction *action);
|
|
|
|
static void step_callback (GtkAction *action);
|
|
|
|
static void rewind_callback (GtkAction *action);
|
|
|
|
static void speed_up_callback (GtkAction *action);
|
|
|
|
static void speed_down_callback (GtkAction *action);
|
|
|
|
static void speed_reset_callback (GtkAction *action);
|
2009-11-20 17:23:13 +08:00
|
|
|
static void speedcombo_changed (GtkWidget *combo,
|
|
|
|
gpointer data);
|
|
|
|
static void fpscombo_changed (GtkWidget *combo,
|
2007-06-21 04:04:33 +08:00
|
|
|
gpointer data);
|
2007-06-18 14:51:51 +08:00
|
|
|
static gboolean repaint_sda (GtkWidget *darea,
|
|
|
|
GdkEventExpose *event,
|
|
|
|
gpointer data);
|
|
|
|
static gboolean repaint_da (GtkWidget *darea,
|
|
|
|
GdkEventExpose *event,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void render_frame (gint32 whichframe);
|
|
|
|
static void show_frame (void);
|
|
|
|
static void total_alpha_preview (guchar *ptr);
|
|
|
|
static void init_preview (void);
|
2007-06-21 04:04:33 +08:00
|
|
|
static void update_combobox (void);
|
|
|
|
static gdouble get_duration_factor (gint index);
|
2009-11-20 17:23:13 +08:00
|
|
|
static gint get_fps (gint index);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2000-01-14 04:47:30 +08:00
|
|
|
/* tag util functions*/
|
2007-06-18 14:51:51 +08:00
|
|
|
static gint parse_ms_tag (const gchar *str);
|
|
|
|
static DisposeType parse_disposal_tag (const gchar *str);
|
|
|
|
static DisposeType get_frame_disposal (guint whichframe);
|
|
|
|
static guint32 get_frame_duration (guint whichframe);
|
|
|
|
static gboolean is_disposal_tag (const gchar *str,
|
|
|
|
DisposeType *disposal,
|
|
|
|
gint *taglength);
|
|
|
|
static gboolean is_ms_tag (const gchar *str,
|
|
|
|
gint *duration,
|
|
|
|
gint *taglength);
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-05-01 05:03:44 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
query, /* query_proc */
|
2000-05-01 05:03:44 +08:00
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Global widgets'n'stuff */
|
2006-02-28 16:25:34 +08:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
static GtkUIManager *ui_manager = NULL;
|
|
|
|
static guchar *preview_data = NULL;
|
|
|
|
static GtkWidget *drawing_area = NULL;
|
|
|
|
static GtkWidget *shape_drawing_area = NULL;
|
2003-12-24 06:07:06 +08:00
|
|
|
static guchar *shape_drawing_area_data = NULL;
|
2006-02-28 16:25:34 +08:00
|
|
|
static guchar *drawing_area_data = NULL;
|
2006-03-09 16:08:13 +08:00
|
|
|
static GtkWidget *progress;
|
2003-12-24 06:07:06 +08:00
|
|
|
static guint width, height;
|
|
|
|
static guchar *preview_alpha1_data;
|
|
|
|
static guchar *preview_alpha2_data;
|
|
|
|
static gint32 image_id;
|
|
|
|
static gint32 total_frames;
|
|
|
|
static guint frame_number;
|
|
|
|
static gint32 *layers;
|
|
|
|
static gboolean playing = FALSE;
|
2006-02-28 16:25:34 +08:00
|
|
|
static guint timer = 0;
|
2003-12-24 06:07:06 +08:00
|
|
|
static GimpImageBaseType imagetype;
|
|
|
|
static guchar *palette;
|
|
|
|
static gint ncolours;
|
2007-06-21 04:04:33 +08:00
|
|
|
static gint duration_index = 3;
|
2009-11-20 17:23:13 +08:00
|
|
|
static gint default_frame_duration = 100; /* ms */
|
2007-06-18 14:51:51 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-04-19 02:42:24 +08:00
|
|
|
/* for shaping */
|
2004-05-07 08:30:24 +08:00
|
|
|
typedef struct
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
} CursorOffset;
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
static gchar *shape_preview_mask = NULL;
|
|
|
|
static GtkWidget *shape_window = NULL;
|
|
|
|
static GdkWindow *root_win = NULL;
|
|
|
|
static gboolean detached = FALSE;
|
2007-06-21 04:04:33 +08:00
|
|
|
static GtkWidget *speedcombo = NULL;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
MAIN ()
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-08-14 02:29:14 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
1999-12-21 21:57:58 +08:00
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_install_procedure (PLUG_IN_PROC,
|
2006-03-17 17:29:48 +08:00
|
|
|
N_("Preview a GIMP layer-based animation"),
|
2003-12-24 06:07:06 +08:00
|
|
|
"",
|
|
|
|
"Adam D. Moss <adam@gimp.org>",
|
|
|
|
"Adam D. Moss <adam@gimp.org>",
|
|
|
|
"1997, 1998...",
|
2004-05-07 08:30:24 +08:00
|
|
|
N_("_Playback..."),
|
2003-12-24 06:07:06 +08:00
|
|
|
"RGB*, INDEXED*, GRAY*",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (args), 0,
|
|
|
|
args, NULL);
|
2004-05-07 08:30:24 +08:00
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Filters/Animation");
|
2006-06-17 20:21:47 +08:00
|
|
|
gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_STOCK_ID,
|
|
|
|
(const guint8 *) GTK_STOCK_MEDIA_PLAY);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
static void
|
|
|
|
run (const gchar *name,
|
|
|
|
gint n_params,
|
|
|
|
const GimpParam *param,
|
2003-07-02 02:54:28 +08:00
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-08-14 02:29:14 +08:00
|
|
|
static GimpParam values[1];
|
|
|
|
GimpRunMode run_mode;
|
2000-08-22 09:26:57 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2005-08-14 02:29:14 +08:00
|
|
|
*return_vals = values;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
if (run_mode == GIMP_RUN_NONINTERACTIVE && n_params != 3)
|
2003-03-26 00:38:19 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
1999-12-21 21:57:58 +08:00
|
|
|
{
|
|
|
|
image_id = param[1].data.d_image;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
do_playback ();
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_displays_flush ();
|
1999-12-21 21:57:58 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
1997-11-25 06:05:25 +08:00
|
|
|
values[0].data.d_status = status;
|
|
|
|
}
|
|
|
|
|
1998-04-19 02:42:24 +08:00
|
|
|
static void
|
2006-02-26 06:04:19 +08:00
|
|
|
reshape_from_bitmap (const gchar *bitmap)
|
1998-04-19 02:42:24 +08:00
|
|
|
{
|
1998-07-20 04:08:36 +08:00
|
|
|
static gchar *prev_bitmap = NULL;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
1998-07-20 04:08:36 +08:00
|
|
|
if ((!prev_bitmap) ||
|
2006-02-26 06:04:19 +08:00
|
|
|
(memcmp (prev_bitmap, bitmap, (width * height) / 8 + height)))
|
1998-07-20 04:08:36 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
GdkBitmap *shape_mask;
|
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
shape_mask = gdk_bitmap_create_from_data (gtk_widget_get_window (shape_window),
|
2005-04-08 21:11:07 +08:00
|
|
|
bitmap,
|
|
|
|
width, height);
|
1998-07-20 04:08:36 +08:00
|
|
|
gtk_widget_shape_combine_mask (shape_window, shape_mask, 0, 0);
|
2001-12-02 23:43:00 +08:00
|
|
|
g_object_unref (shape_mask);
|
1998-07-20 04:08:36 +08:00
|
|
|
|
|
|
|
if (!prev_bitmap)
|
2006-02-26 06:04:19 +08:00
|
|
|
prev_bitmap = g_malloc ((width * height) / 8 + height);
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
memcpy (prev_bitmap, bitmap, (width * height) / 8 + height);
|
1998-07-20 04:08:36 +08:00
|
|
|
}
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
2006-06-22 17:34:01 +08:00
|
|
|
popup_menu (GtkWidget *widget,
|
2006-03-09 17:50:03 +08:00
|
|
|
GdkEventButton *event)
|
1998-04-19 02:42:24 +08:00
|
|
|
{
|
2006-06-22 17:34:01 +08:00
|
|
|
GtkWidget *menu = gtk_ui_manager_get_widget (ui_manager, "/anim-play-popup");
|
2006-02-26 06:04:19 +08:00
|
|
|
|
2006-06-22 17:34:01 +08:00
|
|
|
gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
|
|
|
|
gtk_menu_popup (GTK_MENU (menu),
|
|
|
|
NULL, NULL, NULL, NULL,
|
|
|
|
event ? event->button : 0,
|
|
|
|
event ? event->time : gtk_get_current_event_time ());
|
2006-02-26 06:04:19 +08:00
|
|
|
|
2006-06-22 17:34:01 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2011-10-02 22:23:59 +08:00
|
|
|
if (gdk_event_triggers_context_menu ((GdkEvent *) event))
|
2006-06-22 17:34:01 +08:00
|
|
|
return popup_menu (widget, event);
|
2006-02-26 06:04:19 +08:00
|
|
|
|
2006-03-09 17:50:03 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-03-09 17:50:03 +08:00
|
|
|
static gboolean
|
|
|
|
shape_pressed (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2006-06-22 17:34:01 +08:00
|
|
|
if (button_press (widget, event))
|
2006-03-09 17:50:03 +08:00
|
|
|
return TRUE;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2006-03-09 17:50:03 +08:00
|
|
|
/* ignore double and triple click */
|
|
|
|
if (event->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
CursorOffset *p = g_object_get_data (G_OBJECT(widget), "cursor-offset");
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
p->x = (gint) event->x;
|
|
|
|
p->y = (gint) event->y;
|
|
|
|
|
|
|
|
gtk_grab_add (widget);
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_pointer_grab (gtk_widget_get_window (widget), TRUE,
|
2006-03-09 17:50:03 +08:00
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK,
|
|
|
|
NULL, NULL, 0);
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_window_raise (gtk_widget_get_window (widget));
|
2006-03-09 17:50:03 +08:00
|
|
|
}
|
2002-06-08 07:47:04 +08:00
|
|
|
|
|
|
|
return FALSE;
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
2003-10-30 04:57:21 +08:00
|
|
|
maybeblocked_expose (GtkWidget *widget,
|
2003-12-24 06:07:06 +08:00
|
|
|
GdkEventExpose *event)
|
1998-07-19 20:02:29 +08:00
|
|
|
{
|
|
|
|
if (playing)
|
2002-06-08 07:47:04 +08:00
|
|
|
return TRUE;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
return repaint_sda (widget, event, NULL);
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
1998-04-19 02:42:24 +08:00
|
|
|
shape_released (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_grab_remove (widget);
|
2003-10-30 04:57:21 +08:00
|
|
|
gdk_display_pointer_ungrab (gtk_widget_get_display (widget), 0);
|
2003-12-24 06:07:06 +08:00
|
|
|
gdk_flush ();
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
1998-04-19 02:42:24 +08:00
|
|
|
shape_motion (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event)
|
|
|
|
{
|
2003-12-24 06:07:06 +08:00
|
|
|
GdkModifierType mask;
|
2006-02-28 16:25:34 +08:00
|
|
|
gint xp, yp;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
|
|
|
gdk_window_get_pointer (root_win, &xp, &yp, &mask);
|
|
|
|
|
|
|
|
/* if a button is still held by the time we process this event... */
|
2006-02-27 19:50:57 +08:00
|
|
|
if (mask & GDK_BUTTON1_MASK)
|
1998-04-19 02:42:24 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
CursorOffset *p = g_object_get_data (G_OBJECT (widget), "cursor-offset");
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
if (!p)
|
|
|
|
return FALSE;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
gtk_window_move (GTK_WINDOW (widget), xp - p->x, yp - p->y);
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
else /* the user has released all buttons */
|
|
|
|
{
|
2006-02-27 19:50:57 +08:00
|
|
|
shape_released (widget);
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
2002-06-08 07:47:04 +08:00
|
|
|
|
|
|
|
return FALSE;
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
2003-10-30 04:57:21 +08:00
|
|
|
repaint_da (GtkWidget *darea,
|
2002-06-08 07:47:04 +08:00
|
|
|
GdkEventExpose *event,
|
2003-12-24 06:07:06 +08:00
|
|
|
gpointer data)
|
1998-07-19 20:02:29 +08:00
|
|
|
{
|
2008-06-29 02:40:23 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (darea);
|
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (darea),
|
2008-06-29 02:40:23 +08:00
|
|
|
style->white_gc,
|
2003-12-24 06:07:06 +08:00
|
|
|
0, 0, width, height,
|
2006-02-26 06:04:19 +08:00
|
|
|
(total_frames == 1) ? GDK_RGB_DITHER_MAX : DITHERTYPE,
|
2003-12-24 06:07:06 +08:00
|
|
|
drawing_area_data, width * 3);
|
2002-06-08 07:47:04 +08:00
|
|
|
|
|
|
|
return TRUE;
|
1998-07-19 20:02:29 +08:00
|
|
|
}
|
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
static gboolean
|
2003-10-30 04:57:21 +08:00
|
|
|
repaint_sda (GtkWidget *darea,
|
2002-06-08 07:47:04 +08:00
|
|
|
GdkEventExpose *event,
|
2003-12-24 06:07:06 +08:00
|
|
|
gpointer data)
|
1998-07-19 20:02:29 +08:00
|
|
|
{
|
2008-06-29 02:40:23 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (darea);
|
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (darea),
|
2008-06-29 02:40:23 +08:00
|
|
|
style->white_gc,
|
2003-12-24 06:07:06 +08:00
|
|
|
0, 0, width, height,
|
2006-02-26 06:04:19 +08:00
|
|
|
(total_frames == 1) ? GDK_RGB_DITHER_MAX : DITHERTYPE,
|
2003-12-24 06:07:06 +08:00
|
|
|
shape_drawing_area_data, width * 3);
|
2002-06-08 07:47:04 +08:00
|
|
|
|
|
|
|
return TRUE;
|
1998-07-19 20:02:29 +08:00
|
|
|
}
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
static void
|
|
|
|
close_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
1998-04-19 02:42:24 +08:00
|
|
|
{
|
2006-02-26 06:40:52 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (data));
|
2006-02-26 06:04:19 +08:00
|
|
|
}
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
static void
|
|
|
|
help_callback (GtkAction *action,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gimp_standard_help_func (PLUG_IN_PROC, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
static void
|
|
|
|
detach_callback (GtkToggleAction *action)
|
|
|
|
{
|
|
|
|
gboolean active = gtk_toggle_action_get_active (action);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
if (active == detached)
|
|
|
|
{
|
2006-04-19 20:11:00 +08:00
|
|
|
g_warning ("detached state and toggle action got out of sync");
|
2006-02-26 06:04:19 +08:00
|
|
|
return;
|
|
|
|
}
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
detached = active;
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
if (detached)
|
|
|
|
{
|
|
|
|
/* Create a total-alpha buffer merely for the not-shaped
|
|
|
|
drawing area to now display. */
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
drawing_area_data = g_malloc (width * height * 3);
|
|
|
|
total_alpha_preview (drawing_area_data);
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (shape_window),
|
|
|
|
gtk_widget_get_screen (drawing_area));
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2010-04-20 01:21:07 +08:00
|
|
|
if (gtk_widget_get_realized (drawing_area))
|
2006-02-26 06:04:19 +08:00
|
|
|
{
|
|
|
|
gint x, y;
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_window_get_origin (gtk_widget_get_window (drawing_area), &x, &y);
|
2006-02-27 19:50:57 +08:00
|
|
|
|
|
|
|
gtk_window_move (GTK_WINDOW (shape_window), x + 6, y + 6);
|
2006-02-26 06:04:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show (shape_window);
|
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_window_set_back_pixmap (gtk_widget_get_window (shape_drawing_area), NULL, TRUE);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
memset (shape_preview_mask, 0, (width * height) / 8 + height);
|
|
|
|
render_frame (frame_number);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (drawing_area_data);
|
|
|
|
drawing_area_data = shape_drawing_area_data;
|
|
|
|
|
|
|
|
render_frame (frame_number);
|
|
|
|
|
|
|
|
gtk_widget_hide (shape_window);
|
|
|
|
}
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
gtk_widget_queue_draw (drawing_area);
|
1998-04-19 02:42:24 +08:00
|
|
|
}
|
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
static GtkUIManager *
|
|
|
|
ui_manager_new (GtkWidget *window)
|
|
|
|
{
|
|
|
|
static GtkActionEntry actions[] =
|
|
|
|
{
|
|
|
|
{ "step", GTK_STOCK_MEDIA_NEXT,
|
|
|
|
N_("_Step"), NULL, N_("Step to next frame"),
|
|
|
|
G_CALLBACK (step_callback) },
|
|
|
|
|
|
|
|
{ "rewind", GTK_STOCK_MEDIA_REWIND,
|
2006-03-09 16:08:13 +08:00
|
|
|
NULL, NULL, N_("Rewind the animation"),
|
2006-02-26 06:40:52 +08:00
|
|
|
G_CALLBACK (rewind_callback) },
|
|
|
|
|
|
|
|
{ "help", GTK_STOCK_HELP,
|
|
|
|
NULL, NULL, NULL,
|
2006-03-09 19:02:47 +08:00
|
|
|
G_CALLBACK (help_callback) },
|
|
|
|
|
|
|
|
{ "close", GTK_STOCK_CLOSE,
|
|
|
|
NULL, "<control>W", NULL,
|
|
|
|
G_CALLBACK (close_callback)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"quit", GTK_STOCK_QUIT,
|
|
|
|
NULL, "<control>Q", NULL,
|
|
|
|
G_CALLBACK (close_callback)
|
2007-06-18 14:51:51 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"speed-up", NULL,
|
|
|
|
N_("Faster"), "<control>L", N_("Increase the speed of the animation"),
|
|
|
|
G_CALLBACK (speed_up_callback)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"speed-down", NULL,
|
|
|
|
N_("Slower"), "<control>J", N_("Decrease the speed of the animation"),
|
|
|
|
G_CALLBACK (speed_down_callback)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"speed-reset", NULL,
|
|
|
|
N_("Reset speed"), "<control>K", N_("Reset the speed of the animation"),
|
|
|
|
G_CALLBACK (speed_reset_callback)
|
2006-03-09 19:02:47 +08:00
|
|
|
}
|
2005-09-19 20:17:39 +08:00
|
|
|
};
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
static GtkToggleActionEntry toggle_actions[] =
|
|
|
|
{
|
2006-02-26 07:18:59 +08:00
|
|
|
{ "play", GTK_STOCK_MEDIA_PLAY,
|
2006-03-09 16:08:13 +08:00
|
|
|
NULL, NULL, N_("Start playback"),
|
2006-02-26 07:18:59 +08:00
|
|
|
G_CALLBACK (play_callback), FALSE },
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
{ "detach", GIMP_STOCK_DETACH,
|
|
|
|
N_("Detach"), NULL,
|
|
|
|
N_("Detach the animation from the dialog window"),
|
|
|
|
G_CALLBACK (detach_callback), FALSE }
|
|
|
|
};
|
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
GtkUIManager *ui_manager = gtk_ui_manager_new ();
|
|
|
|
GtkActionGroup *group = gtk_action_group_new ("Actions");
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
gtk_action_group_set_translation_domain (group, NULL);
|
2006-02-26 06:04:19 +08:00
|
|
|
|
|
|
|
gtk_action_group_add_actions (group,
|
|
|
|
actions,
|
|
|
|
G_N_ELEMENTS (actions),
|
|
|
|
window);
|
|
|
|
gtk_action_group_add_toggle_actions (group,
|
|
|
|
toggle_actions,
|
|
|
|
G_N_ELEMENTS (toggle_actions),
|
|
|
|
NULL);
|
2005-09-19 20:17:39 +08:00
|
|
|
|
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (window),
|
|
|
|
gtk_ui_manager_get_accel_group (ui_manager));
|
|
|
|
gtk_accel_group_lock (gtk_ui_manager_get_accel_group (ui_manager));
|
|
|
|
|
|
|
|
gtk_ui_manager_insert_action_group (ui_manager, group, -1);
|
|
|
|
g_object_unref (group);
|
|
|
|
|
|
|
|
gtk_ui_manager_add_ui_from_string (ui_manager,
|
|
|
|
"<ui>"
|
|
|
|
" <toolbar name=\"anim-play-toolbar\">"
|
|
|
|
" <toolitem action=\"play\" />"
|
|
|
|
" <toolitem action=\"step\" />"
|
|
|
|
" <toolitem action=\"rewind\" />"
|
2006-02-26 06:04:19 +08:00
|
|
|
" <separator />"
|
|
|
|
" <toolitem action=\"detach\" />"
|
2006-02-26 06:40:52 +08:00
|
|
|
" <separator name=\"space\" />"
|
|
|
|
" <toolitem action=\"help\" />"
|
2006-03-09 19:02:47 +08:00
|
|
|
" </toolbar>"
|
|
|
|
" <accelerator action=\"close\" />"
|
|
|
|
" <accelerator action=\"quit\" />"
|
2005-09-19 20:17:39 +08:00
|
|
|
"</ui>",
|
|
|
|
-1, &error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("error parsing ui: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
gtk_ui_manager_add_ui_from_string (ui_manager,
|
|
|
|
"<ui>"
|
|
|
|
" <popup name=\"anim-play-popup\">"
|
|
|
|
" <menuitem action=\"play\" />"
|
|
|
|
" <menuitem action=\"step\" />"
|
|
|
|
" <menuitem action=\"rewind\" />"
|
|
|
|
" <separator />"
|
2007-06-18 14:51:51 +08:00
|
|
|
" <menuitem action=\"speed-down\" />"
|
|
|
|
" <menuitem action=\"speed-up\" />"
|
|
|
|
" <menuitem action=\"speed-reset\" />"
|
|
|
|
" <separator />"
|
2006-02-26 06:04:19 +08:00
|
|
|
" <menuitem action=\"detach\" />"
|
|
|
|
" <menuitem action=\"close\" />"
|
|
|
|
" </popup>"
|
|
|
|
"</ui>",
|
|
|
|
-1, &error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("error parsing ui: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
return ui_manager;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2000-08-22 09:26:57 +08:00
|
|
|
build_dialog (GimpImageBaseType basetype,
|
2003-12-24 06:07:06 +08:00
|
|
|
gchar *imagename)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-26 06:40:52 +08:00
|
|
|
GtkWidget *toolbar;
|
|
|
|
GtkWidget *frame;
|
2007-06-21 04:04:33 +08:00
|
|
|
GtkWidget *main_vbox;
|
2006-02-26 06:40:52 +08:00
|
|
|
GtkWidget *vbox;
|
2007-06-21 04:04:33 +08:00
|
|
|
GtkWidget *hbox;
|
2006-02-26 06:40:52 +08:00
|
|
|
GtkWidget *abox;
|
|
|
|
GtkToolItem *item;
|
2007-06-18 14:51:51 +08:00
|
|
|
GtkAction *action;
|
2006-02-26 06:40:52 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
gchar *name;
|
2007-06-21 04:04:33 +08:00
|
|
|
gint index;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-14 02:29:14 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
name = g_strconcat (_("Animation Playback:"), " ", imagename, NULL);
|
2000-01-07 00:40:17 +08:00
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), name);
|
|
|
|
gtk_window_set_role (GTK_WINDOW (window), "animation-playback");
|
2000-01-07 00:40:17 +08:00
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
g_free (name);
|
2000-01-07 00:40:17 +08:00
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (window_destroy),
|
2002-06-08 07:47:04 +08:00
|
|
|
NULL);
|
2006-06-22 17:34:01 +08:00
|
|
|
g_signal_connect (window, "popup-menu",
|
|
|
|
G_CALLBACK (popup_menu),
|
|
|
|
NULL);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
gimp_help_connect (window, gimp_standard_help_func, PLUG_IN_PROC, NULL);
|
|
|
|
|
|
|
|
ui_manager = ui_manager_new (window);
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
2004-05-18 20:54:26 +08:00
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
toolbar = gtk_ui_manager_get_widget (ui_manager, "/anim-play-toolbar");
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, FALSE, 0);
|
2005-09-19 20:17:39 +08:00
|
|
|
gtk_widget_show (toolbar);
|
2004-05-18 20:54:26 +08:00
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
item =
|
|
|
|
GTK_TOOL_ITEM (gtk_ui_manager_get_widget (ui_manager,
|
|
|
|
"/anim-play-toolbar/space"));
|
|
|
|
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
|
|
|
|
gtk_tool_item_set_expand (item, TRUE);
|
2005-09-20 00:05:52 +08:00
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), abox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (abox);
|
2004-05-18 20:54:26 +08:00
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), frame);
|
|
|
|
gtk_widget_show (frame);
|
2004-05-18 20:54:26 +08:00
|
|
|
|
|
|
|
drawing_area = gtk_drawing_area_new ();
|
|
|
|
gtk_widget_set_size_request (drawing_area, width, height);
|
2006-03-09 17:50:03 +08:00
|
|
|
gtk_widget_add_events (drawing_area, GDK_BUTTON_PRESS_MASK);
|
2006-03-09 16:08:13 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), drawing_area);
|
2004-05-18 20:54:26 +08:00
|
|
|
gtk_widget_show (drawing_area);
|
|
|
|
|
2006-03-09 17:50:03 +08:00
|
|
|
g_signal_connect (drawing_area, "button-press-event",
|
2006-06-22 17:34:01 +08:00
|
|
|
G_CALLBACK (button_press),
|
2006-03-09 17:50:03 +08:00
|
|
|
NULL);
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
progress = gtk_progress_bar_new ();
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), progress, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (progress);
|
|
|
|
|
2011-03-17 21:31:39 +08:00
|
|
|
speedcombo = gtk_combo_box_text_new ();
|
2009-11-20 17:23:13 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), speedcombo, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (speedcombo);
|
|
|
|
|
|
|
|
for (index = 0; index < 9; index++)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
/* list is given in "fps" - frames per second */
|
|
|
|
text = g_strdup_printf (_("%d fps"), get_fps (index));
|
2011-03-17 21:31:39 +08:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speedcombo), text);
|
2009-11-20 17:23:13 +08:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (speedcombo), 0);
|
|
|
|
|
|
|
|
g_signal_connect (speedcombo, "changed",
|
|
|
|
G_CALLBACK (fpscombo_changed),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_help_set_help_data (speedcombo, _("Default framerate"), NULL);
|
|
|
|
|
2011-03-17 21:31:39 +08:00
|
|
|
speedcombo = gtk_combo_box_text_new ();
|
2009-11-20 17:23:13 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), speedcombo, FALSE, FALSE, 0);
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_widget_show (speedcombo);
|
|
|
|
|
|
|
|
for (index = 0; index < 7; index++)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
text = g_strdup_printf ("%g\303\227", (100 / get_duration_factor (index)) / 100);
|
2011-03-17 21:31:39 +08:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speedcombo), text);
|
2007-06-21 04:04:33 +08:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (speedcombo), 3);
|
|
|
|
|
|
|
|
g_signal_connect (speedcombo, "changed",
|
|
|
|
G_CALLBACK (speedcombo_changed),
|
|
|
|
NULL);
|
|
|
|
|
2007-11-09 19:17:00 +08:00
|
|
|
gimp_help_set_help_data (speedcombo, _("Playback speed"), NULL);
|
2007-06-21 04:04:33 +08:00
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
if (total_frames < 2)
|
|
|
|
{
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/ui/anim-play-toolbar/play");
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/ui/anim-play-toolbar/step");
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/ui/anim-play-toolbar/rewind");
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
}
|
2004-05-18 20:54:26 +08:00
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-reset");
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
|
2006-02-26 06:40:52 +08:00
|
|
|
gtk_widget_show (window);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2004-05-18 20:54:26 +08:00
|
|
|
/* let's get into shape. */
|
|
|
|
shape_window = gtk_window_new (GTK_WINDOW_POPUP);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2004-05-18 20:54:26 +08:00
|
|
|
shape_drawing_area = gtk_drawing_area_new ();
|
|
|
|
gtk_widget_set_size_request (shape_drawing_area, width, height);
|
|
|
|
gtk_container_add (GTK_CONTAINER (shape_window), shape_drawing_area);
|
|
|
|
gtk_widget_show (shape_drawing_area);
|
|
|
|
gtk_widget_add_events (shape_drawing_area, GDK_BUTTON_PRESS_MASK);
|
|
|
|
gtk_widget_realize (shape_window);
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_window_set_back_pixmap (gtk_widget_get_window (shape_window), NULL, FALSE);
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2004-05-18 20:54:26 +08:00
|
|
|
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (shape_window),
|
2006-02-26 06:04:19 +08:00
|
|
|
GDK_HAND2);
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_window_set_cursor (gtk_widget_get_window (shape_window), cursor);
|
2004-05-18 20:54:26 +08:00
|
|
|
gdk_cursor_unref (cursor);
|
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (shape_window, "button-press-event",
|
2006-02-26 06:04:19 +08:00
|
|
|
G_CALLBACK (shape_pressed),
|
|
|
|
NULL);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (shape_window, "button-release-event",
|
2006-02-26 06:04:19 +08:00
|
|
|
G_CALLBACK (shape_released),
|
|
|
|
NULL);
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (shape_window, "motion-notify-event",
|
2006-02-26 06:04:19 +08:00
|
|
|
G_CALLBACK (shape_motion),
|
|
|
|
NULL);
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
g_object_set_data (G_OBJECT (shape_window),
|
|
|
|
"cursor-offset", g_new0 (CursorOffset, 1));
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (drawing_area, "expose-event",
|
2006-02-26 06:04:19 +08:00
|
|
|
G_CALLBACK (repaint_da),
|
|
|
|
NULL);
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (shape_drawing_area, "expose-event",
|
2006-02-26 06:04:19 +08:00
|
|
|
G_CALLBACK (maybeblocked_expose),
|
|
|
|
NULL);
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2002-06-08 07:47:04 +08:00
|
|
|
root_win = gdk_get_default_root_window ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
do_playback (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-18 20:54:26 +08:00
|
|
|
width = gimp_image_width (image_id);
|
|
|
|
height = gimp_image_height (image_id);
|
1997-11-25 06:05:25 +08:00
|
|
|
layers = gimp_image_get_layers (image_id, &total_frames);
|
2004-05-18 20:54:26 +08:00
|
|
|
imagetype = gimp_image_base_type (image_id);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (imagetype == GIMP_INDEXED)
|
2005-04-08 21:11:07 +08:00
|
|
|
{
|
|
|
|
palette = gimp_image_get_colormap (image_id, &ncolours);
|
|
|
|
}
|
2000-08-22 09:26:57 +08:00
|
|
|
else if (imagetype == GIMP_GRAY)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-04-08 21:11:07 +08:00
|
|
|
gint i;
|
|
|
|
|
2006-04-19 20:11:00 +08:00
|
|
|
palette = g_new (guchar, 768);
|
2005-04-08 21:11:07 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
2006-04-19 20:11:00 +08:00
|
|
|
palette[i * 3] = palette[i * 3 + 1] = palette[i * 3 + 2] = i;
|
2005-04-08 21:11:07 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
ncolours = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_number = 0;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2006-04-19 20:11:00 +08:00
|
|
|
init_preview ();
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2002-05-08 08:30:26 +08:00
|
|
|
build_dialog (gimp_image_base_type (image_id),
|
|
|
|
gimp_image_get_name (image_id));
|
2003-10-30 04:57:21 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure that whole preview is dirtied with pure-alpha */
|
2005-04-08 21:11:07 +08:00
|
|
|
total_alpha_preview (preview_data);
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
render_frame (0);
|
|
|
|
show_frame ();
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rendering Functions */
|
|
|
|
|
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
render_frame (gint32 whichframe)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2008-06-29 02:40:23 +08:00
|
|
|
GtkStyle *shape_style = gtk_widget_get_style (shape_drawing_area);
|
|
|
|
GtkStyle *drawing_style = gtk_widget_get_style (drawing_area);
|
2012-09-22 06:46:05 +08:00
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint drawable_id;
|
1997-11-25 06:05:25 +08:00
|
|
|
static guchar *rawframe = NULL;
|
2003-12-24 06:07:06 +08:00
|
|
|
static gint rawwidth = 0, rawheight = 0, rawbpp = 0;
|
|
|
|
gint rawx = 0, rawy = 0;
|
|
|
|
guchar *srcptr;
|
|
|
|
guchar *destptr;
|
|
|
|
gint i, j, k; /* imaginative loop variables */
|
|
|
|
DisposeType dispose;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (whichframe >= total_frames)
|
|
|
|
{
|
1999-12-29 02:30:01 +08:00
|
|
|
printf( "playback: Asked for frame number %d in a %d-frame animation!\n",
|
2003-12-24 06:07:06 +08:00
|
|
|
(int) (whichframe+1), (int) total_frames);
|
2005-03-04 23:12:29 +08:00
|
|
|
gimp_quit ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
drawable_id = layers[total_frames - (whichframe + 1)];
|
|
|
|
|
|
|
|
buffer = gimp_drawable_get_buffer (drawable_id);
|
|
|
|
|
2000-08-17 03:11:27 +08:00
|
|
|
/* Lame attempt to catch the case that a user has closed the image. */
|
2012-09-22 06:46:05 +08:00
|
|
|
if (!buffer)
|
2000-08-17 03:11:27 +08:00
|
|
|
{
|
2006-02-14 20:08:34 +08:00
|
|
|
gimp_message (_("Tried to display an invalid layer."));
|
2000-08-17 03:11:27 +08:00
|
|
|
gtk_main_quit ();
|
|
|
|
return;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-12-24 06:07:06 +08:00
|
|
|
dispose = get_frame_disposal (frame_number);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
if (((dispose == DISPOSE_REPLACE) || (whichframe == 0)) &&
|
2012-09-22 06:46:05 +08:00
|
|
|
gimp_drawable_has_alpha (drawable_id))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-12-24 06:07:06 +08:00
|
|
|
total_alpha_preview (preview_data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* only get a new 'raw' drawable-data buffer if this and
|
2006-04-19 20:11:00 +08:00
|
|
|
the previous raw buffer were different sizes */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-04-19 20:11:00 +08:00
|
|
|
if ((rawwidth * rawheight * rawbpp) !=
|
2012-09-22 06:46:05 +08:00
|
|
|
((gimp_drawable_width (drawable_id) *
|
|
|
|
gimp_drawable_height (drawable_id) *
|
|
|
|
gimp_drawable_has_alpha (drawable_id) ? 4 : 3)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-12-24 06:07:06 +08:00
|
|
|
if (rawframe != NULL)
|
2005-04-08 21:11:07 +08:00
|
|
|
g_free (rawframe);
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
rawwidth = gimp_drawable_width (drawable_id);
|
|
|
|
rawheight = gimp_drawable_height (drawable_id);
|
|
|
|
rawbpp = gimp_drawable_has_alpha (drawable_id) ? 4 : 3;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
rawframe = g_malloc (rawwidth * rawheight * rawbpp);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Initialise and fetch the whole raw new frame */
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, rawwidth, rawheight), 1.0,
|
|
|
|
gimp_drawable_has_alpha (drawable_id) ?
|
|
|
|
babl_format ("R'G'B'A u8") :
|
|
|
|
babl_format ("R'G'B' u8"),
|
|
|
|
rawframe, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
gimp_drawable_offsets (drawable_id, &rawx, &rawy);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* render... */
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((rawwidth == width) &&
|
|
|
|
(rawheight == height) &&
|
|
|
|
(rawx == 0) &&
|
|
|
|
(rawy == 0))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
/* --- These cases are for the best cases, in --- */
|
|
|
|
/* --- which this frame is the same size and position --- */
|
|
|
|
/* --- as the preview buffer itself --- */
|
|
|
|
|
|
|
|
if (gimp_drawable_has_alpha (drawable_id))
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
destptr = preview_data;
|
|
|
|
srcptr = rawframe;
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
i = rawwidth * rawheight;
|
|
|
|
while (i--)
|
2006-02-28 16:25:34 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if (! (srcptr[3] & 128))
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr += 4;
|
|
|
|
destptr += 3;
|
|
|
|
continue;
|
|
|
|
}
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
*(destptr++) = *(srcptr++);
|
|
|
|
*(destptr++) = *(srcptr++);
|
|
|
|
*(destptr++) = *(srcptr++);
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate the shape mask */
|
|
|
|
if (detached)
|
|
|
|
{
|
|
|
|
srcptr = rawframe + 3;
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (j = 0; j < rawheight; j++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
k = j * ((7 + rawwidth) / 8);
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (i = 0; i < rawwidth; i++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((*srcptr) & 128)
|
|
|
|
shape_preview_mask[k + i/8] |= (1 << (i&7));
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr += 4;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-22 06:46:05 +08:00
|
|
|
}
|
|
|
|
else /* no alpha */
|
|
|
|
{
|
|
|
|
if ((rawwidth == width) && (rawheight == height))
|
|
|
|
memcpy (preview_data, rawframe, width * height * 3);
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
if (detached)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
/* opacify the shape mask */
|
|
|
|
memset (shape_preview_mask, 255,
|
|
|
|
(rawwidth * rawheight) / 8 + rawheight);
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-22 06:46:05 +08:00
|
|
|
|
|
|
|
/* Display the preview buffer... finally. */
|
|
|
|
if (detached)
|
|
|
|
{
|
|
|
|
reshape_from_bitmap (shape_preview_mask);
|
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (shape_drawing_area),
|
|
|
|
shape_style->white_gc,
|
|
|
|
0, 0, width, height,
|
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
|
|
|
preview_data, width * 3);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
reshape_from_bitmap (shape_preview_mask);
|
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (drawing_area),
|
|
|
|
drawing_style->white_gc,
|
|
|
|
0, 0, width, height,
|
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
|
|
|
preview_data, width * 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* --- These are suboptimal catch-all cases for when --- */
|
|
|
|
/* --- this frame is bigger/smaller than the preview --- */
|
|
|
|
/* --- buffer, and/or offset within it. --- */
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
if (gimp_drawable_has_alpha (drawable_id))
|
|
|
|
{
|
|
|
|
srcptr = rawframe;
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (j = rawy; j < rawheight + rawy; j++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
for (i = rawx; i < rawwidth + rawx; i++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((i >= 0 && i < width) &&
|
|
|
|
(j >= 0 && j < height))
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if (srcptr[3] & 128)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2005-04-08 21:11:07 +08:00
|
|
|
preview_data[(j * width + i) * 3 ] = *(srcptr);
|
|
|
|
preview_data[(j * width + i) * 3 + 1] = *(srcptr + 1);
|
|
|
|
preview_data[(j * width + i) * 3 + 2] = *(srcptr + 2);
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr += 4;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
if (detached)
|
2006-02-28 16:25:34 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr = rawframe + 3;
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (j = rawy; j < rawheight + rawy; j++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
k = j * ((width + 7) / 8);
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (i = rawx; i < rawwidth + rawx; i++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((i>=0 && i<width) &&
|
|
|
|
(j>=0 && j<height))
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((*srcptr) & 128)
|
2005-04-08 21:11:07 +08:00
|
|
|
shape_preview_mask[k + i/8] |= (1 << (i&7));
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
2012-09-22 06:46:05 +08:00
|
|
|
|
|
|
|
srcptr += 4;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-22 06:46:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* noalpha */
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr = rawframe;
|
2006-02-28 16:25:34 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
for (j = rawy; j < rawheight + rawy; j++)
|
|
|
|
{
|
|
|
|
for (i = rawx; i < rawwidth + rawx; i++)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((i >= 0 && i < width) &&
|
|
|
|
(j >= 0 && j < height))
|
|
|
|
{
|
|
|
|
preview_data[(j * width + i) * 3 ] = *(srcptr);
|
|
|
|
preview_data[(j * width + i) * 3 + 1] = *(srcptr + 1);
|
|
|
|
preview_data[(j * width + i) * 3 + 2] = *(srcptr + 2);
|
|
|
|
}
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
srcptr += 3;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-22 06:46:05 +08:00
|
|
|
}
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
/* Display the preview buffer... finally. */
|
|
|
|
if (detached)
|
|
|
|
{
|
|
|
|
if ((dispose != DISPOSE_REPLACE) && (whichframe != 0))
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
gint top = MAX (rawy, 0);
|
|
|
|
gint bottom = MIN (rawy + rawheight, height);
|
|
|
|
|
2003-12-24 06:07:06 +08:00
|
|
|
reshape_from_bitmap (shape_preview_mask);
|
2009-10-10 16:51:59 +08:00
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (shape_drawing_area),
|
2008-06-29 02:40:23 +08:00
|
|
|
shape_style->white_gc,
|
2012-09-22 06:46:05 +08:00
|
|
|
0, top, width, bottom - top,
|
2006-04-19 20:11:00 +08:00
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
2012-09-22 06:46:05 +08:00
|
|
|
preview_data + 3 * top * width,
|
|
|
|
width * 3);
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
reshape_from_bitmap (shape_preview_mask);
|
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (shape_drawing_area),
|
|
|
|
shape_style->white_gc,
|
2003-12-24 06:07:06 +08:00
|
|
|
0, 0, width, height,
|
2006-04-19 20:11:00 +08:00
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
2003-12-24 06:07:06 +08:00
|
|
|
preview_data, width * 3);
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
if ((dispose != DISPOSE_REPLACE) && (whichframe != 0))
|
2006-02-28 16:25:34 +08:00
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
gint top = MAX (rawy, 0);
|
|
|
|
gint bottom = MIN (rawy + rawheight, height);
|
2003-12-24 06:07:06 +08:00
|
|
|
|
2012-09-22 06:46:05 +08:00
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (drawing_area),
|
|
|
|
drawing_style->white_gc,
|
|
|
|
0, top, width, bottom - top,
|
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
|
|
|
preview_data + 3 * top * width,
|
|
|
|
width * 3);
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-22 06:46:05 +08:00
|
|
|
gdk_draw_rgb_image (gtk_widget_get_window (drawing_area),
|
|
|
|
drawing_style->white_gc,
|
|
|
|
0, 0, width, height,
|
|
|
|
(total_frames == 1 ?
|
|
|
|
GDK_RGB_DITHER_MAX : DITHERTYPE),
|
|
|
|
preview_data, width * 3);
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2003-10-30 04:57:21 +08:00
|
|
|
/* clean up */
|
2012-09-22 06:46:05 +08:00
|
|
|
g_object_unref (buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
show_frame (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-06-08 07:47:04 +08:00
|
|
|
gchar *text;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the dialog's progress bar */
|
2006-03-09 16:08:13 +08:00
|
|
|
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress),
|
2006-02-28 16:25:34 +08:00
|
|
|
((gfloat) frame_number /
|
|
|
|
(gfloat) (total_frames - 0.999)));
|
2002-06-08 07:47:04 +08:00
|
|
|
|
2004-03-04 19:56:17 +08:00
|
|
|
text = g_strdup_printf (_("Frame %d of %d"), frame_number + 1, total_frames);
|
2006-03-09 16:08:13 +08:00
|
|
|
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), text);
|
2002-06-08 07:47:04 +08:00
|
|
|
g_free (text);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-04-19 20:11:00 +08:00
|
|
|
init_preview (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
gint i;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
preview_data = g_malloc (width * height * 3);
|
|
|
|
shape_preview_mask = g_malloc ((width * height) / 8 + 1 + height);
|
|
|
|
preview_alpha1_data = g_malloc (width * 3);
|
|
|
|
preview_alpha2_data = g_malloc (width * 3);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
for (i = 0; i < width; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-26 06:04:19 +08:00
|
|
|
if (i & 8)
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2005-04-08 21:11:07 +08:00
|
|
|
preview_alpha1_data[i*3 + 0] =
|
|
|
|
preview_alpha1_data[i*3 + 1] =
|
|
|
|
preview_alpha1_data[i*3 + 2] = 102;
|
|
|
|
preview_alpha2_data[i*3 + 0] =
|
|
|
|
preview_alpha2_data[i*3 + 1] =
|
|
|
|
preview_alpha2_data[i*3 + 2] = 154;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2003-12-24 06:07:06 +08:00
|
|
|
{
|
2005-04-08 21:11:07 +08:00
|
|
|
preview_alpha1_data[i*3 + 0] =
|
|
|
|
preview_alpha1_data[i*3 + 1] =
|
|
|
|
preview_alpha1_data[i*3 + 2] = 154;
|
|
|
|
preview_alpha2_data[i*3 + 0] =
|
|
|
|
preview_alpha2_data[i*3 + 1] =
|
|
|
|
preview_alpha2_data[i*3 + 2] = 102;
|
2003-12-24 06:07:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-07-19 20:02:29 +08:00
|
|
|
|
|
|
|
drawing_area_data = preview_data;
|
|
|
|
shape_drawing_area_data = preview_data;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-26 06:04:19 +08:00
|
|
|
total_alpha_preview (guchar *ptr)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-26 06:04:19 +08:00
|
|
|
gint i;
|
2004-05-26 04:16:07 +08:00
|
|
|
|
2006-02-26 06:04:19 +08:00
|
|
|
for (i = 0; i < height; i++)
|
|
|
|
{
|
|
|
|
if (i & 8)
|
|
|
|
memcpy (&ptr[i * 3 * width], preview_alpha1_data, 3 * width);
|
|
|
|
else
|
|
|
|
memcpy (&ptr[i * 3 * width], preview_alpha2_data, 3 * width);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Util. */
|
|
|
|
|
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
remove_timer (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (timer)
|
|
|
|
{
|
2003-01-31 11:08:29 +08:00
|
|
|
g_source_remove (timer);
|
1997-11-25 06:05:25 +08:00
|
|
|
timer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-12-21 21:57:58 +08:00
|
|
|
do_step (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-26 06:04:19 +08:00
|
|
|
frame_number = (frame_number + 1) % total_frames;
|
2005-04-08 21:11:07 +08:00
|
|
|
render_frame (frame_number);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
static void
|
2006-02-26 06:40:52 +08:00
|
|
|
window_destroy (GtkWidget *widget)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-04-20 11:21:31 +08:00
|
|
|
if (playing)
|
2005-09-19 20:17:39 +08:00
|
|
|
remove_timer ();
|
1998-04-19 02:42:24 +08:00
|
|
|
|
|
|
|
if (shape_window)
|
2003-11-06 23:27:05 +08:00
|
|
|
gtk_widget_destroy (GTK_WIDGET (shape_window));
|
1998-04-19 02:42:24 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
gtk_main_quit ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
|
1997-12-12 18:01:21 +08:00
|
|
|
static gint
|
2003-01-31 11:08:29 +08:00
|
|
|
advance_frame_callback (gpointer data)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-06-21 04:04:33 +08:00
|
|
|
gdouble duration;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
remove_timer();
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
duration = get_frame_duration ((frame_number + 1) % total_frames);
|
|
|
|
|
|
|
|
timer = g_timeout_add (duration * get_duration_factor (duration_index),
|
2003-12-24 06:07:06 +08:00
|
|
|
advance_frame_callback, NULL);
|
1998-07-19 20:02:29 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
do_step ();
|
|
|
|
show_frame ();
|
1997-12-12 18:01:21 +08:00
|
|
|
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2006-02-26 07:18:59 +08:00
|
|
|
play_callback (GtkToggleAction *action)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-21 04:47:37 +08:00
|
|
|
if (playing)
|
2006-02-26 07:18:59 +08:00
|
|
|
remove_timer ();
|
|
|
|
|
|
|
|
playing = gtk_toggle_action_get_active (action);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-02-26 07:18:59 +08:00
|
|
|
if (playing)
|
2008-09-04 16:37:32 +08:00
|
|
|
timer = g_timeout_add (get_frame_duration (frame_number) *
|
2007-06-21 04:04:33 +08:00
|
|
|
get_duration_factor (duration_index),
|
2006-02-26 07:18:59 +08:00
|
|
|
advance_frame_callback, NULL);
|
2006-03-09 16:08:13 +08:00
|
|
|
|
|
|
|
g_object_set (action,
|
2008-10-20 14:04:39 +08:00
|
|
|
"tooltip", playing ? _("Stop playback") : _("Start playback"),
|
|
|
|
NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
static gdouble
|
|
|
|
get_duration_factor (gint index)
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 0.125;
|
|
|
|
case 1:
|
|
|
|
return 0.25;
|
|
|
|
case 2:
|
|
|
|
return 0.5;
|
|
|
|
case 3:
|
|
|
|
return 1.0;
|
|
|
|
case 4:
|
|
|
|
return 2.0;
|
|
|
|
case 5:
|
|
|
|
return 4.0;
|
|
|
|
case 6:
|
|
|
|
return 8.0;
|
|
|
|
default:
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
static gint
|
|
|
|
get_fps (gint index)
|
|
|
|
{
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 10;
|
|
|
|
case 1:
|
|
|
|
return 12;
|
|
|
|
case 2:
|
|
|
|
return 15;
|
|
|
|
case 3:
|
|
|
|
return 24;
|
|
|
|
case 4:
|
|
|
|
return 25;
|
|
|
|
case 5:
|
|
|
|
return 30;
|
|
|
|
case 6:
|
|
|
|
return 50;
|
|
|
|
case 7:
|
|
|
|
return 60;
|
|
|
|
case 8:
|
|
|
|
return 72;
|
|
|
|
default:
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2006-02-26 06:04:19 +08:00
|
|
|
step_callback (GtkAction *action)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-21 04:47:37 +08:00
|
|
|
if (playing)
|
2005-09-19 20:17:39 +08:00
|
|
|
gtk_action_activate (gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-toolbar/play"));
|
1997-11-25 06:05:25 +08:00
|
|
|
do_step();
|
|
|
|
show_frame();
|
|
|
|
}
|
|
|
|
|
2005-09-19 20:17:39 +08:00
|
|
|
static void
|
2006-02-26 06:04:19 +08:00
|
|
|
rewind_callback (GtkAction *action)
|
2005-09-19 20:17:39 +08:00
|
|
|
{
|
|
|
|
if (playing)
|
|
|
|
gtk_action_activate (gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-toolbar/play"));
|
|
|
|
frame_number = 0;
|
|
|
|
render_frame (frame_number);
|
|
|
|
show_frame ();
|
|
|
|
}
|
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
static void
|
|
|
|
speed_up_callback (GtkAction *action)
|
|
|
|
{
|
2007-06-21 04:04:33 +08:00
|
|
|
if (duration_index > 0)
|
|
|
|
--duration_index;
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_action_set_sensitive (action, duration_index > 0);
|
2007-06-18 14:51:51 +08:00
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-reset");
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_action_set_sensitive (action, duration_index != 3);
|
2007-06-18 14:51:51 +08:00
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-down");
|
|
|
|
gtk_action_set_sensitive (action, TRUE);
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
update_combobox ();
|
2007-06-18 14:51:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
speed_down_callback (GtkAction *action)
|
|
|
|
{
|
2007-06-21 04:04:33 +08:00
|
|
|
if (duration_index < 6)
|
|
|
|
++duration_index;
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_action_set_sensitive (action, duration_index < 6);
|
2007-06-18 14:51:51 +08:00
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-reset");
|
2007-06-21 04:04:33 +08:00
|
|
|
gtk_action_set_sensitive (action, duration_index != 3);
|
2007-06-18 14:51:51 +08:00
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-up");
|
|
|
|
gtk_action_set_sensitive (action, TRUE);
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
update_combobox ();
|
2007-06-18 14:51:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
speed_reset_callback (GtkAction *action)
|
|
|
|
{
|
2007-06-21 04:04:33 +08:00
|
|
|
duration_index = 3;
|
2007-06-18 14:51:51 +08:00
|
|
|
|
|
|
|
gtk_action_set_sensitive (action, FALSE);
|
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-down");
|
|
|
|
gtk_action_set_sensitive (action, TRUE);
|
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-up");
|
|
|
|
gtk_action_set_sensitive (action, TRUE);
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
update_combobox ();
|
2007-06-18 14:51:51 +08:00
|
|
|
}
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
|
2007-06-18 14:51:51 +08:00
|
|
|
static void
|
2009-11-20 17:23:13 +08:00
|
|
|
speedcombo_changed (GtkWidget *combo, gpointer data)
|
2007-06-18 14:51:51 +08:00
|
|
|
{
|
2007-06-21 04:04:33 +08:00
|
|
|
GtkAction * action;
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
duration_index = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-reset");
|
|
|
|
gtk_action_set_sensitive (action, duration_index != 3);
|
|
|
|
|
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-down");
|
|
|
|
gtk_action_set_sensitive (action, duration_index < 6);
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
action = gtk_ui_manager_get_action (ui_manager,
|
|
|
|
"/anim-play-popup/speed-up");
|
|
|
|
gtk_action_set_sensitive (action, duration_index > 0);
|
|
|
|
}
|
2007-06-18 14:51:51 +08:00
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
static void
|
|
|
|
fpscombo_changed (GtkWidget *combo, gpointer data)
|
|
|
|
{
|
|
|
|
default_frame_duration = 1000 / get_fps(gtk_combo_box_get_active (GTK_COMBO_BOX (combo)));
|
|
|
|
}
|
|
|
|
|
2007-06-21 04:04:33 +08:00
|
|
|
static void
|
|
|
|
update_combobox (void)
|
|
|
|
{
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (speedcombo), duration_index);
|
2007-06-18 14:51:51 +08:00
|
|
|
}
|
|
|
|
|
2000-01-14 04:47:30 +08:00
|
|
|
/* tag util. */
|
|
|
|
|
|
|
|
static DisposeType
|
2004-05-26 04:16:07 +08:00
|
|
|
get_frame_disposal (guint whichframe)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2003-12-24 06:07:06 +08:00
|
|
|
DisposeType disposal;
|
2006-04-19 20:11:00 +08:00
|
|
|
gchar *layer_name;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2010-07-09 18:27:36 +08:00
|
|
|
layer_name = gimp_item_get_name (layers[total_frames-(whichframe+1)]);
|
2004-05-26 04:16:07 +08:00
|
|
|
disposal = parse_disposal_tag (layer_name);
|
|
|
|
g_free (layer_name);
|
2000-01-14 04:47:30 +08:00
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
return disposal;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint32
|
2004-05-26 04:16:07 +08:00
|
|
|
get_frame_duration (guint whichframe)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2003-12-24 06:07:06 +08:00
|
|
|
gchar *layer_name;
|
2000-01-14 04:47:30 +08:00
|
|
|
gint duration = 0;
|
|
|
|
|
2010-07-09 18:27:36 +08:00
|
|
|
layer_name = gimp_item_get_name (layers[total_frames-(whichframe+1)]);
|
2004-05-26 04:16:07 +08:00
|
|
|
if (layer_name)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2006-02-27 19:50:57 +08:00
|
|
|
duration = parse_ms_tag (layer_name);
|
|
|
|
g_free (layer_name);
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2009-11-20 17:23:13 +08:00
|
|
|
if (duration <= 0)
|
|
|
|
duration = default_frame_duration;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
return (guint32) duration;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
static gboolean
|
2006-02-28 16:25:34 +08:00
|
|
|
is_ms_tag (const gchar *str,
|
|
|
|
gint *duration,
|
|
|
|
gint *taglength)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
|
|
|
gint sum = 0;
|
|
|
|
gint offset;
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
length = strlen(str);
|
|
|
|
|
|
|
|
if (str[0] != '(')
|
2005-04-08 21:11:07 +08:00
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
offset = 1;
|
|
|
|
|
|
|
|
/* eat any spaces between open-parenthesis and number */
|
2006-02-26 06:04:19 +08:00
|
|
|
while ((offset < length) && (str[offset] == ' '))
|
2000-01-14 04:47:30 +08:00
|
|
|
offset++;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2003-11-27 03:20:24 +08:00
|
|
|
if ((offset>=length) || (!g_ascii_isdigit (str[offset])))
|
2005-04-08 21:11:07 +08:00
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sum *= 10;
|
|
|
|
sum += str[offset] - '0';
|
|
|
|
offset++;
|
|
|
|
}
|
2003-11-27 03:20:24 +08:00
|
|
|
while ((offset<length) && (g_ascii_isdigit (str[offset])));
|
2000-01-14 04:47:30 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
if (length - offset <= 2)
|
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
/* eat any spaces between number and 'ms' */
|
2005-04-08 21:11:07 +08:00
|
|
|
while ((offset < length) && (str[offset] == ' '))
|
2000-01-14 04:47:30 +08:00
|
|
|
offset++;
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
if (length - offset <= 2 ||
|
2003-11-27 18:32:32 +08:00
|
|
|
g_ascii_toupper (str[offset]) != 'M' ||
|
|
|
|
g_ascii_toupper (str[offset + 1]) != 'S')
|
2005-04-08 21:11:07 +08:00
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* eat any spaces between 'ms' and close-parenthesis */
|
2005-04-08 21:11:07 +08:00
|
|
|
while ((offset < length) && (str[offset] == ' '))
|
2000-01-14 04:47:30 +08:00
|
|
|
offset++;
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
if ((length - offset < 1) || (str[offset] != ')'))
|
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
|
|
|
|
offset++;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-01-14 04:47:30 +08:00
|
|
|
*duration = sum;
|
|
|
|
*taglength = offset;
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
return TRUE;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
2006-02-28 16:25:34 +08:00
|
|
|
static gint
|
|
|
|
parse_ms_tag (const gchar *str)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
gint i;
|
|
|
|
gint length = strlen (str);
|
2000-01-14 04:47:30 +08:00
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
for (i = 0; i < length; i++)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
gint rtn;
|
|
|
|
gint dummy;
|
|
|
|
|
2003-11-27 03:20:24 +08:00
|
|
|
if (is_ms_tag (&str[i], &rtn, &dummy))
|
2003-12-24 06:07:06 +08:00
|
|
|
return rtn;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2000-01-14 04:47:30 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
static gboolean
|
2006-02-28 16:25:34 +08:00
|
|
|
is_disposal_tag (const gchar *str,
|
|
|
|
DisposeType *disposal,
|
|
|
|
gint *taglength)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2005-04-08 21:11:07 +08:00
|
|
|
if (strlen (str) != 9)
|
|
|
|
return FALSE;
|
2003-10-30 04:57:21 +08:00
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
if (strncmp (str, "(combine)", 9) == 0)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
|
|
|
*taglength = 9;
|
|
|
|
*disposal = DISPOSE_COMBINE;
|
2005-04-08 21:11:07 +08:00
|
|
|
return TRUE;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
2005-04-08 21:11:07 +08:00
|
|
|
else if (strncmp (str, "(replace)", 9) == 0)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
|
|
|
*taglength = 9;
|
|
|
|
*disposal = DISPOSE_REPLACE;
|
2005-04-08 21:11:07 +08:00
|
|
|
return TRUE;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
2005-04-08 21:11:07 +08:00
|
|
|
return FALSE;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static DisposeType
|
2006-02-28 16:25:34 +08:00
|
|
|
parse_disposal_tag (const gchar *str)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
gint i;
|
|
|
|
gint length = strlen (str);
|
2000-01-14 04:47:30 +08:00
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
for (i = 0; i < length; i++)
|
2000-01-14 04:47:30 +08:00
|
|
|
{
|
2006-02-28 16:25:34 +08:00
|
|
|
DisposeType rtn;
|
|
|
|
gint dummy;
|
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
if (is_disposal_tag (&str[i], &rtn, &dummy))
|
2006-02-27 19:50:57 +08:00
|
|
|
return rtn;
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|
|
|
|
|
2004-05-26 04:16:07 +08:00
|
|
|
return DISPOSE_UNDEFINED; /* FIXME */
|
2000-01-14 04:47:30 +08:00
|
|
|
}
|