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
)
42 swfdec_as_object_get_variable (object
, SWFDEC_AS_STR_target
, &val
);
43 if (!SWFDEC_AS_VALUE_IS_MOVIE (*&val
))
46 return SWFDEC_AS_VALUE_GET_MOVIE (*&val
);
49 SWFDEC_AS_NATIVE (700, 2, swfdec_movie_color_getRGB
)
51 swfdec_movie_color_getRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
52 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
57 movie
= swfdec_movie_color_get_movie (obj
);
62 result
= (movie
->color_transform
.rb
<< 16) |
63 ((movie
->color_transform
.gb
% 256) << 8) |
64 (movie
->color_transform
.bb
% 256);
65 swfdec_as_value_set_integer (cx
, ret
, result
);
69 add_variable (SwfdecAsObject
*obj
, const char *name
, double value
)
73 swfdec_as_value_set_number (obj
->context
, &val
, value
);
74 swfdec_as_object_set_variable (obj
, name
, &val
);
77 SWFDEC_AS_NATIVE (700, 3, swfdec_movie_color_getTransform
)
79 swfdec_movie_color_getTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
80 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
85 movie
= swfdec_movie_color_get_movie (obj
);
90 ret
= swfdec_as_object_new (cx
, SWFDEC_AS_STR_Object
, NULL
);
92 add_variable (ret
, SWFDEC_AS_STR_ra
, movie
->color_transform
.ra
* 100.0 / 256.0);
93 add_variable (ret
, SWFDEC_AS_STR_ga
, movie
->color_transform
.ga
* 100.0 / 256.0);
94 add_variable (ret
, SWFDEC_AS_STR_ba
, movie
->color_transform
.ba
* 100.0 / 256.0);
95 add_variable (ret
, SWFDEC_AS_STR_aa
, movie
->color_transform
.aa
* 100.0 / 256.0);
96 add_variable (ret
, SWFDEC_AS_STR_rb
, movie
->color_transform
.rb
);
97 add_variable (ret
, SWFDEC_AS_STR_gb
, movie
->color_transform
.gb
);
98 add_variable (ret
, SWFDEC_AS_STR_bb
, movie
->color_transform
.bb
);
99 add_variable (ret
, SWFDEC_AS_STR_ab
, movie
->color_transform
.ab
);
100 SWFDEC_AS_VALUE_SET_OBJECT (rval
, ret
);
103 SWFDEC_AS_NATIVE (700, 0, swfdec_movie_color_setRGB
)
105 swfdec_movie_color_setRGB (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
106 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
114 movie
= swfdec_movie_color_get_movie (obj
);
119 color
= swfdec_as_value_to_integer (cx
, &argv
[0]);
121 movie
->color_transform
.ra
= 0;
122 movie
->color_transform
.rb
= (color
& 0xFF0000) >> 16;
123 movie
->color_transform
.ga
= 0;
124 movie
->color_transform
.gb
= (color
& 0xFF00) >> 8;
125 movie
->color_transform
.ba
= 0;
126 movie
->color_transform
.bb
= color
& 0xFF;
127 swfdec_movie_invalidate_last (movie
);
131 parse_property (SwfdecAsObject
*obj
, const char *name
, int *target
, gboolean scale
)
136 if (!swfdec_as_object_get_variable (obj
, name
, &val
))
138 d
= swfdec_as_value_to_number (obj
->context
, &val
);
140 *target
= d
* 256.0 / 100.0;
146 SWFDEC_AS_NATIVE (700, 1, swfdec_movie_color_setTransform
)
148 swfdec_movie_color_setTransform (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
149 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
151 SwfdecAsObject
*parse
;
157 movie
= swfdec_movie_color_get_movie (obj
);
162 if (!SWFDEC_AS_VALUE_IS_COMPOSITE (*&argv
[0]))
164 parse
= SWFDEC_AS_VALUE_GET_COMPOSITE (*&argv
[0]);
167 parse_property (parse
, SWFDEC_AS_STR_ra
, &movie
->color_transform
.ra
, TRUE
);
168 parse_property (parse
, SWFDEC_AS_STR_ga
, &movie
->color_transform
.ga
, TRUE
);
169 parse_property (parse
, SWFDEC_AS_STR_ba
, &movie
->color_transform
.ba
, TRUE
);
170 parse_property (parse
, SWFDEC_AS_STR_aa
, &movie
->color_transform
.aa
, TRUE
);
171 parse_property (parse
, SWFDEC_AS_STR_rb
, &movie
->color_transform
.rb
, FALSE
);
172 parse_property (parse
, SWFDEC_AS_STR_gb
, &movie
->color_transform
.gb
, FALSE
);
173 parse_property (parse
, SWFDEC_AS_STR_bb
, &movie
->color_transform
.bb
, FALSE
);
174 parse_property (parse
, SWFDEC_AS_STR_ab
, &movie
->color_transform
.ab
, FALSE
);
175 swfdec_movie_invalidate_last (movie
);