[Swfdec] 2 commits - doc/swfdec-sections.txt libswfdec/swfdec_color.h libswfdec/swfdec_player.c libswfdec/swfdec_player.h libswfdec/swfdec_player_internal.h libswfdec/swfdec_sprite.c libswfdec/swfdec_sprite.h libswfdec/swfdec_sprite_movie.c libswfdec/swfdec_sprite_movie.h libswfdec/swfdec_types.h

Benjamin Otte company at kemper.freedesktop.org
Sat Feb 17 06:56:13 PST 2007


 doc/swfdec-sections.txt            |    2 +
 libswfdec/swfdec_color.h           |    4 --
 libswfdec/swfdec_player.c          |   65 ++++++++++++++++++++++++++++++-------
 libswfdec/swfdec_player.h          |    7 +++
 libswfdec/swfdec_player_internal.h |    4 +-
 libswfdec/swfdec_sprite.c          |   24 +++++++++----
 libswfdec/swfdec_sprite.h          |    1 
 libswfdec/swfdec_sprite_movie.c    |   19 ----------
 libswfdec/swfdec_sprite_movie.h    |    3 -
 libswfdec/swfdec_types.h           |    4 ++
 10 files changed, 86 insertions(+), 47 deletions(-)

New commits:
diff-tree 20b8eddca6677d1c69f541d058fce59031487450 (from 8162df646cb4ebb7009c48093a026f827a9c34fe)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 14:47:40 2007 +0100

    rework background color handling
    
    - There's only one background color per player, not one per frame per sprite
    - The background color is exported by the SwfdecPlayer, so it can be overwritten

diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index 43457d5..4a45ff4 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -45,6 +45,8 @@ swfdec_player_is_initialized
 swfdec_player_get_rate
 swfdec_player_get_image_size
 swfdec_player_get_next_event
+swfdec_player_get_background_color
+swfdec_player_set_background_color
 swfdec_player_render
 swfdec_player_advance
 swfdec_player_handle_mouse
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 2255771..a1b9660 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1,5 +1,5 @@
 /* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
+ * Copyright (C) 2006-2007 Benjamin Otte <otte at gnome.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -266,7 +266,8 @@ enum {
   PROP_CACHE_SIZE,
   PROP_INITIALIZED,
   PROP_MOUSE_CURSOR,
-  PROP_NEXT_EVENT
+  PROP_NEXT_EVENT,
+  PROP_BACKGROUND_COLOR
 };
 
 G_DEFINE_TYPE (SwfdecPlayer, swfdec_player, G_TYPE_OBJECT)
@@ -285,6 +286,9 @@ swfdec_player_get_property (GObject *obj
   SwfdecPlayer *player = SWFDEC_PLAYER (object);
   
   switch (param_id) {
+    case PROP_BACKGROUND_COLOR:
+      g_value_set_uint (value, swfdec_player_get_background_color (player));
+      break;
     case PROP_CACHE_SIZE:
       g_value_set_uint (value, player->cache->max_size);
       break;
@@ -310,6 +314,9 @@ swfdec_player_set_property (GObject *obj
   SwfdecPlayer *player = SWFDEC_PLAYER (object);
 
   switch (param_id) {
+    case PROP_BACKGROUND_COLOR:
+      swfdec_player_set_background_color (player, g_value_get_uint (value));
+      break;
     case PROP_CACHE_SIZE:
       player->cache->max_size = g_value_get_uint (value);
       break;
@@ -713,7 +720,9 @@ swfdec_player_class_init (SwfdecPlayerCl
   g_object_class_install_property (object_class, PROP_CACHE_SIZE,
       g_param_spec_uint ("cache-size", "cache size", "maximum cache size in bytes",
 	  0, G_MAXUINT, 50 * 1024 * 1024, G_PARAM_READABLE));
-
+  g_object_class_install_property (object_class, PROP_BACKGROUND_COLOR,
+      g_param_spec_uint ("background-color", "background color", "ARGB color used to draw the background",
+	  0, G_MAXUINT, SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF), G_PARAM_READWRITE));
 
   /**
    * SwfdecPlayer::trace:
@@ -820,6 +829,7 @@ swfdec_player_init (SwfdecPlayer *player
 
   player->actions = swfdec_ring_buffer_new_for_type (SwfdecPlayerAction, 16);
   player->cache = swfdec_cache_new (50 * 1024 * 1024); /* 100 MB */
+  player->bgcolor = SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF);
 
   player->mouse_visible = TRUE;
   player->mouse_cursor = SWFDEC_MOUSE_CURSOR_NORMAL;
@@ -1154,14 +1164,8 @@ swfdec_player_render (SwfdecPlayer *play
   cairo_rectangle (cr, x, y, width, height);
   cairo_clip (cr);
   cairo_scale (cr, 1.0 / SWFDEC_TWIPS_SCALE_FACTOR, 1.0 / SWFDEC_TWIPS_SCALE_FACTOR);
-  /* FIXME: find a nicer way to render the background */
-  if (player->roots == NULL ||
-      !SWFDEC_IS_SPRITE_MOVIE (player->roots->data) ||
-      !swfdec_sprite_movie_paint_background (SWFDEC_SPRITE_MOVIE (player->roots->data), cr)) {
-    SWFDEC_INFO ("couldn't paint the background, using white");
-    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
-    cairo_paint (cr);
-  }
+  swfdec_color_set_source (cr, player->bgcolor);
+  cairo_paint (cr);
 
   for (walk = player->roots; walk; walk = walk->next) {
     swfdec_movie_render (walk->data, cr, &trans, &real, TRUE);
@@ -1299,3 +1303,42 @@ swfdec_player_get_audio (SwfdecPlayer *	
   return player->audio;
 }
 
+/**
+ * swfdec_player_get_background_color:
+ * @player: a #SwfdecPlayer
+ *
+ * Gets the current background color. The color will be an ARGB-quad, with the 
+ * MSB being the alpha value.
+ *
+ * Returns: the background color as an ARGB value
+ **/
+unsigned int
+swfdec_player_get_background_color (SwfdecPlayer *player)
+{
+  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF));
+
+  return player->bgcolor;
+}
+
+/**
+ * swfdec_player_set_background_color:
+ * @player: a #SwfdecPlayer
+ * @color: new color to use as background color
+ *
+ * Sets a new background color as an ARGB value. To get transparency, set the 
+ * value to 0. To get a black beackground, use 0xFF000000.
+ **/
+void
+swfdec_player_set_background_color (SwfdecPlayer *player, unsigned int color)
+{
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  player->bgcolor_set = TRUE;
+  if (player->bgcolor == color)
+    return;
+  g_object_notify (G_OBJECT (player), "background-color");
+  if (swfdec_player_is_initialized (player)) {
+    g_signal_emit (player, signals[INVALIDATE], 0, 0.0, 0.0, 
+	(double) player->width, (double) player->height);
+  }
+}
diff --git a/libswfdec/swfdec_player.h b/libswfdec/swfdec_player.h
index 437d3ee..0c6f70c 100644
--- a/libswfdec/swfdec_player.h
+++ b/libswfdec/swfdec_player.h
@@ -1,5 +1,5 @@
 /* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
+ * Copyright (C) 2006-2007 Benjamin Otte <otte at gnome.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -63,6 +63,11 @@ double		swfdec_player_get_rate		(SwfdecP
 void		swfdec_player_get_image_size	(SwfdecPlayer *	player,
 						 int *		width,
 						 int *		height);
+unsigned int	swfdec_player_get_background_color 
+						(SwfdecPlayer *	player);
+void		swfdec_player_set_background_color 
+						(SwfdecPlayer *	player,
+						 unsigned int	color);
 					 
 void		swfdec_player_render		(SwfdecPlayer *	player,
 						 cairo_t *	cr,
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index 2d2c6f9..be548b4 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -1,5 +1,5 @@
 /* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
+ * Copyright (C) 2006-2007 Benjamin Otte <otte at gnome.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -46,6 +46,8 @@ struct _SwfdecPlayer
   unsigned int		height;			/* height of movie */
   GList *		roots;			/* all the root movies */
   SwfdecCache *		cache;			/* player cache */
+  gboolean		bgcolor_set;		/* TRUE if the background color has been set */
+  SwfdecColor		bgcolor;		/* background color */
 
   /* javascript */
   JSContext *		jscx;			/* global Javascript context */
diff --git a/libswfdec/swfdec_sprite.c b/libswfdec/swfdec_sprite.c
index 0a50906..4145c72 100644
--- a/libswfdec/swfdec_sprite.c
+++ b/libswfdec/swfdec_sprite.c
@@ -229,7 +229,6 @@ tag_show_frame (SwfdecSwfDecoder * s)
   if (s->parse_sprite->parse_frame < s->parse_sprite->n_frames) {
     SwfdecSpriteFrame *old = &s->parse_sprite->frames[s->parse_sprite->parse_frame - 1];
     SwfdecSpriteFrame *new = &s->parse_sprite->frames[s->parse_sprite->parse_frame];
-    new->bg_color = old->bg_color;
     if (old->sound_head)
       new->sound_head = g_object_ref (old->sound_head);
   }
@@ -240,11 +239,24 @@ tag_show_frame (SwfdecSwfDecoder * s)
 int
 tag_func_set_background_color (SwfdecSwfDecoder * s)
 {
-  SwfdecSpriteFrame *frame;
+  SwfdecPlayer *player = SWFDEC_DECODER (s)->player;
+  SwfdecColor color = swfdec_bits_get_color (&s->b);
 
-  frame = &s->parse_sprite->frames[s->parse_sprite->parse_frame];
-
-  frame->bg_color = swfdec_bits_get_color (&s->b);
+  if (player->bgcolor_set) {
+    /* only an INFO because it can be set by user, should be error if we check duplication of tag */
+    SWFDEC_INFO ("background color has been set to %X already, setting to %X ignored",
+	player->bgcolor, color);
+  } else {
+    SWFDEC_LOG ("setting background color to %X", color);
+    /* can't use swfdec_player_set_background_color() here, because the player is locked and doesn't emit signals */
+    player->bgcolor = color;
+    player->bgcolor_set = TRUE;
+    player->invalid.x0 = SWFDEC_DOUBLE_TO_TWIPS (0.0);
+    player->invalid.y0 = SWFDEC_DOUBLE_TO_TWIPS (0.0);
+    player->invalid.x1 = SWFDEC_DOUBLE_TO_TWIPS (player->width);
+    player->invalid.y1 = SWFDEC_DOUBLE_TO_TWIPS (player->height);
+    g_object_notify (G_OBJECT (player), "background-color");
+  }
 
   return SWFDEC_STATUS_OK;
 }
@@ -507,8 +519,6 @@ swfdec_sprite_set_n_frames (SwfdecSprite
   for (i = 0; i < n_frames; i++) {
     sprite->frames[i].sound_samples = 44100 * 256 / rate;
   }
-  /* default bg is white */
-  sprite->frames[0].bg_color = SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF);
 
   SWFDEC_LOG ("n_frames = %d", sprite->n_frames);
 }
diff --git a/libswfdec/swfdec_sprite.h b/libswfdec/swfdec_sprite.h
index 1968d1a..5ac0bf8 100644
--- a/libswfdec/swfdec_sprite.h
+++ b/libswfdec/swfdec_sprite.h
@@ -63,7 +63,6 @@ struct _SwfdecSpriteFrame
   GSList *sound;			/* list of SwfdecSoundChunk events to start playing here */
 
   /* visuals */
-  SwfdecColor bg_color;
   GArray *actions;			/* SwfdecSpriteAction in execution order */
 };
 
diff --git a/libswfdec/swfdec_sprite_movie.c b/libswfdec/swfdec_sprite_movie.c
index 36cbd8f..1cc2f0b 100644
--- a/libswfdec/swfdec_sprite_movie.c
+++ b/libswfdec/swfdec_sprite_movie.c
@@ -142,11 +142,6 @@ swfdec_sprite_movie_do_goto_frame (Swfde
     start = movie->current_frame + 1;
     old = NULL;
   }
-  if (movie->current_frame == (guint) -1 || 
-      movie->sprite->frames[goto_frame].bg_color != 
-      movie->sprite->frames[movie->current_frame].bg_color) {
-    swfdec_movie_invalidate (mov);
-  }
   movie->current_frame = goto_frame;
   SWFDEC_DEBUG ("performing goto %u -> %u for character %u", 
       start, goto_frame, SWFDEC_CHARACTER (movie->sprite)->id);
@@ -355,17 +350,3 @@ swfdec_sprite_movie_init (SwfdecSpriteMo
   movie->sound_frame = (guint) -1;
 }
 
-gboolean
-swfdec_sprite_movie_paint_background (SwfdecSpriteMovie *movie, cairo_t *cr)
-{
-  SwfdecSpriteFrame *frame;
-  
-  if (movie->current_frame >= SWFDEC_MOVIE (movie)->n_frames)
-    return FALSE;
-
-  frame = &movie->sprite->frames[movie->current_frame];
-  swfdec_color_set_source (cr, frame->bg_color);
-  cairo_paint (cr);
-  return TRUE;
-}
-
diff --git a/libswfdec/swfdec_sprite_movie.h b/libswfdec/swfdec_sprite_movie.h
index bdc6802..79a0db1 100644
--- a/libswfdec/swfdec_sprite_movie.h
+++ b/libswfdec/swfdec_sprite_movie.h
@@ -60,9 +60,6 @@ struct _SwfdecSpriteMovieClass
 
 GType		swfdec_sprite_movie_get_type		(void);
 
-gboolean	swfdec_sprite_movie_paint_background	(SwfdecSpriteMovie *    movie,
-							 cairo_t *		cr);
-
 
 G_END_DECLS
 #endif
diff-tree 8162df646cb4ebb7009c48093a026f827a9c34fe (from 86ceb1bdea1ecee5bff104a29c07351bf78454c1)
Author: Benjamin Otte <otte at gnome.org>
Date:   Sat Feb 17 14:30:35 2007 +0100

    move SwfdecColor definition to swfdec_types.h

diff --git a/libswfdec/swfdec_color.h b/libswfdec/swfdec_color.h
index a7a7723..878ec66 100644
--- a/libswfdec/swfdec_color.h
+++ b/libswfdec/swfdec_color.h
@@ -24,10 +24,6 @@
 
 #include <libswfdec/swfdec_types.h>
 
-/* Pixel value in the same colorspace as cairo - endian-dependant ARGB.
- * The alpha pixel must be present */
-typedef unsigned int SwfdecColor;
-
 struct _SwfdecColorTransform {
   /* naming here is taken from ActionScript, where ?a is the multiplier and ?b the offset */
   int ra, rb, ga, gb, ba, bb, aa, ab;
diff --git a/libswfdec/swfdec_types.h b/libswfdec/swfdec_types.h
index 3228a36..f03b60f 100644
--- a/libswfdec/swfdec_types.h
+++ b/libswfdec/swfdec_types.h
@@ -5,6 +5,10 @@
 #include <glib-object.h>
 #include <cairo.h>
 
+/* Pixel value in the same colorspace as cairo - endian-dependant ARGB.
+ * The alpha pixel must be present */
+typedef unsigned int SwfdecColor;
+
 /* audio is 44100Hz, framerate is multiple of 256Hz, FLV timestamps are 1000Hz
  * This is a multiple of all these numbers, so we can be always accurate
  */


More information about the Swfdec mailing list