copy/paste caused some issues here
[swfdec.git] / libswfdec / swfdec_filter.c
blob3a1e7bd4055a3b343c61c092feea8743345ff1cf
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
3 * 2007 Pekka Lampila <pekka.lampila@iki.fi>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include "swfdec_filter.h"
26 #include "swfdec_debug.h"
28 G_DEFINE_ABSTRACT_TYPE (SwfdecFilter, swfdec_filter, SWFDEC_TYPE_AS_OBJECT)
30 static void
31 swfdec_filter_class_init (SwfdecFilterClass *klass)
35 static void
36 swfdec_filter_init (SwfdecFilter *array)
40 cairo_pattern_t *
41 swfdec_filter_apply (SwfdecFilter *filter, cairo_pattern_t *pattern)
43 SwfdecFilterClass *klass;
44 cairo_pattern_t *ret;
46 g_return_val_if_fail (SWFDEC_IS_FILTER (filter), NULL);
47 g_return_val_if_fail (pattern != NULL, NULL);
49 klass = SWFDEC_FILTER_GET_CLASS (filter);
50 g_assert (klass->apply);
52 ret = klass->apply (filter, pattern);
53 cairo_pattern_destroy (pattern);
54 return ret;
57 GSList *
58 swfdec_filter_parse (SwfdecPlayer *player, SwfdecBits *bits)
60 GSList *filters = NULL;
61 guint i, n_filters, filter_id;
63 g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);
64 g_return_val_if_fail (bits != NULL, NULL);
66 n_filters = swfdec_bits_get_u8 (bits);
67 SWFDEC_LOG (" filters: %u", n_filters);
68 for (i = 0; i < n_filters && swfdec_bits_left (bits); i++) {
69 filter_id = swfdec_bits_get_u8 (bits);
70 switch (filter_id) {
71 case 0:
72 SWFDEC_WARNING (" drop shadow");
73 swfdec_bits_skip_bytes (bits, 16);
74 break;
75 case 1:
76 SWFDEC_WARNING (" blur");
77 swfdec_bits_skip_bytes (bits, 9);
78 break;
79 case 2:
80 SWFDEC_WARNING (" glow");
81 swfdec_bits_skip_bytes (bits, 15);
82 break;
83 case 3:
84 SWFDEC_WARNING (" bevel");
85 swfdec_bits_skip_bytes (bits, 27);
86 break;
87 case 4:
89 guint n;
90 n = swfdec_bits_get_u8 (bits);
91 SWFDEC_WARNING (" gradient glow");
92 swfdec_bits_skip_bytes (bits, n * 5 + 19);
94 break;
95 case 5:
97 guint x, y;
98 x = swfdec_bits_get_u8 (bits);
99 y = swfdec_bits_get_u8 (bits);
100 SWFDEC_WARNING (" %u x %u convolution", x, y);
101 swfdec_bits_skip_bytes (bits, (x + y) * 4 + 13);
103 break;
104 case 6:
105 SWFDEC_WARNING (" color matrix");
106 swfdec_bits_skip_bytes (bits, 20 * 4);
107 break;
108 case 7:
110 guint n;
111 n = swfdec_bits_get_u8 (bits);
112 SWFDEC_WARNING (" gradient bevel");
113 swfdec_bits_skip_bytes (bits, n * 5 + 19);
115 break;
116 default:
117 SWFDEC_ERROR ("unknown filter id %u", filter_id);
118 break;
122 filters = g_slist_reverse (filters);
123 return filters;