[Swfdec] Branch 'as' - 7 commits - libswfdec/Makefile.am libswfdec/swfdec_as_context.c libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_strings.c libswfdec/swfdec_as_super.c libswfdec/swfdec_color_as.c libswfdec/swfdec_color_as.h libswfdec/swfdec_js_color.c libswfdec/swfdec_player.c

Benjamin Otte company at kemper.freedesktop.org
Wed May 23 07:26:04 PDT 2007


 libswfdec/Makefile.am           |    3 
 libswfdec/swfdec_as_context.c   |    4 
 libswfdec/swfdec_as_frame.c     |    4 
 libswfdec/swfdec_as_frame.h     |    2 
 libswfdec/swfdec_as_interpret.c |   38 +++----
 libswfdec/swfdec_as_object.c    |   13 +-
 libswfdec/swfdec_as_object.h    |    2 
 libswfdec/swfdec_as_strings.c   |   13 ++
 libswfdec/swfdec_as_super.c     |    6 -
 libswfdec/swfdec_color_as.c     |  211 ++++++++++++++++++++++++++++++++++++++++
 libswfdec/swfdec_color_as.h     |   56 ++++++++++
 libswfdec/swfdec_js_color.c     |  192 ------------------------------------
 libswfdec/swfdec_player.c       |    2 
 13 files changed, 318 insertions(+), 228 deletions(-)

New commits:
diff-tree 37f9a4467fe9e82fdc7fe6d6e73aaf9291cbbe7d (from b4b7b353623ac870903f5a45dbfc85bf03c28513)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed May 23 16:29:45 2007 +0200

    it's the prototype, not the constructor, stupid

diff --git a/libswfdec/swfdec_as_super.c b/libswfdec/swfdec_as_super.c
index e5b9728..ffbc0b5 100644
--- a/libswfdec/swfdec_as_super.c
+++ b/libswfdec/swfdec_as_super.c
@@ -79,10 +79,10 @@ swfdec_as_super_new (SwfdecAsFrame *fram
   if (frame->thisp) {
     SwfdecAsValue val;
     super->object = frame->thisp;
-    swfdec_as_object_get_variable (frame->thisp, SWFDEC_AS_STR_constructor, &val);
+    swfdec_as_object_get_variable (frame->thisp, SWFDEC_AS_STR___proto__, &val);
     if (SWFDEC_AS_VALUE_IS_OBJECT (&val)) {
-      SwfdecAsObject *constructor = SWFDEC_AS_VALUE_GET_OBJECT (&val);
-      swfdec_as_object_get_variable (constructor, SWFDEC_AS_STR___constructor__, &val);
+      SwfdecAsObject *proto = SWFDEC_AS_VALUE_GET_OBJECT (&val);
+      swfdec_as_object_get_variable (proto, SWFDEC_AS_STR___constructor__, &val);
       if (SWFDEC_AS_VALUE_IS_OBJECT (&val)) {
 	super->constructor = (SwfdecAsFunction *) SWFDEC_AS_VALUE_GET_OBJECT (&val);
 	if (!SWFDEC_IS_AS_FUNCTION (super->constructor))
diff-tree b4b7b353623ac870903f5a45dbfc85bf03c28513 (from 9228f671c687da6698b259fbce8d56ada7ab524a)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 21:55:22 2007 +0200

    implement InitObject action

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 63b53a6..f5503fb 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -1192,35 +1192,31 @@ fail:
   fp->sp[-1] = JSVAL_VOID;
   return JS_TRUE;
 }
+#endif
 
 static void
 swfdec_action_init_object (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  JSStackFrame *fp = cx->fp;
-  JSObject *object;
-  guint n_args;
-  gulong i;
+  SwfdecAsStack *stack = cx->frame->stack;
+  SwfdecAsObject *object;
+  guint i, n_args;
 
-  if (!JS_ValueToECMAUint32 (cx, fp->sp[-1], &n_args))
-    return JS_FALSE;
-  if (!swfdec_script_ensure_stack (cx, 2 * n_args + 1))
-    return JS_FALSE;
+  n_args = swfdec_as_value_to_integer (cx, swfdec_as_stack_pop (stack));
+  if (n_args * 2 < swfdec_as_stack_get_size (stack)) {
+    SWFDEC_FIXME ("InitObject action with too small stack, help!");
+    n_args = swfdec_as_stack_get_size (stack) / 2;
+  }
 
-  object = JS_NewObject (cx, &js_ObjectClass, NULL, NULL);
+  object = swfdec_as_object_new (cx);
   if (object == NULL)
-    return JS_FALSE;
+    return;
   for (i = 0; i < n_args; i++) {
-    const char *s = swfdec_js_to_string (cx, fp->sp[-3 - 2 * i]);
-    if (s == NULL)
-      return JS_FALSE;
-    if (!JS_SetProperty (cx, object, s, &fp->sp[-2 - 2 * i]))
-      return JS_FALSE;
+    const char *s = swfdec_as_value_to_string (cx, swfdec_as_stack_peek (stack, 2));
+    swfdec_as_object_set_variable (object, s, swfdec_as_stack_peek (stack, 1));
+    swfdec_as_stack_pop_n (stack, 2);
   }
-  fp->sp -= 2 * n_args;
-  fp->sp[-1] = OBJECT_TO_JSVAL (object);
-  return JS_TRUE;
+  SWFDEC_AS_VALUE_SET_OBJECT (swfdec_as_stack_push (stack), object);
 }
-#endif
 
 static void
 swfdec_action_init_array (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
@@ -2099,9 +2095,7 @@ const SwfdecActionSpec swfdec_as_actions
   [SWFDEC_AS_ACTION_NEW_OBJECT] = { "NewObject", NULL, -1, 1, { NULL, NULL, swfdec_action_new_object, swfdec_action_new_object, swfdec_action_new_object } },
   [SWFDEC_AS_ACTION_DEFINE_LOCAL2] = { "DefineLocal2", NULL, 1, 0, { NULL, NULL, swfdec_action_define_local2, swfdec_action_define_local2, swfdec_action_define_local2 } },
   [SWFDEC_AS_ACTION_INIT_ARRAY] = { "InitArray", NULL, -1, 1, { NULL, NULL, swfdec_action_init_array, swfdec_action_init_array, swfdec_action_init_array } },
-#if 0
-  [0x43] = { "InitObject", NULL, -1, 1, { NULL, NULL, swfdec_action_init_object, swfdec_action_init_object, swfdec_action_init_object } },
-#endif
+  [SWFDEC_AS_ACTION_INIT_OBJECT] = { "InitObject", NULL, -1, 1, { NULL, NULL, swfdec_action_init_object, swfdec_action_init_object, swfdec_action_init_object } },
   [SWFDEC_AS_ACTION_TYPE_OF] = { "TypeOf", NULL, 1, 1, { NULL, NULL, swfdec_action_type_of, swfdec_action_type_of, swfdec_action_type_of } },
 #if 0
   [0x45] = { "TargetPath", NULL, 1, 1, { NULL, NULL, swfdec_action_target_path, swfdec_action_target_path, swfdec_action_target_path } },
diff-tree 9228f671c687da6698b259fbce8d56ada7ab524a (from 608fea8b3a14545b57ed30aaccd991bf4ba4933f)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 21:25:18 2007 +0200

    messed up a check for calling native functions

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 44ee604..c88c66a 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -420,7 +420,7 @@ start:
     if (frame->argc >= native->min_args && 
 	(native->type == 0 || 
 	 (frame->thisp != NULL && 
-	  !g_type_is_a (G_OBJECT_TYPE (frame->thisp), native->type)))) {
+	  g_type_is_a (G_OBJECT_TYPE (frame->thisp), native->type)))) {
       native->native (frame->thisp, frame->argc, frame->argv, frame->return_value);
     }
     swfdec_as_context_return (context);
diff-tree 608fea8b3a14545b57ed30aaccd991bf4ba4933f (from parents)
Merge: c99ae0ff12cab447a6c1192f8f68a403a3c937d7 67d689d2c9390a5520e4ccfe9a28313f2e60f1bb
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 21:09:50 2007 +0200

    Merge branch 'as' of ssh://company@git.freedesktop.org/git/swfdec into as

diff-tree c99ae0ff12cab447a6c1192f8f68a403a3c937d7 (from ebdd3d457ee189c03941ed1fab0ab14a7f1ee990)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 20:58:07 2007 +0200

    reenable Color class

diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index 7cf86f6..ba1f4d4 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -21,7 +21,6 @@ lib_LTLIBRARIES = libswfdec- at SWFDEC_MAJO
 
 foofiles = \
 	swfdec_js.c \
-	swfdec_js_color.c \
 	swfdec_js_connection.c \
 	swfdec_js_global.c \
 	swfdec_js_mouse.c \
@@ -64,6 +63,7 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_codec_screen.c \
 	swfdec_codec_video.c \
 	swfdec_color.c \
+	swfdec_color_as.c \
 	swfdec_connection.c \
 	swfdec_debug.c \
 	swfdec_debugger.c \
@@ -160,6 +160,7 @@ noinst_HEADERS = \
 	swfdec_codec_audio.h \
 	swfdec_codec_video.h \
 	swfdec_color.h \
+	swfdec_color_as.h \
 	swfdec_connection.h \
 	swfdec_debug.h \
 	swfdec_debugger.h \
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 8153c32..7f8529c 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -315,9 +315,9 @@ swfdec_as_object_get_variable (SwfdecAsO
 {
   guint i;
 
-  g_return_if_fail (SWFDEC_IS_AS_OBJECT (object));
-  g_return_if_fail (variable != NULL);
-  g_return_if_fail (value != NULL);
+  g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), FALSE);
+  g_return_val_if_fail (variable != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
 
   for (i = 0; i < 256 && object != NULL; i++) {
     if (swfdec_as_object_lookup (object, variable, value, NULL))
@@ -330,7 +330,7 @@ swfdec_as_object_get_variable (SwfdecAsO
   }
   //SWFDEC_WARNING ("no such variable %s", variable);
   SWFDEC_AS_VALUE_SET_UNDEFINED (value);
-  return FALSE:
+  return FALSE;
 }
 
 void
diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index bc4b61a..52b4d01 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -150,6 +150,19 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("registerClass")
   SWFDEC_AS_CONSTANT_STRING ("__constructor__")
   SWFDEC_AS_CONSTANT_STRING ("_global")
+  SWFDEC_AS_CONSTANT_STRING ("aa")
+  SWFDEC_AS_CONSTANT_STRING ("ab")
+  SWFDEC_AS_CONSTANT_STRING ("ba")
+  SWFDEC_AS_CONSTANT_STRING ("bb")
+  SWFDEC_AS_CONSTANT_STRING ("ga")
+  SWFDEC_AS_CONSTANT_STRING ("gb")
+  SWFDEC_AS_CONSTANT_STRING ("ra")
+  SWFDEC_AS_CONSTANT_STRING ("rb")
+  SWFDEC_AS_CONSTANT_STRING ("getRGB")
+  SWFDEC_AS_CONSTANT_STRING ("getTransform")
+  SWFDEC_AS_CONSTANT_STRING ("setRGB")
+  SWFDEC_AS_CONSTANT_STRING ("setTransform")
+  SWFDEC_AS_CONSTANT_STRING ("Color")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_color_as.c b/libswfdec/swfdec_color_as.c
new file mode 100644
index 0000000..33ed9ee
--- /dev/null
+++ b/libswfdec/swfdec_color_as.c
@@ -0,0 +1,211 @@
+/* Swfdec
+ * Copyright (C) 2006-2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_color_as.h"
+#include "swfdec_as_context.h"
+#include "swfdec_debug.h"
+#include "swfdec_movie.h"
+
+G_DEFINE_TYPE (SwfdecMovieColor, swfdec_movie_color, SWFDEC_TYPE_AS_OBJECT)
+
+static void
+swfdec_movie_color_mark (SwfdecAsObject *object)
+{
+  SwfdecMovieColor *color = SWFDEC_MOVIE_COLOR (object);
+
+  /* FIXME: unset movie when movie is already dead */
+  if (color->movie)
+    swfdec_as_object_mark (SWFDEC_AS_OBJECT (color->movie));
+
+  SWFDEC_AS_OBJECT_CLASS (swfdec_movie_color_parent_class)->mark (object);
+}
+
+static void
+swfdec_movie_color_class_init (SwfdecMovieColorClass *klass)
+{
+  SwfdecAsObjectClass *asobject_class = SWFDEC_AS_OBJECT_CLASS (klass);
+
+  asobject_class->mark = swfdec_movie_color_mark;
+}
+
+static void
+swfdec_movie_color_init (SwfdecMovieColor *color)
+{
+}
+
+/*** AS CODE ***/
+
+static void
+swfdec_movie_color_getRGB (SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  int result;
+  SwfdecMovie *movie = SWFDEC_MOVIE_COLOR (obj)->movie;
+  
+  if (movie == NULL)
+    return;
+
+  result = (movie->color_transform.rb << 16) |
+	   ((movie->color_transform.gb % 256) << 8) | 
+	   (movie->color_transform.bb % 256);
+  SWFDEC_AS_VALUE_SET_INT (rval, result);
+}
+
+static inline void
+add_variable (SwfdecAsObject *obj, const char *name, double value)
+{
+  SwfdecAsValue val;
+
+  SWFDEC_AS_VALUE_SET_NUMBER (&val, value);
+  swfdec_as_object_set_variable (obj, name, &val);
+}
+
+static void
+swfdec_movie_color_getTransform (SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecAsObject *ret;
+  SwfdecMovie *movie = SWFDEC_MOVIE_COLOR (obj)->movie;
+  
+  if (movie == NULL)
+    return;
+
+  ret = swfdec_as_object_new (obj->context);
+  if (ret == NULL)
+    return;
+
+  add_variable (ret, SWFDEC_AS_STR_ra, movie->color_transform.ra * 100.0 / 256.0);
+  add_variable (ret, SWFDEC_AS_STR_ga, movie->color_transform.ga * 100.0 / 256.0);
+  add_variable (ret, SWFDEC_AS_STR_ba, movie->color_transform.ba * 100.0 / 256.0);
+  add_variable (ret, SWFDEC_AS_STR_aa, movie->color_transform.aa * 100.0 / 256.0);
+  add_variable (ret, SWFDEC_AS_STR_rb, movie->color_transform.rb);
+  add_variable (ret, SWFDEC_AS_STR_gb, movie->color_transform.gb);
+  add_variable (ret, SWFDEC_AS_STR_bb, movie->color_transform.bb);
+  add_variable (ret, SWFDEC_AS_STR_ab, movie->color_transform.ab);
+  SWFDEC_AS_VALUE_SET_OBJECT (rval, ret);
+}
+
+static void
+swfdec_movie_color_setRGB (SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  guint color;
+  SwfdecMovie *movie = SWFDEC_MOVIE_COLOR (obj)->movie;
+  
+  if (movie == NULL)
+    return;
+
+  color = swfdec_as_value_to_integer (obj->context, &argv[0]);
+
+  movie->color_transform.ra = 0;
+  movie->color_transform.rb = (color & 0xFF0000) >> 16;
+  movie->color_transform.ga = 0;
+  movie->color_transform.gb = (color & 0xFF00) >> 8;
+  movie->color_transform.ba = 0;
+  movie->color_transform.bb = color & 0xFF;
+  swfdec_movie_invalidate (movie);
+}
+
+static inline void
+parse_property (SwfdecAsObject *obj, const char *name, int *target, gboolean scale)
+{
+  SwfdecAsValue val;
+  double d;
+
+  if (!swfdec_as_object_get_variable (obj, name, &val))
+    return;
+  d = swfdec_as_value_to_number (obj->context, &val);
+  if (scale) {
+    *target = d * 256.0 / 100.0;
+  } else {
+    *target = d;
+  }
+}
+
+static void
+swfdec_movie_color_setTransform (SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecAsObject *parse;
+  SwfdecMovie *movie = SWFDEC_MOVIE_COLOR (obj)->movie;
+  
+  if (movie == NULL)
+    return;
+
+  if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv[0]))
+    return;
+  parse = SWFDEC_AS_VALUE_GET_OBJECT (&argv[0]);
+  parse_property (parse, SWFDEC_AS_STR_ra, &movie->color_transform.ra, TRUE);
+  parse_property (parse, SWFDEC_AS_STR_ga, &movie->color_transform.ga, TRUE);
+  parse_property (parse, SWFDEC_AS_STR_ba, &movie->color_transform.ba, TRUE);
+  parse_property (parse, SWFDEC_AS_STR_aa, &movie->color_transform.aa, TRUE);
+  parse_property (parse, SWFDEC_AS_STR_rb, &movie->color_transform.rb, FALSE);
+  parse_property (parse, SWFDEC_AS_STR_gb, &movie->color_transform.gb, FALSE);
+  parse_property (parse, SWFDEC_AS_STR_bb, &movie->color_transform.bb, FALSE);
+  parse_property (parse, SWFDEC_AS_STR_ab, &movie->color_transform.ab, FALSE);
+  swfdec_movie_invalidate (movie);
+}
+
+static void
+swfdec_movie_color_construct (SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecMovieColor *color = SWFDEC_MOVIE_COLOR (obj);
+
+  if (argc > 0 && SWFDEC_AS_VALUE_IS_OBJECT (&argv[0])) {
+    SwfdecAsObject *object = SWFDEC_AS_VALUE_GET_OBJECT (&argv[0]);
+    if (SWFDEC_IS_MOVIE (object))
+      color->movie = SWFDEC_MOVIE (object);
+  }
+  SWFDEC_AS_VALUE_SET_OBJECT (rval, obj);
+}
+
+void
+swfdec_movie_color_init_context (SwfdecAsContext *context, guint version)
+{
+  SwfdecAsObject *color, *proto;
+  SwfdecAsValue val;
+
+  g_return_if_fail (SWFDEC_IS_AS_CONTEXT (context));
+
+  color = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+      SWFDEC_AS_STR_Color, SWFDEC_TYPE_MOVIE_COLOR, swfdec_movie_color_construct, 0));
+  if (!color)
+    return;
+  if (!swfdec_as_context_use_mem (context, sizeof (SwfdecMovieColor)))
+    return;
+  proto = g_object_new (SWFDEC_TYPE_MOVIE_COLOR, NULL);
+  swfdec_as_object_add (proto, context, sizeof (SwfdecMovieColor));
+  /* set the right properties on the Color object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
+  swfdec_as_object_set_variable (color, SWFDEC_AS_STR_prototype, &val);
+  /* set the right properties on the Color.prototype object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, context->Object_prototype);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR___proto__, &val);
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, color);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_getRGB, SWFDEC_TYPE_MOVIE_COLOR,
+      swfdec_movie_color_getRGB, 0);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_getTransform, SWFDEC_TYPE_MOVIE_COLOR,
+      swfdec_movie_color_getTransform, 0);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_setRGB, SWFDEC_TYPE_MOVIE_COLOR,
+      swfdec_movie_color_setRGB, 1);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_setTransform, SWFDEC_TYPE_MOVIE_COLOR,
+      swfdec_movie_color_setTransform, 1);
+}
+
diff --git a/libswfdec/swfdec_color_as.h b/libswfdec/swfdec_color_as.h
new file mode 100644
index 0000000..7980d5b
--- /dev/null
+++ b/libswfdec/swfdec_color_as.h
@@ -0,0 +1,56 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library 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
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef _SWFDEC_MOVIE_COLOR_H_
+#define _SWFDEC_MOVIE_COLOR_H_
+
+#include <libswfdec/swfdec_as_object.h>
+#include <libswfdec/swfdec_as_types.h>
+#include <libswfdec/swfdec_script.h>
+
+G_BEGIN_DECLS
+
+typedef struct _SwfdecMovieColor SwfdecMovieColor;
+typedef struct _SwfdecMovieColorClass SwfdecMovieColorClass;
+
+#define SWFDEC_TYPE_MOVIE_COLOR                    (swfdec_movie_color_get_type())
+#define SWFDEC_IS_MOVIE_COLOR(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_MOVIE_COLOR))
+#define SWFDEC_IS_MOVIE_COLOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_MOVIE_COLOR))
+#define SWFDEC_MOVIE_COLOR(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_MOVIE_COLOR, SwfdecMovieColor))
+#define SWFDEC_MOVIE_COLOR_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_MOVIE_COLOR, SwfdecMovieColorClass))
+#define SWFDEC_MOVIE_COLOR_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_MOVIE_COLOR, SwfdecMovieColorClass))
+
+struct _SwfdecMovieColor {
+  SwfdecAsObject	object;
+
+  SwfdecMovie *		movie;		/* movie we set the color for or NULL */
+};
+
+struct _SwfdecMovieColorClass {
+  SwfdecAsObjectClass	object_class;
+};
+
+GType		swfdec_movie_color_get_type	(void);
+
+void	      	swfdec_movie_color_init_context	(SwfdecAsContext *	context,
+					      	 guint			version);
+
+
+G_END_DECLS
+#endif
diff --git a/libswfdec/swfdec_js_color.c b/libswfdec/swfdec_js_color.c
deleted file mode 100644
index fe7b1f0..0000000
--- a/libswfdec/swfdec_js_color.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library 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
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfdec_js.h"
-#include "swfdec_debug.h"
-#include "swfdec_movie.h"
-#include "swfdec_player_internal.h"
-
-static JSBool
-swfdec_js_color_get_rgb (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  int result;
-  SwfdecMovie *movie = JS_GetPrivate (cx, obj);
-
-  if (!movie)
-    return JS_TRUE;
-  result = (movie->color_transform.rb << 16) |
-	   ((movie->color_transform.gb % 256) << 8) | 
-	   (movie->color_transform.bb % 256);
-  *rval = INT_TO_JSVAL (result);
-  return JS_TRUE;
-}
-
-static inline void
-add_variable (JSContext *cx, JSObject *obj, const char *name, double value)
-{
-  jsval val;
-
-  if (JS_NewNumberValue (cx, value, &val))
-    JS_SetProperty (cx, obj, name, &val);
-}
-
-static JSBool
-swfdec_js_color_get_transform (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  JSObject *ret;
-  SwfdecMovie *movie = JS_GetPrivate (cx, obj);
-
-  if (!movie)
-    return JS_TRUE;
-  ret = JS_NewObject (cx, NULL, NULL, NULL);
-  if (ret == NULL)
-    return JS_TRUE;
-
-  add_variable (cx, ret, "ra", movie->color_transform.ra * 100.0 / 256.0);
-  add_variable (cx, ret, "ga", movie->color_transform.ga * 100.0 / 256.0);
-  add_variable (cx, ret, "ba", movie->color_transform.ba * 100.0 / 256.0);
-  add_variable (cx, ret, "aa", movie->color_transform.aa * 100.0 / 256.0);
-  add_variable (cx, ret, "rb", movie->color_transform.rb);
-  add_variable (cx, ret, "gb", movie->color_transform.gb);
-  add_variable (cx, ret, "bb", movie->color_transform.bb);
-  add_variable (cx, ret, "ab", movie->color_transform.ab);
-  *rval = OBJECT_TO_JSVAL (ret);
-  return JS_TRUE;
-}
-
-static JSBool
-swfdec_js_color_set_rgb (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  guint color;
-  SwfdecMovie *movie = JS_GetPrivate (cx, obj);
-
-  if (!movie)
-    return JS_TRUE;
-  if (!JS_ValueToECMAUint32 (cx, argv[0], &color))
-    return JS_TRUE;
-
-  movie->color_transform.ra = 0;
-  movie->color_transform.rb = (color & 0xFF0000) >> 16;
-  movie->color_transform.ga = 0;
-  movie->color_transform.gb = (color & 0xFF00) >> 8;
-  movie->color_transform.ba = 0;
-  movie->color_transform.bb = color & 0xFF;
-  swfdec_movie_invalidate (movie);
-  return JS_TRUE;
-}
-
-static inline void
-parse_property (JSContext *cx, JSObject *obj, const char *name, int *target, gboolean scale)
-{
-  jsval val;
-  double d;
-
-  if (!JS_GetProperty (cx, obj, name, &val))
-    return;
-  if (JSVAL_IS_VOID (val))
-    return;
-  if (!JS_ValueToNumber (cx, val, &d))
-    return;
-  if (scale) {
-    *target = d * 256.0 / 100.0;
-  } else {
-    *target = d;
-  }
-}
-
-static JSBool
-swfdec_js_color_set_transform (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  JSObject *parse;
-  SwfdecMovie *movie = JS_GetPrivate (cx, obj);
-
-  if (!movie)
-    return JS_TRUE;
-  if (!movie)
-    return JS_TRUE;
-  parse = JSVAL_TO_OBJECT (argv[0]);
-  parse_property (cx, parse, "ra", &movie->color_transform.ra, TRUE);
-  parse_property (cx, parse, "ga", &movie->color_transform.ga, TRUE);
-  parse_property (cx, parse, "ba", &movie->color_transform.ba, TRUE);
-  parse_property (cx, parse, "aa", &movie->color_transform.aa, TRUE);
-  parse_property (cx, parse, "rb", &movie->color_transform.rb, FALSE);
-  parse_property (cx, parse, "gb", &movie->color_transform.gb, FALSE);
-  parse_property (cx, parse, "bb", &movie->color_transform.bb, FALSE);
-  parse_property (cx, parse, "ab", &movie->color_transform.ab, FALSE);
-  swfdec_movie_invalidate (movie);
-  return JS_TRUE;
-}
-
-static JSFunctionSpec color_methods[] = {
-  { "getRGB",		swfdec_js_color_get_rgb,	1, 0, 0 },
-  { "getTransform",  	swfdec_js_color_get_transform,	1, 0, 0 },
-  { "setRGB",		swfdec_js_color_set_rgb,	1, 0, 0 },
-  { "setTransform",  	swfdec_js_color_set_transform,	1, 0, 0 },
-  {0,0,0,0,0}
-};
-
-static void
-swfdec_js_color_finalize (JSContext *cx, JSObject *obj)
-{
-  SwfdecMovie *movie;
-
-  movie = JS_GetPrivate (cx, obj);
-  if (movie) {
-    g_object_unref (movie);
-  }
-}
-
-static JSClass color_class = {
-    "Color", JSCLASS_HAS_PRIVATE,
-    JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
-    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_color_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-static JSBool
-swfdec_js_color_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecMovie *movie;
-
-  if (argc > 0) {
-    movie = swfdec_scriptable_from_jsval (cx, argv[0], SWFDEC_TYPE_MOVIE);
-  } else {
-    movie = NULL;
-  }
-  if (movie != NULL) {
-    if (!JS_SetPrivate (cx, obj, movie))
-      return JS_FALSE;
-    g_object_ref (movie);
-  }
-  *rval = OBJECT_TO_JSVAL (obj);
-  return JS_TRUE;
-}
-
-void
-swfdec_js_add_color (SwfdecPlayer *player)
-{
-  JS_InitClass (player->jscx, player->jsobj, NULL,
-      &color_class, swfdec_js_color_new, 0, NULL, color_methods,
-      NULL, NULL);
-}
-
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index ec783b7..74a8e7c 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1020,6 +1020,7 @@ swfdec_player_launch (SwfdecPlayer *play
 
 extern void swfdec_player_init_global (SwfdecPlayer *player, guint version);
 extern void swfdec_mouse_init_context (SwfdecPlayer *player, guint version);
+extern void swfdec_movie_color_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_sprite_movie_init_context (SwfdecPlayer *player, guint version);
 /**
  * swfdec_player_initialize:
@@ -1052,6 +1053,7 @@ swfdec_player_initialize (SwfdecPlayer *
     swfdec_player_init_global (player, version);
     swfdec_mouse_init_context (player, version);
     swfdec_sprite_movie_init_context (player, version);
+    swfdec_movie_color_init_context (player, version);
     if (context->state == SWFDEC_AS_CONTEXT_NEW) {
       context->state = SWFDEC_AS_CONTEXT_RUNNING;
       swfdec_as_object_set_constructor (player->roots->data, player->MovieClip);
diff-tree ebdd3d457ee189c03941ed1fab0ab14a7f1ee990 (from f847682cb4372a9e77801399bcd57b56ae8eb253)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 15:01:16 2007 +0200

    make swfdec_as_object_get_variable return TRUE/FALSE if the variable exists

diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 6152d51..8153c32 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -309,7 +309,7 @@ swfdec_as_object_lookup (SwfdecAsObject 
   return klass->get (object, variable, value, flags);
 }
 
-void
+gboolean
 swfdec_as_object_get_variable (SwfdecAsObject *object, 
     const char *variable, SwfdecAsValue *value)
 {
@@ -321,15 +321,16 @@ swfdec_as_object_get_variable (SwfdecAsO
 
   for (i = 0; i < 256 && object != NULL; i++) {
     if (swfdec_as_object_lookup (object, variable, value, NULL))
-      return;
+      return TRUE;
     object = object->prototype;
   }
   if (i == 256) {
     swfdec_as_context_abort (object->context, "Prototype recursion limit exceeded");
-    return;
+    return FALSE;
   }
   //SWFDEC_WARNING ("no such variable %s", variable);
   SWFDEC_AS_VALUE_SET_UNDEFINED (value);
+  return FALSE:
 }
 
 void
diff --git a/libswfdec/swfdec_as_object.h b/libswfdec/swfdec_as_object.h
index c677d51..c834310 100644
--- a/libswfdec/swfdec_as_object.h
+++ b/libswfdec/swfdec_as_object.h
@@ -110,7 +110,7 @@ void		swfdec_as_object_unroot	  	(Swfdec
 void		swfdec_as_object_set_variable	(SwfdecAsObject *	object,
 						 const char *		variable,
 						 const SwfdecAsValue *	value);
-void		swfdec_as_object_get_variable	(SwfdecAsObject *	object,
+gboolean	swfdec_as_object_get_variable	(SwfdecAsObject *	object,
 						 const char *		variable,
 						 SwfdecAsValue *	value);
 void		swfdec_as_object_delete_variable(SwfdecAsObject *	object,
diff-tree f847682cb4372a9e77801399bcd57b56ae8eb253 (from 9611954464237c3162a09458e506840adb0943e5)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue May 22 14:48:51 2007 +0200

    fix various cases that assumed frame->thisp != NULL

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 1bca426..44ee604 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -418,7 +418,9 @@ start:
   if (SWFDEC_IS_AS_NATIVE_FUNCTION (frame->function)) {
     SwfdecAsNativeFunction *native = SWFDEC_AS_NATIVE_FUNCTION (frame->function);
     if (frame->argc >= native->min_args && 
-	(native->type == 0 || g_type_is_a (G_OBJECT_TYPE (frame->thisp), native->type))) {
+	(native->type == 0 || 
+	 (frame->thisp != NULL && 
+	  !g_type_is_a (G_OBJECT_TYPE (frame->thisp), native->type)))) {
       native->native (frame->thisp, frame->argc, frame->argv, frame->return_value);
     }
     swfdec_as_context_return (context);
diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index 75e0534..2982e3c 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -228,11 +228,13 @@ swfdec_as_frame_find_variable (SwfdecAsF
     ret = swfdec_as_object_find_variable (frame->target, variable);
     if (ret)
       return frame->target;
-  } else {
+  } else if (frame->thisp) {
     /* The default target is the original object that called into us */
     ret = swfdec_as_object_find_variable (SWFDEC_AS_FRAME (cur)->thisp, variable);
     if (ret)
       return SWFDEC_AS_FRAME (cur)->thisp;
+  } else {
+    SWFDEC_ERROR ("FIXME: what happens when no target and no this exists?");
   }
   /* 2) the global object */
   ret = swfdec_as_object_find_variable (SWFDEC_AS_OBJECT (frame)->context->global, variable);
diff --git a/libswfdec/swfdec_as_frame.h b/libswfdec/swfdec_as_frame.h
index 3cacbb1..97f119f 100644
--- a/libswfdec/swfdec_as_frame.h
+++ b/libswfdec/swfdec_as_frame.h
@@ -40,7 +40,7 @@ struct _SwfdecAsFrame {
 
   SwfdecAsFrame *	next;		/* next frame (FIXME: keep a list in the context instead?) */
   SwfdecAsFunction *	function;	/* function we're executing or NULL if toplevel */
-  SwfdecAsObject *	thisp;		/* this object in current frame */
+  SwfdecAsObject *	thisp;		/* this object in current frame or NULL if none */
   gboolean		construct;	/* TRUE if this is the constructor for thisp */
   /* debugging */
   char *		function_name;	/* name of function */


More information about the Swfdec mailing list