[Swfdec] Branch 'interpreter' - 8 commits - libswfdec/swfdec_bits.c
libswfdec/swfdec_bits.h libswfdec/swfdec_js.c
libswfdec/swfdec_js.h libswfdec/swfdec_script.c
test/swfdec_out.c test/swfdec_out.h test/swfedit_tag.c
test/swfedit_token.c test/swfedit_token.h
Benjamin Otte
company at kemper.freedesktop.org
Wed Jan 24 12:37:24 PST 2007
libswfdec/swfdec_bits.c | 8 +-
libswfdec/swfdec_bits.h | 4 -
libswfdec/swfdec_js.c | 92 +++++++++++++++++++++++++---------
libswfdec/swfdec_js.h | 5 +
libswfdec/swfdec_script.c | 64 +++++++++++++++++++++--
test/swfdec_out.c | 24 ++++++++
test/swfdec_out.h | 5 +
test/swfedit_tag.c | 64 +++++++++++++++++++++++
test/swfedit_token.c | 123 +++++++++++++++++++++++++++++++++++++---------
test/swfedit_token.h | 2
10 files changed, 329 insertions(+), 62 deletions(-)
New commits:
diff-tree 4db4a99c916781cbceb31ca171c242867d4047cd (from 9dab0726ed4e35c06038b8700492bd62658ff689)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 21:37:13 2007 +0100
use swfdec_js_eval_set for SetVariable
diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index b2c4c81..32af30e 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -329,11 +329,8 @@ swfdec_action_set_variable (JSContext *c
if (s == NULL)
return JS_FALSE;
- if (strpbrk (s, "./:")) {
- SWFDEC_WARNING ("FIXME: implement paths");
- }
- if (!JS_SetProperty (cx, cx->fp->scopeChain, s, &cx->fp->sp[-1]))
- return JS_FALSE;
+ swfdec_js_eval_set (cx, cx->fp->scopeChain, s, cx->fp->sp[-1],
+ ((SwfdecScript *) cx->fp->swf)->version < 7);
cx->fp->sp -= 2;
return JS_TRUE;
}
diff-tree 9dab0726ed4e35c06038b8700492bd62658ff689 (from 6d219aa23eb4010d5438fce453650c158d09a720)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 21:36:55 2007 +0100
implement swfdec_js_eval_set
diff --git a/libswfdec/swfdec_js.c b/libswfdec/swfdec_js.c
index bbd6a43..1601b4b 100644
--- a/libswfdec/swfdec_js.c
+++ b/libswfdec/swfdec_js.c
@@ -322,30 +322,38 @@ swfdec_js_eval_get_property (JSContext *
}
}
-/**
- * swfdec_js_eval:
- * @cx: a #JSContext
- * @obj: #JSObject to use as a source for evaluating
- * @str: The string to evaluate
- * @ignore_case: TRUE for case insensitive evaluation
- *
- * This function works like the Actionscript eval function used on @obj.
- * It handles both slash-style and dot-style notation.
- *
- * Returns: the value or JSVAL_VOID if no value was found.
- **/
-jsval
-swfdec_js_eval (JSContext *cx, JSObject *obj, const char *str,
- gboolean ignore_case)
+static JSBool
+swfdec_js_eval_set_property (JSContext *cx, JSObject *obj,
+ const char *name, gboolean initial, gboolean ignore_case, jsval *ret)
+{
+ JSAtom *atom;
+ JSObject *pobj;
+ JSProperty *prop;
+
+ atom = js_Atomize (cx, name, strlen(name), ignore_case ? ATOM_NOCASE : 0);
+ if (!atom)
+ return JS_FALSE;
+ if (initial) {
+ return OBJ_SET_PROPERTY (cx, obj, (jsid) atom, ret);
+ } else {
+ if (!js_FindProperty (cx, (jsid) atom, &obj, &pobj, &prop))
+ return JS_FALSE;
+ if (!prop)
+ return JS_FALSE;
+ if (pobj)
+ obj = pobj;
+ return OBJ_SET_PROPERTY (cx, obj, (jsid) prop->id, ret);
+ }
+}
+
+static gboolean
+swfdec_js_eval_internal (JSContext *cx, JSObject *obj, const char *str,
+ gboolean ignore_case, jsval *val, gboolean set)
{
jsval cur;
char *work = NULL;
gboolean initial = TRUE;
- g_return_val_if_fail (cx != NULL, JSVAL_VOID);
- g_return_val_if_fail (obj != NULL, JSVAL_VOID);
- g_return_val_if_fail (str != NULL, JSVAL_VOID);
-
SWFDEC_LOG ("eval called with \"%s\" on %p", str, obj);
if (strchr (str, '/')) {
work = swfdec_js_slash_to_dot (str);
@@ -369,19 +377,57 @@ swfdec_js_eval (JSContext *cx, JSObject
g_free (name);
str = dot + 1;
} else {
- if (!swfdec_js_eval_get_property (cx, obj, str, initial, ignore_case, &cur))
- goto out;
+ if (set) {
+ if (!swfdec_js_eval_set_property (cx, obj, str, initial, ignore_case, val))
+ goto out;
+ } else {
+ if (!swfdec_js_eval_get_property (cx, obj, str, initial, ignore_case, &cur))
+ goto out;
+ }
str = NULL;
}
initial = FALSE;
}
g_free (work);
- return cur;
+ *val = cur;
+ return TRUE;
out:
SWFDEC_DEBUG ("error: returning void for %s", str);
g_free (work);
- return JSVAL_VOID;
+ return FALSE;
}
+/**
+ * swfdec_js_eval:
+ * @cx: a #JSContext
+ * @obj: #JSObject to use as a source for evaluating
+ * @str: The string to evaluate
+ * @ignore_case: TRUE for case insensitive evaluation
+ *
+ * This function works like the Actionscript eval function used on @obj.
+ * It handles both slash-style and dot-style notation.
+ *
+ * Returns: the value or JSVAL_VOID if no value was found.
+ **/
+jsval
+swfdec_js_eval (JSContext *cx, JSObject *obj, const char *str,
+ gboolean ignore_case)
+{
+ jsval ret;
+
+ g_return_val_if_fail (cx != NULL, JSVAL_VOID);
+ g_return_val_if_fail (obj != NULL, JSVAL_VOID);
+ g_return_val_if_fail (str != NULL, JSVAL_VOID);
+
+ if (!swfdec_js_eval_internal (cx, obj, str, ignore_case, &ret, FALSE))
+ ret = JSVAL_VOID;
+ return ret;
+}
+void
+swfdec_js_eval_set (JSContext *cx, JSObject *obj, const char *str,
+ jsval val, gboolean ignore_case)
+{
+ swfdec_js_eval_internal (cx, obj, str, ignore_case, &val, TRUE);
+}
diff --git a/libswfdec/swfdec_js.h b/libswfdec/swfdec_js.h
index 47e97ff..ea49a72 100644
--- a/libswfdec/swfdec_js.h
+++ b/libswfdec/swfdec_js.h
@@ -51,6 +51,11 @@ jsval swfdec_js_eval (JSContext * cx
JSObject * obj,
const char * str,
gboolean ignore_case);
+void swfdec_js_eval_set (JSContext * cx,
+ JSObject * obj,
+ const char * str,
+ jsval val,
+ gboolean ignore_case);
/* support functions */
const char * swfdec_js_to_string (JSContext * cx,
diff-tree 6d219aa23eb4010d5438fce453650c158d09a720 (from 00501d98ab1ec0257887814ccc9d582b3b8113a3)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 18:44:35 2007 +0100
add support for colors and the SetBackground tag
diff --git a/test/swfdec_out.c b/test/swfdec_out.c
index b795b28..bf7aa9e 100644
--- a/test/swfdec_out.c
+++ b/test/swfdec_out.c
@@ -213,6 +213,7 @@ swfdec_out_put_rect (SwfdecOut *out, Swf
guint req, tmp;
g_return_if_fail (out != NULL);
+ g_return_if_fail (rect != NULL);
x0 = rect->x0;
y0 = rect->y0;
@@ -233,3 +234,25 @@ swfdec_out_put_rect (SwfdecOut *out, Swf
swfdec_out_put_sbits (out, y1, req);
swfdec_out_syncbits (out);
}
+
+void
+swfdec_out_put_rgb (SwfdecOut *out, SwfdecColor color)
+{
+ g_return_if_fail (out != NULL);
+
+ swfdec_out_put_u8 (out, SWF_COLOR_R (color));
+ swfdec_out_put_u8 (out, SWF_COLOR_G (color));
+ swfdec_out_put_u8 (out, SWF_COLOR_B (color));
+}
+
+void
+swfdec_out_put_rgba (SwfdecOut *out, SwfdecColor color)
+{
+ g_return_if_fail (out != NULL);
+
+ swfdec_out_put_u8 (out, SWF_COLOR_R (color));
+ swfdec_out_put_u8 (out, SWF_COLOR_G (color));
+ swfdec_out_put_u8 (out, SWF_COLOR_B (color));
+ swfdec_out_put_u8 (out, SWF_COLOR_A (color));
+}
+
diff --git a/test/swfdec_out.h b/test/swfdec_out.h
index b6d155f..d1f916c 100644
--- a/test/swfdec_out.h
+++ b/test/swfdec_out.h
@@ -21,6 +21,7 @@
#define __SWFDEC_OUT_H__
#include <libswfdec/swfdec_buffer.h>
+#include <libswfdec/swfdec_color.h>
#include <libswfdec/swfdec_rect.h>
G_BEGIN_DECLS
@@ -64,6 +65,10 @@ void swfdec_out_put_u16 (SwfdecOut * o
void swfdec_out_put_u32 (SwfdecOut * out,
guint i);
+void swfdec_out_put_rgb (SwfdecOut * out,
+ SwfdecColor color);
+void swfdec_out_put_rgba (SwfdecOut * out,
+ SwfdecColor color);
void swfdec_out_put_rect (SwfdecOut * out,
SwfdecRect * rect);
diff --git a/test/swfedit_tag.c b/test/swfedit_tag.c
index 55020a0..dd15978 100644
--- a/test/swfedit_tag.c
+++ b/test/swfedit_tag.c
@@ -96,6 +96,30 @@ swfedit_rect_read (SwfdecBits *bits)
return rect;
}
+static void
+swfedit_rgb_write (gpointer data, SwfdecOut *out)
+{
+ swfdec_out_put_rgb (out, GPOINTER_TO_UINT (data));
+}
+
+static gpointer
+swfedit_rgb_read (SwfdecBits *bits)
+{
+ return GUINT_TO_POINTER (swfdec_bits_get_color (bits));
+}
+
+static void
+swfedit_rgba_write (gpointer data, SwfdecOut *out)
+{
+ swfdec_out_put_rgba (out, GPOINTER_TO_UINT (data));
+}
+
+static gpointer
+swfedit_rgba_read (SwfdecBits *bits)
+{
+ return GUINT_TO_POINTER (swfdec_bits_get_rgba (bits));
+}
+
struct {
void (* write) (gpointer data, SwfdecOut *out);
gpointer (* read) (SwfdecBits *bits);
@@ -106,6 +130,8 @@ struct {
{ swfedit_u16_write, swfedit_u16_read },
{ swfedit_u32_write, swfedit_u32_read },
{ swfedit_rect_write, swfedit_rect_read },
+ { swfedit_rgb_write, swfedit_rgb_read },
+ { swfedit_rgba_write, swfedit_rgba_read },
};
void
@@ -156,14 +182,16 @@ swfedit_tag_read_token (SwfeditToken *to
typedef struct {
const char * name; /* name to use for this field */
SwfeditTokenType type; /* type of this field */
- guint n_items; /* field to look at for item count */
+ guint n_items; /* field to look at for item count (or 0 to use 1 item) */
guint hint; /* hint to pass to field when creating */
} SwfeditTagDefinition;
static const SwfeditTagDefinition ShowFrame[] = { { NULL, 0, 0, 0 } };
+static const SwfeditTagDefinition SetBackgroundColor[] = { { "color", SWFEDIT_TOKEN_RGB, 0, 0 }, { NULL, 0, 0, 0 } };
static const SwfeditTagDefinition *tags[] = {
[SWFDEC_TAG_SHOWFRAME] = ShowFrame,
+ [SWFDEC_TAG_SETBACKGROUNDCOLOR] = SetBackgroundColor,
};
static const SwfeditTagDefinition *
diff --git a/test/swfedit_token.c b/test/swfedit_token.c
index ecf471c..3327b81 100644
--- a/test/swfedit_token.c
+++ b/test/swfedit_token.c
@@ -22,42 +22,57 @@
#endif
#include <stdlib.h>
+#include <string.h>
#include <gtk/gtk.h>
#include <libswfdec/swfdec_buffer.h>
+#include <libswfdec/swfdec_color.h>
#include "swfedit_token.h"
/*** CONVERTERS ***/
static gboolean
+swfedit_parse_hex (const char *s, guint *result)
+{
+ guint byte;
+
+ if (s[0] >= '0' && s[0] <= '9')
+ byte = s[0] - '0';
+ else if (s[0] >= 'a' && s[0] <= 'f')
+ byte = s[0] + 10 - 'a';
+ else if (s[0] >= 'A' && s[0] <= 'F')
+ byte = s[0] + 10 - 'A';
+ else
+ return FALSE;
+ s++;
+ byte *= 16;
+ if (s[0] >= '0' && s[0] <= '9')
+ byte += s[0] - '0';
+ else if (s[0] >= 'a' && s[0] <= 'f')
+ byte += s[0] + 10 - 'a';
+ else if (s[0] >= 'A' && s[0] <= 'F')
+ byte += s[0] + 10 - 'A';
+ else
+ return FALSE;
+ *result = byte;
+ return TRUE;
+}
+
+static gboolean
swfedit_binary_from_string (const char *s, gpointer* result)
{
GByteArray *array = g_byte_array_new ();
- guint8 byte;
+ guint byte;
+ guint8 add;
while (g_ascii_isspace (*s)) s++;
do {
- if (s[0] >= '0' && s[0] <= '9')
- byte = s[0] - '0';
- else if (s[0] >= 'a' && s[0] <= 'f')
- byte = s[0] + 10 - 'a';
- else if (s[0] >= 'A' && s[0] <= 'F')
- byte = s[0] + 10 - 'A';
- else
+ if (!swfedit_parse_hex (s, &byte))
break;
- s++;
- byte *= 16;
- if (s[0] >= '0' && s[0] <= '9')
- byte += s[0] - '0';
- else if (s[0] >= 'a' && s[0] <= 'f')
- byte += s[0] + 10 - 'a';
- else if (s[0] >= 'A' && s[0] <= 'F')
- byte += s[0] + 10 - 'A';
- else
- break;
- s++;
- g_byte_array_append (array, &byte, 1);
+ s += 2;
+ add = byte;
+ g_byte_array_append (array, &add, 1);
while (g_ascii_isspace (*s)) s++;
- } while (TRUE);
+ } while (*s != '\0');
if (*s == '\0') {
SwfdecBuffer *buffer = swfdec_buffer_new ();
buffer->length = array->len;
@@ -97,7 +112,6 @@ swfedit_from_string_unsigned (const char
return FALSE;
if (u > max)
return FALSE;
- *result = GUINT_TO_POINTER ((guint) u);
return TRUE;
}
@@ -140,6 +154,63 @@ swfedit_rect_to_string (gconstpointer va
(int) rect->x1, (int) rect->y1);
}
+static gboolean
+swfedit_rgb_from_string (const char *s, gpointer* result)
+{
+ guint r, g, b;
+ if (strlen (s) != 6)
+ return FALSE;
+ if (!swfedit_parse_hex (s, &r))
+ return FALSE;
+ s += 2;
+ if (!swfedit_parse_hex (s, &g))
+ return FALSE;
+ s += 2;
+ if (!swfedit_parse_hex (s, &b))
+ return FALSE;
+ *result = GUINT_TO_POINTER (SWF_COLOR_COMBINE (r, g, b, 0xFF));
+ return TRUE;
+}
+
+static char *
+swfedit_rgb_to_string (gconstpointer value)
+{
+ guint c = GPOINTER_TO_UINT (value);
+
+ return g_strdup_printf ("%02X%02X%02X", SWF_COLOR_R (c),
+ SWF_COLOR_G (c), SWF_COLOR_B (c));
+}
+
+static gboolean
+swfedit_rgba_from_string (const char *s, gpointer* result)
+{
+ guint r, g, b, a;
+ if (strlen (s) != 8)
+ return FALSE;
+ if (!swfedit_parse_hex (s, &a))
+ return FALSE;
+ s += 2;
+ if (!swfedit_parse_hex (s, &r))
+ return FALSE;
+ s += 2;
+ if (!swfedit_parse_hex (s, &g))
+ return FALSE;
+ s += 2;
+ if (!swfedit_parse_hex (s, &b))
+ return FALSE;
+ *result = GUINT_TO_POINTER (SWF_COLOR_COMBINE (r, g, b, a));
+ return TRUE;
+}
+
+static char *
+swfedit_rgba_to_string (gconstpointer value)
+{
+ guint c = GPOINTER_TO_UINT (value);
+
+ return g_strdup_printf ("%02X%02X%02X%02X", SWF_COLOR_R (c),
+ SWF_COLOR_G (c), SWF_COLOR_B (c), SWF_COLOR_A (c));
+}
+
struct {
gboolean (* from_string) (const char *s, gpointer *);
char * (* to_string) (gconstpointer value);
@@ -151,6 +222,8 @@ struct {
{ swfedit_uint16_from_string, swfedit_to_string_unsigned, NULL },
{ swfedit_uint32_from_string, swfedit_to_string_unsigned, NULL },
{ swfedit_rect_from_string, swfedit_rect_to_string, g_free },
+ { swfedit_rgb_from_string, swfedit_rgb_to_string, NULL },
+ { swfedit_rgba_from_string, swfedit_rgba_to_string, NULL },
};
/*** GTK_TREE_MODEL ***/
diff --git a/test/swfedit_token.h b/test/swfedit_token.h
index 8dec753..7909188 100644
--- a/test/swfedit_token.h
+++ b/test/swfedit_token.h
@@ -32,6 +32,8 @@ typedef enum {
SWFEDIT_TOKEN_UINT16,
SWFEDIT_TOKEN_UINT32,
SWFEDIT_TOKEN_RECT,
+ SWFEDIT_TOKEN_RGB,
+ SWFEDIT_TOKEN_RGBA,
SWFEDIT_N_TOKENS
} SwfeditTokenType;
diff-tree 00501d98ab1ec0257887814ccc9d582b3b8113a3 (from e0270bcea5766d30ae6eeb7f8b0f0ef062f121f4)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 18:44:11 2007 +0100
implement StringAdd and GetURL, so Steve dances again
diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 171877f..b2c4c81 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -773,9 +773,62 @@ swfdec_action_increment (JSContext *cx,
return JS_NewNumberValue (cx, d, &cx->fp->sp[-1]);
}
+static JSBool
+swfdec_action_get_url (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ SwfdecMovie *movie;
+ SwfdecBits bits;
+ const char *url, *target;
+
+ swfdec_bits_init_data (&bits, data, len);
+ url = swfdec_bits_skip_string (&bits);
+ target = swfdec_bits_skip_string (&bits);
+ if (swfdec_bits_left (&bits)) {
+ SWFDEC_WARNING ("leftover bytes in GetURL action");
+ }
+ movie = swfdec_action_get_target (cx);
+ if (movie)
+ swfdec_root_movie_load (SWFDEC_ROOT_MOVIE (movie->root), url, target);
+ else
+ SWFDEC_WARNING ("no movie to load");
+ return JS_TRUE;
+}
+
+static JSBool
+swfdec_action_string_add (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+ JSString *lval, *rval;
+
+ rval = JS_ValueToString (cx, cx->fp->sp[-1]);
+ lval = JS_ValueToString (cx, cx->fp->sp[-2]);
+ if (lval == NULL || rval == NULL)
+ return FALSE;
+ lval = JS_ConcatStrings (cx, lval, rval);
+ if (lval == NULL)
+ return FALSE;
+ cx->fp->sp--;
+ cx->fp->sp[-1] = STRING_TO_JSVAL (lval);
+ return JS_TRUE;
+}
+
/*** PRINT FUNCTIONS ***/
static char *
+swfdec_action_print_get_url (guint action, const guint8 *data, guint len)
+{
+ SwfdecBits bits;
+ const char *url, *target;
+
+ swfdec_bits_init_data (&bits, data, len);
+ url = swfdec_bits_skip_string (&bits);
+ target = swfdec_bits_skip_string (&bits);
+ if (swfdec_bits_left (&bits)) {
+ SWFDEC_WARNING ("leftover bytes in GetURL action");
+ }
+ return g_strdup_printf ("GetURL %s %s", url, target);
+}
+
+static char *
swfdec_action_print_if (guint action, const guint8 *data, guint len)
{
if (len != 2) {
@@ -942,7 +995,7 @@ static const SwfdecActionSpec actions[25
[0x1c] = { "GetVariable", NULL, 1, 1, { NULL, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable, swfdec_action_get_variable } },
[0x1d] = { "SetVariable", NULL, 2, 0, { NULL, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable, swfdec_action_set_variable } },
[0x20] = { "SetTarget2", NULL },
- [0x21] = { "StringAdd", NULL },
+ [0x21] = { "StringAdd", NULL, 2, 1, { NULL, swfdec_action_string_add, swfdec_action_string_add, swfdec_action_string_add, swfdec_action_string_add } },
[0x22] = { "GetProperty", NULL, 2, 1, { NULL, swfdec_action_get_property, swfdec_action_get_property, swfdec_action_get_property, swfdec_action_get_property } },
[0x23] = { "SetProperty", NULL, 3, 0, { NULL, swfdec_action_set_property, swfdec_action_set_property, swfdec_action_set_property, swfdec_action_set_property } },
[0x24] = { "CloneSprite", NULL },
@@ -1010,7 +1063,7 @@ static const SwfdecActionSpec actions[25
/* version 3 */
[0x81] = { "GotoFrame", swfdec_action_print_goto_frame, 0, 0, { swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame } },
- [0x83] = { "GetURL", NULL },
+ [0x83] = { "GetURL", swfdec_action_print_get_url, 0, 0, { swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url, swfdec_action_get_url } },
/* version 5 */
[0x87] = { "StoreRegister", NULL },
[0x88] = { "ConstantPool", swfdec_action_print_constant_pool, 0, 0, { NULL, NULL, swfdec_action_constant_pool, swfdec_action_constant_pool, swfdec_action_constant_pool } },
diff-tree e0270bcea5766d30ae6eeb7f8b0f0ef062f121f4 (from 6efabb680e16b9144d8b4e880c18396861190d69)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 18:43:48 2007 +0100
make the color functions return a SwfdecColor
diff --git a/libswfdec/swfdec_bits.c b/libswfdec/swfdec_bits.c
index 1a7e402..418e9eb 100644
--- a/libswfdec/swfdec_bits.c
+++ b/libswfdec/swfdec_bits.c
@@ -471,10 +471,10 @@ swfdec_bits_get_string_length (SwfdecBit
return ret;
}
-unsigned int
+SwfdecColor
swfdec_bits_get_color (SwfdecBits * bits)
{
- int r, g, b;
+ unsigned int r, g, b;
r = swfdec_bits_get_u8 (bits);
g = swfdec_bits_get_u8 (bits);
@@ -483,10 +483,10 @@ swfdec_bits_get_color (SwfdecBits * bits
return SWF_COLOR_COMBINE (r, g, b, 0xff);
}
-unsigned int
+SwfdecColor
swfdec_bits_get_rgba (SwfdecBits * bits)
{
- int r, g, b, a;
+ unsigned int r, g, b, a;
r = swfdec_bits_get_u8 (bits);
g = swfdec_bits_get_u8 (bits);
diff --git a/libswfdec/swfdec_bits.h b/libswfdec/swfdec_bits.h
index 08ae1d8..a44c9e2 100644
--- a/libswfdec/swfdec_bits.h
+++ b/libswfdec/swfdec_bits.h
@@ -65,8 +65,8 @@ const char *swfdec_bits_skip_string (Swf
guint swfdec_bits_skip_bytes (SwfdecBits *bits, guint bytes);
char *swfdec_bits_get_string (SwfdecBits * bits);
char *swfdec_bits_get_string_length (SwfdecBits * bits, unsigned int len);
-unsigned int swfdec_bits_get_color (SwfdecBits * bits);
-unsigned int swfdec_bits_get_rgba (SwfdecBits * bits);
+SwfdecColor swfdec_bits_get_color (SwfdecBits * bits);
+SwfdecColor swfdec_bits_get_rgba (SwfdecBits * bits);
SwfdecGradient *swfdec_bits_get_gradient (SwfdecBits * bits);
SwfdecGradient *swfdec_bits_get_gradient_rgba (SwfdecBits * bits);
SwfdecGradient *swfdec_bits_get_morph_gradient (SwfdecBits * bits);
diff-tree 6efabb680e16b9144d8b4e880c18396861190d69 (from f1207b1451c4061e86adf62637134d63909ab754)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 16:40:58 2007 +0100
add initial support for auto-extraction of contents
diff --git a/test/swfedit_tag.c b/test/swfedit_tag.c
index 0a9fb9b..55020a0 100644
--- a/test/swfedit_tag.c
+++ b/test/swfedit_tag.c
@@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <libswfdec/swfdec_bits.h>
+#include <libswfdec/swfdec_tag.h>
#include "swfedit_tag.h"
#include "swfdec_out.h"
@@ -150,6 +151,29 @@ swfedit_tag_read_token (SwfeditToken *to
swfedit_token_add (token, name, type, data);
}
+/*** TAGS ***/
+
+typedef struct {
+ const char * name; /* name to use for this field */
+ SwfeditTokenType type; /* type of this field */
+ guint n_items; /* field to look at for item count */
+ guint hint; /* hint to pass to field when creating */
+} SwfeditTagDefinition;
+
+static const SwfeditTagDefinition ShowFrame[] = { { NULL, 0, 0, 0 } };
+
+static const SwfeditTagDefinition *tags[] = {
+ [SWFDEC_TAG_SHOWFRAME] = ShowFrame,
+};
+
+static const SwfeditTagDefinition *
+swfedit_tag_get_definition (guint tag)
+{
+ if (tag >= G_N_ELEMENTS (tags))
+ return NULL;
+ return tags[tag];
+}
+
/*** SWFEDIT_TAG ***/
G_DEFINE_TYPE (SwfeditTag, swfedit_tag, SWFEDIT_TYPE_TOKEN)
@@ -179,13 +203,23 @@ SwfeditTag *
swfedit_tag_new (SwfeditToken *parent, guint tag, SwfdecBuffer *buffer)
{
SwfeditTag *item;
+ const SwfeditTagDefinition *def;
g_return_val_if_fail (SWFEDIT_IS_TOKEN (parent), NULL);
item = g_object_new (SWFEDIT_TYPE_TAG, NULL);
item->tag = tag;
SWFEDIT_TOKEN (item)->parent = parent;
- swfedit_token_add (SWFEDIT_TOKEN (item), "contents", SWFEDIT_TOKEN_BINARY, buffer);
+ def = swfedit_tag_get_definition (tag);
+ if (def) {
+ SwfdecBits bits;
+ swfdec_bits_init (&bits, buffer);
+ for (;def->name != NULL; def++) {
+ swfedit_tag_read_token (SWFEDIT_TOKEN (item), &bits, def->name, def->type);
+ }
+ } else {
+ swfedit_token_add (SWFEDIT_TOKEN (item), "contents", SWFEDIT_TOKEN_BINARY, buffer);
+ }
return item;
}
diff-tree f1207b1451c4061e86adf62637134d63909ab754 (from 2699f0ac28fe220c12fe6f98b05c50937125aeea)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 16:40:35 2007 +0100
handle tokens without children
diff --git a/test/swfedit_token.c b/test/swfedit_token.c
index b2210fd..ecf471c 100644
--- a/test/swfedit_token.c
+++ b/test/swfedit_token.c
@@ -309,6 +309,8 @@ swfedit_token_iter_children (GtkTreeMode
} else {
token = SWFEDIT_TOKEN (tree_model);
}
+ if (token->tokens->len == 0)
+ return FALSE;
iter->stamp = 0; /* FIXME */
iter->user_data = token;
iter->user_data2 = GINT_TO_POINTER (0);
@@ -322,7 +324,7 @@ swfedit_token_iter_has_child (GtkTreeMod
SwfeditTokenEntry *entry = &g_array_index (token->tokens, SwfeditTokenEntry, GPOINTER_TO_INT (iter->user_data2));
REPORT;
- return entry->type == SWFEDIT_TOKEN_OBJECT;
+ return entry->type == SWFEDIT_TOKEN_OBJECT && SWFEDIT_TOKEN (entry->value)->tokens->len > 0;
}
static gint
@@ -333,7 +335,7 @@ swfedit_token_iter_n_children (GtkTreeMo
REPORT;
if (entry->type != SWFEDIT_TOKEN_OBJECT)
- return FALSE;
+ return 0;
token = entry->value;
return token->tokens->len;
diff-tree 2699f0ac28fe220c12fe6f98b05c50937125aeea (from 4d09855e83ee699d590e8916e4af318ab79cc99b)
Author: Benjamin Otte <otte at gnome.org>
Date: Wed Jan 24 15:44:38 2007 +0100
remove debugging g_print
diff --git a/test/swfdec_out.c b/test/swfdec_out.c
index 70dcc7c..b795b28 100644
--- a/test/swfdec_out.c
+++ b/test/swfdec_out.c
@@ -168,7 +168,6 @@ swfdec_out_put_bits (SwfdecOut *out, gui
*out->ptr = 0;
value &= (1 << bits_now) - 1;
value <<= 8 - out->idx - bits_now;
- g_print ("putting %02X in the next %u bits\n", value, bits_now);
*out->ptr |= value;
out->idx += bits_now;
g_assert (out->idx <= 8);
More information about the Swfdec
mailing list