2 * Copyright (C) 2006-2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_color_as.h"
25 #include "swfdec_as_context.h"
26 #include "swfdec_as_native_function.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_internal.h"
30 #include "swfdec_movie.h"
32 G_DEFINE_TYPE (SwfdecMovieColor
, swfdec_movie_color
, SWFDEC_TYPE_AS_OBJECT
)
35 swfdec_movie_color_mark (SwfdecAsObject
*object
)
37 SwfdecMovieColor
*color
= SWFDEC_MOVIE_COLOR (object
);
39 /* FIXME: unset movie when movie is already dead */
41 swfdec_as_object_mark (SWFDEC_AS_OBJECT (color
->movie
));
43 SWFDEC_AS_OBJECT_CLASS (swfdec_movie_color_parent_class
)->mark (object
);
47 swfdec_movie_color_class_init (SwfdecMovieColorClass
*klass
)
49 SwfdecAsObjectClass
*asobject_class
= SWFDEC_AS_OBJECT_CLASS (klass
);
51 asobject_class
->mark
= swfdec_movie_color_mark
;
55 swfdec_movie_color_init (SwfdecMovieColor
*color
)
62 swfdec_movie_color_getRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
63 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
66 SwfdecMovie
*movie
= SWFDEC_MOVIE_COLOR (obj
)->movie
;
71 result
= (movie
->color_transform
.rb
<< 16) |
72 ((movie
->color_transform
.gb
% 256) << 8) |
73 (movie
->color_transform
.bb
% 256);
74 SWFDEC_AS_VALUE_SET_INT (rval
, result
);
78 add_variable (SwfdecAsObject
*obj
, const char *name
, double value
)
82 SWFDEC_AS_VALUE_SET_NUMBER (&val
, value
);
83 swfdec_as_object_set_variable (obj
, name
, &val
);
87 swfdec_movie_color_getTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
88 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
91 SwfdecMovie
*movie
= SWFDEC_MOVIE_COLOR (obj
)->movie
;
96 ret
= swfdec_as_object_new (cx
);
100 add_variable (ret
, SWFDEC_AS_STR_ra
, movie
->color_transform
.ra
* 100.0 / 256.0);
101 add_variable (ret
, SWFDEC_AS_STR_ga
, movie
->color_transform
.ga
* 100.0 / 256.0);
102 add_variable (ret
, SWFDEC_AS_STR_ba
, movie
->color_transform
.ba
* 100.0 / 256.0);
103 add_variable (ret
, SWFDEC_AS_STR_aa
, movie
->color_transform
.aa
* 100.0 / 256.0);
104 add_variable (ret
, SWFDEC_AS_STR_rb
, movie
->color_transform
.rb
);
105 add_variable (ret
, SWFDEC_AS_STR_gb
, movie
->color_transform
.gb
);
106 add_variable (ret
, SWFDEC_AS_STR_bb
, movie
->color_transform
.bb
);
107 add_variable (ret
, SWFDEC_AS_STR_ab
, movie
->color_transform
.ab
);
108 SWFDEC_AS_VALUE_SET_OBJECT (rval
, ret
);
112 swfdec_movie_color_setRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
113 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
116 SwfdecMovie
*movie
= SWFDEC_MOVIE_COLOR (obj
)->movie
;
121 color
= swfdec_as_value_to_integer (cx
, &argv
[0]);
123 movie
->color_transform
.ra
= 0;
124 movie
->color_transform
.rb
= (color
& 0xFF0000) >> 16;
125 movie
->color_transform
.ga
= 0;
126 movie
->color_transform
.gb
= (color
& 0xFF00) >> 8;
127 movie
->color_transform
.ba
= 0;
128 movie
->color_transform
.bb
= color
& 0xFF;
129 swfdec_movie_invalidate (movie
);
133 parse_property (SwfdecAsObject
*obj
, const char *name
, int *target
, gboolean scale
)
138 if (!swfdec_as_object_get_variable (obj
, name
, &val
))
140 d
= swfdec_as_value_to_number (obj
->context
, &val
);
142 *target
= d
* 256.0 / 100.0;
149 swfdec_movie_color_setTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
150 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
152 SwfdecAsObject
*parse
;
153 SwfdecMovie
*movie
= SWFDEC_MOVIE_COLOR (obj
)->movie
;
158 if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv
[0]))
160 parse
= SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0]);
161 parse_property (parse
, SWFDEC_AS_STR_ra
, &movie
->color_transform
.ra
, TRUE
);
162 parse_property (parse
, SWFDEC_AS_STR_ga
, &movie
->color_transform
.ga
, TRUE
);
163 parse_property (parse
, SWFDEC_AS_STR_ba
, &movie
->color_transform
.ba
, TRUE
);
164 parse_property (parse
, SWFDEC_AS_STR_aa
, &movie
->color_transform
.aa
, TRUE
);
165 parse_property (parse
, SWFDEC_AS_STR_rb
, &movie
->color_transform
.rb
, FALSE
);
166 parse_property (parse
, SWFDEC_AS_STR_gb
, &movie
->color_transform
.gb
, FALSE
);
167 parse_property (parse
, SWFDEC_AS_STR_bb
, &movie
->color_transform
.bb
, FALSE
);
168 parse_property (parse
, SWFDEC_AS_STR_ab
, &movie
->color_transform
.ab
, FALSE
);
169 swfdec_movie_invalidate (movie
);
173 swfdec_movie_color_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
174 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
176 SwfdecMovieColor
*color
= SWFDEC_MOVIE_COLOR (obj
);
178 if (argc
> 0 && SWFDEC_AS_VALUE_IS_OBJECT (&argv
[0])) {
179 SwfdecAsObject
*object
= SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0]);
180 if (SWFDEC_IS_MOVIE (object
))
181 color
->movie
= SWFDEC_MOVIE (object
);
183 SWFDEC_AS_VALUE_SET_OBJECT (rval
, obj
);
187 swfdec_movie_color_init_context (SwfdecPlayer
*player
, guint version
)
189 SwfdecAsContext
*context
;
190 SwfdecAsObject
*color
, *proto
;
193 g_return_if_fail (SWFDEC_IS_PLAYER (player
));
195 context
= SWFDEC_AS_CONTEXT (player
);
196 color
= SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context
->global
,
197 SWFDEC_AS_STR_Color
, SWFDEC_TYPE_MOVIE_COLOR
, swfdec_movie_color_construct
, 0));
198 swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (color
), SWFDEC_TYPE_MOVIE_COLOR
);
201 if (!swfdec_as_context_use_mem (context
, sizeof (SwfdecMovieColor
)))
203 proto
= g_object_new (SWFDEC_TYPE_MOVIE_COLOR
, NULL
);
204 swfdec_as_object_add (proto
, context
, sizeof (SwfdecMovieColor
));
205 /* set the right properties on the Color object */
206 SWFDEC_AS_VALUE_SET_OBJECT (&val
, proto
);
207 swfdec_as_object_set_variable (color
, SWFDEC_AS_STR_prototype
, &val
);
208 /* set the right properties on the Color.prototype object */
209 SWFDEC_AS_VALUE_SET_OBJECT (&val
, context
->Object_prototype
);
210 swfdec_as_object_set_variable (proto
, SWFDEC_AS_STR___proto__
, &val
);
211 SWFDEC_AS_VALUE_SET_OBJECT (&val
, color
);
212 swfdec_as_object_set_variable (proto
, SWFDEC_AS_STR_constructor
, &val
);
213 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_getRGB
, SWFDEC_TYPE_MOVIE_COLOR
,
214 swfdec_movie_color_getRGB
, 0);
215 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_getTransform
, SWFDEC_TYPE_MOVIE_COLOR
,
216 swfdec_movie_color_getTransform
, 0);
217 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_setRGB
, SWFDEC_TYPE_MOVIE_COLOR
,
218 swfdec_movie_color_setRGB
, 1);
219 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_setTransform
, SWFDEC_TYPE_MOVIE_COLOR
,
220 swfdec_movie_color_setTransform
, 1);