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_as_context.h"
25 #include "swfdec_as_native_function.h"
26 #include "swfdec_as_strings.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_internal.h"
29 #include "swfdec_as_internal.h"
30 #include "swfdec_movie.h"
35 swfdec_movie_color_get_movie (SwfdecAsObject
*object
)
38 SwfdecAsObject
*target
;
43 swfdec_as_object_get_variable (object
, SWFDEC_AS_STR_target
, &val
);
44 if (!SWFDEC_AS_VALUE_IS_OBJECT (&val
))
47 target
= SWFDEC_AS_VALUE_GET_OBJECT (&val
);
48 if (!SWFDEC_IS_MOVIE (target
))
51 return SWFDEC_MOVIE (target
);
54 SWFDEC_AS_NATIVE (700, 2, swfdec_movie_color_getRGB
)
56 swfdec_movie_color_getRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
57 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
62 movie
= swfdec_movie_color_get_movie (obj
);
67 result
= (movie
->color_transform
.rb
<< 16) |
68 ((movie
->color_transform
.gb
% 256) << 8) |
69 (movie
->color_transform
.bb
% 256);
70 SWFDEC_AS_VALUE_SET_INT (ret
, result
);
74 add_variable (SwfdecAsObject
*obj
, const char *name
, double value
)
78 SWFDEC_AS_VALUE_SET_NUMBER (&val
, value
);
79 swfdec_as_object_set_variable (obj
, name
, &val
);
82 SWFDEC_AS_NATIVE (700, 3, swfdec_movie_color_getTransform
)
84 swfdec_movie_color_getTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
85 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
90 movie
= swfdec_movie_color_get_movie (obj
);
95 ret
= swfdec_as_object_new (cx
);
97 add_variable (ret
, SWFDEC_AS_STR_ra
, movie
->color_transform
.ra
* 100.0 / 256.0);
98 add_variable (ret
, SWFDEC_AS_STR_ga
, movie
->color_transform
.ga
* 100.0 / 256.0);
99 add_variable (ret
, SWFDEC_AS_STR_ba
, movie
->color_transform
.ba
* 100.0 / 256.0);
100 add_variable (ret
, SWFDEC_AS_STR_aa
, movie
->color_transform
.aa
* 100.0 / 256.0);
101 add_variable (ret
, SWFDEC_AS_STR_rb
, movie
->color_transform
.rb
);
102 add_variable (ret
, SWFDEC_AS_STR_gb
, movie
->color_transform
.gb
);
103 add_variable (ret
, SWFDEC_AS_STR_bb
, movie
->color_transform
.bb
);
104 add_variable (ret
, SWFDEC_AS_STR_ab
, movie
->color_transform
.ab
);
105 SWFDEC_AS_VALUE_SET_OBJECT (rval
, ret
);
108 SWFDEC_AS_NATIVE (700, 0, swfdec_movie_color_setRGB
)
110 swfdec_movie_color_setRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
111 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
119 movie
= swfdec_movie_color_get_movie (obj
);
124 color
= swfdec_as_value_to_integer (cx
, &argv
[0]);
126 movie
->color_transform
.ra
= 0;
127 movie
->color_transform
.rb
= (color
& 0xFF0000) >> 16;
128 movie
->color_transform
.ga
= 0;
129 movie
->color_transform
.gb
= (color
& 0xFF00) >> 8;
130 movie
->color_transform
.ba
= 0;
131 movie
->color_transform
.bb
= color
& 0xFF;
132 swfdec_movie_invalidate_last (movie
);
136 parse_property (SwfdecAsObject
*obj
, const char *name
, int *target
, gboolean scale
)
141 if (!swfdec_as_object_get_variable (obj
, name
, &val
))
143 d
= swfdec_as_value_to_number (swfdec_gc_object_get_context (obj
), &val
);
145 *target
= d
* 256.0 / 100.0;
151 SWFDEC_AS_NATIVE (700, 1, swfdec_movie_color_setTransform
)
153 swfdec_movie_color_setTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
154 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
156 SwfdecAsObject
*parse
;
162 movie
= swfdec_movie_color_get_movie (obj
);
167 if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv
[0]))
169 parse
= SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0]);
170 parse_property (parse
, SWFDEC_AS_STR_ra
, &movie
->color_transform
.ra
, TRUE
);
171 parse_property (parse
, SWFDEC_AS_STR_ga
, &movie
->color_transform
.ga
, TRUE
);
172 parse_property (parse
, SWFDEC_AS_STR_ba
, &movie
->color_transform
.ba
, TRUE
);
173 parse_property (parse
, SWFDEC_AS_STR_aa
, &movie
->color_transform
.aa
, TRUE
);
174 parse_property (parse
, SWFDEC_AS_STR_rb
, &movie
->color_transform
.rb
, FALSE
);
175 parse_property (parse
, SWFDEC_AS_STR_gb
, &movie
->color_transform
.gb
, FALSE
);
176 parse_property (parse
, SWFDEC_AS_STR_bb
, &movie
->color_transform
.bb
, FALSE
);
177 parse_property (parse
, SWFDEC_AS_STR_ab
, &movie
->color_transform
.ab
, FALSE
);
178 swfdec_movie_invalidate_last (movie
);