add blend mode tests
[swfdec.git] / swfdec / swfdec_utils.c
blob9ce47bbb3772af0354c086deb95ce78ef8805a20
1 /* Swfdec
2 * Copyright (C) 2007-2008 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.
8 *
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
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_utils.h"
26 #include <math.h>
27 #include <string.h>
29 #include "swfdec_as_internal.h"
30 #include "swfdec_as_object.h"
31 #include "swfdec_as_strings.h"
33 gboolean
34 swfdec_str_case_equal (gconstpointer v1, gconstpointer v2)
36 const char *s1 = v1;
37 const char *s2 = v2;
39 return g_ascii_strcasecmp (s1, s2) == 0;
42 guint
43 swfdec_str_case_hash (gconstpointer v)
45 const signed char *p;
46 guint32 h = 0;
48 for (p = v; *p != '\0'; p++)
49 h = (h << 5) - h + (*p & 0xDF);
51 return h;
54 int
55 swfdec_strcmp (guint version, const char *s1, const char *s2)
57 g_return_val_if_fail (s1 != NULL, 0);
58 g_return_val_if_fail (s2 != NULL, 0);
60 if (version < 7) {
61 return g_ascii_strcasecmp (s1, s2);
62 } else {
63 return strcmp (s1, s2);
67 int
68 swfdec_strncmp (guint version, const char *s1, const char *s2, guint n)
70 g_return_val_if_fail (s1 != NULL, 0);
71 g_return_val_if_fail (s2 != NULL, 0);
73 if (version < 7) {
74 return g_ascii_strncasecmp (s1, s2, n);
75 } else {
76 return strncmp (s1, s2, n);
80 gboolean
81 swfdec_matrix_from_as_object (cairo_matrix_t *matrix, SwfdecAsObject *object)
83 SwfdecAsValue *val;
84 SwfdecAsContext *cx = object->context;
86 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_a);
87 if (val == NULL ||
88 !isfinite (matrix->xx = swfdec_as_value_to_number (cx, *val)))
89 return FALSE;
90 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_b);
91 if (val == NULL ||
92 !isfinite (matrix->yx = swfdec_as_value_to_number (cx, *val)))
93 return FALSE;
94 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_c);
95 if (val == NULL ||
96 !isfinite (matrix->xy = swfdec_as_value_to_number (cx, *val)))
97 return FALSE;
98 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_d);
99 if (val == NULL ||
100 !isfinite (matrix->yy = swfdec_as_value_to_number (cx, *val)))
101 return FALSE;
103 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_tx);
104 if (val == NULL)
105 return FALSE;
106 matrix->x0 = swfdec_as_value_to_number (cx, *val);
107 if (!isfinite (matrix->x0))
108 matrix->x0 = 0;
109 val = swfdec_as_object_peek_variable (object, SWFDEC_AS_STR_ty);
110 if (val == NULL)
111 return FALSE;
112 matrix->y0 = swfdec_as_value_to_number (cx, *val);
113 if (!isfinite (matrix->y0))
114 matrix->y0 = 0;
116 return TRUE;