2 * Copyright (C) 2003-2006 David Schleef <ds@schleef.org>
3 * 2005-2006 Eric Anholt <eric@anholt.net>
4 * 2006-2007 Benjamin Otte <otte@gnome.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
31 #include <glib-object.h>
32 #include <swfdec/swfdec.h>
33 #include <swfdec/swfdec_audio_decoder.h>
34 #include <swfdec/swfdec_button.h>
35 #include <swfdec/swfdec_text_field.h>
36 #include <swfdec/swfdec_font.h>
37 #include <swfdec/swfdec_image.h>
38 #include <swfdec/swfdec_movie.h>
39 #include <swfdec/swfdec_player_internal.h>
40 #include <swfdec/swfdec_sprite.h>
41 #include <swfdec/swfdec_shape.h>
42 #include <swfdec/swfdec_sound.h>
43 #include <swfdec/swfdec_swf_decoder.h>
44 #include <swfdec/swfdec_resource.h>
45 #include <swfdec/swfdec_tag.h>
46 #include <swfdec/swfdec_text.h>
48 static gboolean verbose
= FALSE
;
51 get_audio_format_name (guint codec
)
54 case SWFDEC_AUDIO_CODEC_ADPCM
:
56 case SWFDEC_AUDIO_CODEC_MP3
:
58 case SWFDEC_AUDIO_CODEC_UNCOMPRESSED
:
59 return "uncompressed";
60 case SWFDEC_AUDIO_CODEC_NELLYMOSER
:
68 dump_sound (SwfdecSound
*sound
)
70 g_print (" codec: %s\n", get_audio_format_name (sound
->codec
));
72 g_print (" format: %s\n", swfdec_audio_format_to_string (sound
->format
));
73 g_print (" samples: %u (%gs)\n", sound
->n_samples
,
74 (double) sound
->n_samples
/ swfdec_audio_format_get_rate (sound
->format
));
79 dump_sprite (SwfdecSwfDecoder
*dec
, SwfdecSprite
*s
)
82 g_print (" %u frames\n", s
->n_frames
);
89 if (!swfdec_sprite_get_action (s
, i
, &tag
, &buffer
))
92 case SWFDEC_TAG_DOACTION
:
93 g_print (" %4u script\n", j
);
95 case SWFDEC_TAG_PLACEOBJECT2
:
96 case SWFDEC_TAG_PLACEOBJECT3
:
99 gboolean has_char
, is_move
;
102 swfdec_bits_init (&bits
, buffer
);
103 swfdec_bits_getbits (&bits
, 6);
104 has_char
= swfdec_bits_getbit (&bits
);
105 is_move
= swfdec_bits_getbit (&bits
);
106 if (tag
== SWFDEC_TAG_PLACEOBJECT3
)
107 swfdec_bits_get_u8 (&bits
);
108 depth
= swfdec_bits_get_u16 (&bits
);
109 g_print (" %4u %5u %s", j
, depth
, is_move
? "move" : "place");
112 c
= swfdec_swf_decoder_get_character (dec
, swfdec_bits_get_u16 (&bits
));
114 g_print (" %s %u", G_OBJECT_TYPE_NAME (c
), c
->id
);
119 case SWFDEC_TAG_REMOVEOBJECT
:
120 case SWFDEC_TAG_REMOVEOBJECT2
:
123 swfdec_bits_init (&bits
, buffer
);
124 if (tag
== SWFDEC_TAG_REMOVEOBJECT
)
125 swfdec_bits_get_u16 (&bits
);
126 g_print (" %4u %5u remove\n", j
, swfdec_bits_get_u16 (&bits
));
129 case SWFDEC_TAG_SHOWFRAME
:
132 case SWFDEC_TAG_STARTSOUND
:
133 /* FIXME add info about what sound etc */
134 g_print (" %4u start sound\n", j
);
136 case SWFDEC_TAG_EXPORTASSETS
:
137 g_print (" %4u export\n", j
);
139 case SWFDEC_TAG_DOINITACTION
:
140 g_print (" %4u init action\n", j
);
142 case SWFDEC_TAG_SETBACKGROUNDCOLOR
:
143 g_print (" %4u background color\n", j
);
145 case SWFDEC_TAG_SOUNDSTREAMHEAD
:
147 g_print (" %4u sound stream\n", j
);
149 case SWFDEC_TAG_SOUNDSTREAMHEAD2
:
150 case SWFDEC_TAG_SOUNDSTREAMBLOCK
:
153 g_assert_not_reached ();
160 dump_path (cairo_path_t
*path
)
163 cairo_path_data_t
*data
= path
->data
;
166 for (i
= 0; i
< path
->num_data
; i
++) {
168 switch (data
[i
].header
.type
) {
169 case CAIRO_PATH_CURVE_TO
:
170 g_print (" curve %g %g (%g %g . %g %g)\n",
171 data
[i
+ 3].point
.x
, data
[i
+ 3].point
.y
,
172 data
[i
+ 1].point
.x
, data
[i
+ 1].point
.y
,
173 data
[i
+ 2].point
.x
, data
[i
+ 2].point
.y
);
176 case CAIRO_PATH_LINE_TO
:
178 case CAIRO_PATH_MOVE_TO
:
182 g_print (" %s %g %g\n", name
, data
[i
].point
.x
, data
[i
].point
.y
);
184 case CAIRO_PATH_CLOSE_PATH
:
185 g_print (" close\n");
188 g_assert_not_reached ();
195 dump_shape (SwfdecShape
*shape
)
199 for (walk
= shape
->draws
; walk
; walk
= walk
->next
) {
200 if (SWFDEC_IS_PATTERN (walk
->data
)) {
201 SwfdecPattern
*pattern
= walk
->data
;
202 char *str
= swfdec_pattern_to_string (pattern
);
203 g_print ("%s\n", str
);
206 g_print (" %g %g %g %g %g %g\n",
207 pattern
->start_transform
.xx
, pattern
->start_transform
.xy
,
208 pattern
->start_transform
.yx
, pattern
->start_transform
.yy
,
209 pattern
->start_transform
.x0
, pattern
->start_transform
.y0
);
211 } else if (SWFDEC_IS_STROKE (walk
->data
)) {
212 SwfdecStroke
*line
= walk
->data
;
213 g_print ("line (width %u, color #%08X)\n", line
->start_width
, line
->start_color
);
215 g_print ("not filled\n");
218 dump_path (&SWFDEC_DRAW (walk
->data
)->path
);
224 dump_text_field (SwfdecTextField
*text
)
226 g_print (" %s\n", text
->input
? text
->input
: "");
229 g_print (" variable %s\n", text
->variable
);
231 g_print (" no variable\n");
236 dump_text (SwfdecText
*text
)
239 gunichar2 uni
[text
->glyphs
->len
];
242 for (i
= 0; i
< text
->glyphs
->len
; i
++) {
243 SwfdecTextGlyph
*glyph
= &g_array_index (text
->glyphs
, SwfdecTextGlyph
, i
);
244 uni
[i
] = g_array_index (glyph
->font
->glyphs
, SwfdecFontEntry
, glyph
->glyph
).value
;
248 s
= g_utf16_to_utf8 (uni
, text
->glyphs
->len
, NULL
, NULL
, NULL
);
251 g_print (" text: %s\n", s
);
256 g_print (" %u characters\n", text
->glyphs
->len
);
260 dump_font (SwfdecFont
*font
)
264 g_print (" %s\n", font
->name
);
265 g_print (" %u characters\n", font
->glyphs
->len
);
267 for (i
= 0; i
< font
->glyphs
->len
; i
++) {
268 gunichar2 c
= g_array_index (font
->glyphs
, SwfdecFontEntry
, i
).value
;
270 if (c
== 0 || (s
= g_utf16_to_utf8 (&c
, 1, NULL
, NULL
, NULL
)) == NULL
) {
282 dump_button (SwfdecButton
*button
)
287 get_image_type_name (SwfdecImageType type
)
290 case SWFDEC_IMAGE_TYPE_JPEG
:
291 return "JPEG with global table";
292 case SWFDEC_IMAGE_TYPE_JPEG2
:
294 case SWFDEC_IMAGE_TYPE_JPEG3
:
295 return "JPEG with alpha";
296 case SWFDEC_IMAGE_TYPE_LOSSLESS
:
298 case SWFDEC_IMAGE_TYPE_LOSSLESS2
:
299 return "lossless with alpha";
300 case SWFDEC_IMAGE_TYPE_PNG
:
302 case SWFDEC_IMAGE_TYPE_UNKNOWN
:
304 g_assert_not_reached ();
310 dump_image (SwfdecImage
*image
)
312 cairo_surface_destroy (swfdec_image_create_surface (image
, NULL
));
313 g_print (" %s %u x %u\n", get_image_type_name (image
->type
),
314 image
->width
, image
->height
);
318 dump_object (gpointer value
, gpointer dec
)
320 SwfdecCharacter
*c
= value
;
322 g_print ("%d: %s\n", c
->id
, G_OBJECT_TYPE_NAME (c
));
323 if (verbose
&& SWFDEC_IS_GRAPHIC (c
)) {
324 SwfdecGraphic
*graphic
= SWFDEC_GRAPHIC (c
);
325 g_print (" extents: %g %g %g %g\n", graphic
->extents
.x0
, graphic
->extents
.y0
,
326 graphic
->extents
.x1
, graphic
->extents
.y1
);
328 if (SWFDEC_IS_IMAGE (c
)) {
329 dump_image (SWFDEC_IMAGE (c
));
331 if (SWFDEC_IS_SPRITE (c
)) {
332 dump_sprite (dec
, SWFDEC_SPRITE (c
));
334 if (SWFDEC_IS_SHAPE(c
)) {
335 dump_shape(SWFDEC_SHAPE(c
));
337 if (SWFDEC_IS_TEXT (c
)) {
338 dump_text (SWFDEC_TEXT (c
));
340 if (SWFDEC_IS_TEXT_FIELD (c
)) {
341 dump_text_field (SWFDEC_TEXT_FIELD (c
));
343 if (SWFDEC_IS_FONT (c
)) {
344 dump_font (SWFDEC_FONT (c
));
346 if (SWFDEC_IS_BUTTON (c
)) {
347 dump_button (SWFDEC_BUTTON (c
));
349 if (SWFDEC_IS_SOUND (c
)) {
350 dump_sound (SWFDEC_SOUND (c
));
355 enqueue (gpointer key
, gpointer value
, gpointer listp
)
357 GList
**list
= listp
;
359 *list
= g_list_prepend (*list
, value
);
363 sort_by_id (gconstpointer a
, gconstpointer b
)
365 if (SWFDEC_CHARACTER (a
)->id
< SWFDEC_CHARACTER (b
)->id
)
371 main (int argc
, char *argv
[])
374 SwfdecPlayer
*player
;
375 GError
*error
= NULL
;
376 GOptionEntry options
[] = {
377 { "verbose", 'v', 0, G_OPTION_ARG_NONE
, &verbose
, "bew verbose", NULL
},
384 ctx
= g_option_context_new ("");
385 g_option_context_add_main_entries (ctx
, options
, "options");
386 g_option_context_parse (ctx
, &argc
, &argv
, &error
);
387 g_option_context_free (ctx
);
389 g_printerr ("Error parsing command line arguments: %s\n", error
->message
);
390 g_error_free (error
);
397 g_print ("usage: %s [OPTIONS] file\n", argv
[0]);
401 player
= swfdec_player_new (NULL
);
402 url
= swfdec_url_new_from_input (argv
[1]);
403 swfdec_player_set_url (player
, url
);
404 swfdec_url_free (url
);
406 swfdec_player_advance (player
, 0);
407 if (!swfdec_player_is_initialized (player
)) {
408 g_printerr ("File \"%s\" is not a SWF file\n", argv
[1]);
409 g_object_unref (player
);
413 s
= (SwfdecSwfDecoder
*) SWFDEC_MOVIE (player
->priv
->roots
->data
)->resource
->decoder
;
414 /* FIXME: can happen after a _root.loadMovie() call */
415 if (!SWFDEC_IS_SWF_DECODER (s
)) {
416 g_printerr ("Movie already unloaded from \"%s\"\n", argv
[1]);
417 g_object_unref (player
);
423 g_print (" version: %d\n", s
->version
);
424 g_print (" rate : %g fps\n", SWFDEC_DECODER (s
)->rate
/ 256.0);
425 g_print (" size : %ux%u pixels\n", SWFDEC_DECODER (s
)->width
, SWFDEC_DECODER (s
)->height
);
426 g_print ("objects:\n");
427 g_hash_table_foreach (s
->characters
, enqueue
, &list
);
428 list
= g_list_sort (list
, sort_by_id
);
429 g_list_foreach (list
, dump_object
, s
);
432 g_print ("main sprite:\n");
433 dump_sprite (s
, s
->main_sprite
);
434 g_object_unref (player
);