2 * Copyright (C) 2007 Pekka Lampila <pekka.lampila@iki.fi>
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_transform_as.h"
25 #include "swfdec_as_strings.h"
26 #include "swfdec_as_internal.h"
27 #include "swfdec_as_frame_internal.h"
28 #include "swfdec_debug.h"
30 G_DEFINE_TYPE (SwfdecColorTransformAs
, swfdec_color_transform_as
, SWFDEC_TYPE_AS_RELAY
)
33 swfdec_color_transform_as_class_init (SwfdecColorTransformAsClass
*klass
)
38 swfdec_color_transform_as_init (SwfdecColorTransformAs
*transform
)
51 SWFDEC_AS_NATIVE (1105, 101, swfdec_color_transform_as_get_alphaMultiplier
)
53 swfdec_color_transform_as_get_alphaMultiplier (SwfdecAsContext
*cx
,
54 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
57 SwfdecColorTransformAs
*transform
;
59 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
61 *ret
= swfdec_as_value_from_number (cx
, transform
->aa
);
64 SWFDEC_AS_NATIVE (1105, 102, swfdec_color_transform_as_set_alphaMultiplier
)
66 swfdec_color_transform_as_set_alphaMultiplier (SwfdecAsContext
*cx
,
67 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
70 SwfdecColorTransformAs
*transform
;
73 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
75 transform
->aa
= value
;
78 SWFDEC_AS_NATIVE (1105, 103, swfdec_color_transform_as_get_redMultiplier
)
80 swfdec_color_transform_as_get_redMultiplier (SwfdecAsContext
*cx
,
81 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
84 SwfdecColorTransformAs
*transform
;
86 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
88 *ret
= swfdec_as_value_from_number (cx
, transform
->ra
);
91 SWFDEC_AS_NATIVE (1105, 104, swfdec_color_transform_as_set_redMultiplier
)
93 swfdec_color_transform_as_set_redMultiplier (SwfdecAsContext
*cx
,
94 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
97 SwfdecColorTransformAs
*transform
;
100 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
102 transform
->ra
= value
;
105 SWFDEC_AS_NATIVE (1105, 105, swfdec_color_transform_as_get_greenMultiplier
)
107 swfdec_color_transform_as_get_greenMultiplier (SwfdecAsContext
*cx
,
108 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
111 SwfdecColorTransformAs
*transform
;
113 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
115 *ret
= swfdec_as_value_from_number (cx
, transform
->ga
);
118 SWFDEC_AS_NATIVE (1105, 106, swfdec_color_transform_as_set_greenMultiplier
)
120 swfdec_color_transform_as_set_greenMultiplier (SwfdecAsContext
*cx
,
121 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
124 SwfdecColorTransformAs
*transform
;
127 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
129 transform
->ga
= value
;
132 SWFDEC_AS_NATIVE (1105, 107, swfdec_color_transform_as_get_blueMultiplier
)
134 swfdec_color_transform_as_get_blueMultiplier (SwfdecAsContext
*cx
,
135 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
138 SwfdecColorTransformAs
*transform
;
140 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
142 *ret
= swfdec_as_value_from_number (cx
, transform
->ba
);
145 SWFDEC_AS_NATIVE (1105, 108, swfdec_color_transform_as_set_blueMultiplier
)
147 swfdec_color_transform_as_set_blueMultiplier (SwfdecAsContext
*cx
,
148 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
151 SwfdecColorTransformAs
*transform
;
154 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
156 transform
->ba
= value
;
159 SWFDEC_AS_NATIVE (1105, 109, swfdec_color_transform_as_get_alphaOffset
)
161 swfdec_color_transform_as_get_alphaOffset (SwfdecAsContext
*cx
,
162 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
165 SwfdecColorTransformAs
*transform
;
167 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
169 *ret
= swfdec_as_value_from_number (cx
, transform
->ab
);
172 SWFDEC_AS_NATIVE (1105, 110, swfdec_color_transform_as_set_alphaOffset
)
174 swfdec_color_transform_as_set_alphaOffset (SwfdecAsContext
*cx
,
175 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
178 SwfdecColorTransformAs
*transform
;
181 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
183 transform
->ab
= value
;
186 SWFDEC_AS_NATIVE (1105, 111, swfdec_color_transform_as_get_redOffset
)
188 swfdec_color_transform_as_get_redOffset (SwfdecAsContext
*cx
,
189 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
192 SwfdecColorTransformAs
*transform
;
194 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
196 *ret
= swfdec_as_value_from_number (cx
, transform
->rb
);
199 SWFDEC_AS_NATIVE (1105, 112, swfdec_color_transform_as_set_redOffset
)
201 swfdec_color_transform_as_set_redOffset (SwfdecAsContext
*cx
,
202 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
205 SwfdecColorTransformAs
*transform
;
208 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
210 transform
->rb
= value
;
213 SWFDEC_AS_NATIVE (1105, 113, swfdec_color_transform_as_get_greenOffset
)
215 swfdec_color_transform_as_get_greenOffset (SwfdecAsContext
*cx
,
216 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
219 SwfdecColorTransformAs
*transform
;
221 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
223 *ret
= swfdec_as_value_from_number (cx
, transform
->gb
);
226 SWFDEC_AS_NATIVE (1105, 114, swfdec_color_transform_as_set_greenOffset
)
228 swfdec_color_transform_as_set_greenOffset (SwfdecAsContext
*cx
,
229 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
232 SwfdecColorTransformAs
*transform
;
235 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
237 transform
->gb
= value
;
240 SWFDEC_AS_NATIVE (1105, 115, swfdec_color_transform_as_get_blueOffset
)
242 swfdec_color_transform_as_get_blueOffset (SwfdecAsContext
*cx
,
243 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
246 SwfdecColorTransformAs
*transform
;
248 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
250 *ret
= swfdec_as_value_from_number (cx
, transform
->bb
);
253 SWFDEC_AS_NATIVE (1105, 116, swfdec_color_transform_as_set_blueOffset
)
255 swfdec_color_transform_as_set_blueOffset (SwfdecAsContext
*cx
,
256 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
259 SwfdecColorTransformAs
*transform
;
262 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "n", &value
);
264 transform
->bb
= value
;
267 SWFDEC_AS_NATIVE (1105, 117, swfdec_color_transform_as_get_rgb
)
269 swfdec_color_transform_as_get_rgb (SwfdecAsContext
*cx
,
270 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
273 SwfdecColorTransformAs
*transform
;
276 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "");
278 // important to calculate the value this way, to get right results with
280 value
= swfdec_as_double_to_integer (transform
->rb
) << 16;
281 value
|= swfdec_as_double_to_integer (transform
->gb
) << 8;
282 value
|= swfdec_as_double_to_integer (transform
->bb
);
284 *ret
= swfdec_as_value_from_integer (cx
, value
);
287 SWFDEC_AS_NATIVE (1105, 118, swfdec_color_transform_as_set_rgb
)
289 swfdec_color_transform_as_set_rgb (SwfdecAsContext
*cx
,
290 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
293 SwfdecColorTransformAs
*transform
;
296 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "i", &value
);
301 transform
->rb
= (value
& 0xFF0000) >> 16;
302 transform
->gb
= (value
& 0x00FF00) >> 8;
303 transform
->bb
= (value
& 0x0000FF);
307 SWFDEC_AS_NATIVE (1105, 1, swfdec_color_transform_as_concat
)
309 swfdec_color_transform_as_concat (SwfdecAsContext
*cx
,
310 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
313 SwfdecColorTransformAs
*transform
, *other
;
314 SwfdecAsObject
*other_object
;
316 SWFDEC_AS_CHECK (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, &transform
, "o",
319 if (!SWFDEC_IS_COLOR_TRANSFORM_AS (other_object
->relay
))
321 other
= SWFDEC_COLOR_TRANSFORM_AS (other_object
->relay
);
323 transform
->rb
+= (transform
->ra
* other
->rb
);
324 transform
->gb
+= (transform
->ga
* other
->gb
);
325 transform
->bb
+= (transform
->ba
* other
->bb
);
326 transform
->ab
+= (transform
->aa
* other
->ab
);
327 transform
->ra
*= other
->ra
;
328 transform
->ga
*= other
->ga
;
329 transform
->ba
*= other
->ba
;
330 transform
->aa
*= other
->aa
;
334 SWFDEC_AS_NATIVE (1105, 0, swfdec_color_transform_as_construct
)
336 swfdec_color_transform_as_construct (SwfdecAsContext
*cx
,
337 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
340 SwfdecColorTransformAs
*transform
;
342 if (!swfdec_as_context_is_constructing (cx
))
345 transform
= g_object_new (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, "context", cx
, NULL
);
346 swfdec_as_object_set_relay (object
, SWFDEC_AS_RELAY (transform
));
347 SWFDEC_AS_VALUE_SET_OBJECT (ret
, object
);
352 SWFDEC_AS_CHECK (0, NULL
, "nnnnnnnn",
353 &transform
->ra
, &transform
->ga
, &transform
->ba
, &transform
->aa
,
354 &transform
->rb
, &transform
->gb
, &transform
->bb
, &transform
->ab
);
357 SwfdecColorTransformAs
*
358 swfdec_color_transform_as_new_from_transform (SwfdecAsContext
*context
,
359 const SwfdecColorTransform
*transform
)
361 SwfdecColorTransformAs
*transform_as
;
362 SwfdecAsObject
*object
;
364 g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context
), NULL
);
365 g_return_val_if_fail (transform
!= NULL
, NULL
);
367 transform_as
= g_object_new (SWFDEC_TYPE_COLOR_TRANSFORM_AS
, "context", context
, NULL
);
368 /* do it this way so the constructor isn't called */
369 object
= swfdec_as_object_new (context
, NULL
);
370 swfdec_as_object_set_relay (object
, SWFDEC_AS_RELAY (transform_as
));
371 swfdec_as_object_set_constructor_by_name (object
,
372 SWFDEC_AS_STR_flash
, SWFDEC_AS_STR_geom
, SWFDEC_AS_STR_ColorTransform
, NULL
);
374 transform_as
->ra
= transform
->ra
/ 256.0;
375 transform_as
->ga
= transform
->ga
/ 256.0;
376 transform_as
->ba
= transform
->ba
/ 256.0;
377 transform_as
->aa
= transform
->aa
/ 256.0;
378 transform_as
->rb
= transform
->rb
;
379 transform_as
->gb
= transform
->gb
;
380 transform_as
->bb
= transform
->bb
;
381 transform_as
->ab
= transform
->ab
;
387 swfdec_color_transform_get_transform (SwfdecColorTransformAs
*trans
,
388 SwfdecColorTransform
*ctrans
)
390 g_return_if_fail (SWFDEC_IS_COLOR_TRANSFORM_AS (trans
));
391 g_return_if_fail (ctrans
!= NULL
);
393 SWFDEC_FIXME ("This conversion needs serious testing with NaN and overflows");
394 ctrans
->mask
= FALSE
;
395 ctrans
->ra
= trans
->ra
* 256.0;
396 ctrans
->ga
= trans
->ga
* 256.0;
397 ctrans
->ba
= trans
->ba
* 256.0;
398 ctrans
->aa
= trans
->aa
* 256.0;
399 ctrans
->rb
= trans
->rb
;
400 ctrans
->gb
= trans
->gb
;
401 ctrans
->bb
= trans
->bb
;
402 ctrans
->ab
= trans
->ab
;