[Swfdec-commits] 16 commits - swfdec/Makefile.am swfdec/swfdec_bitmap_data.c swfdec/swfdec_bitmap_movie.c swfdec/swfdec_bitmap_movie.h swfdec/swfdec_bots.c swfdec/swfdec_color.c swfdec/swfdec_color.h swfdec/swfdec_gradient_pattern.c swfdec/swfdec_image.c swfdec/swfdec_movie.c swfdec/swfdec_movie.h swfdec/swfdec_pattern.c swfdec/swfdec_sprite_movie_as.c swfdec/swfdec_text_field_movie_as.c swfdec/swfdec_text_layout.c test/image test/trace
Benjamin Otte
company at kemper.freedesktop.org
Fri Jul 25 10:02:53 PDT 2008
swfdec/Makefile.am | 2
swfdec/swfdec_bitmap_data.c | 129 ++++++++++++++++++++++--
swfdec/swfdec_bitmap_movie.c | 162 +++++++++++++++++++++++++++++++
swfdec/swfdec_bitmap_movie.h | 57 ++++++++++
swfdec/swfdec_bots.c | 14 +-
swfdec/swfdec_color.c | 36 +++---
swfdec/swfdec_color.h | 8 -
swfdec/swfdec_gradient_pattern.c | 4
swfdec/swfdec_image.c | 2
swfdec/swfdec_movie.c | 20 +++
swfdec/swfdec_movie.h | 1
swfdec/swfdec_pattern.c | 4
swfdec/swfdec_sprite_movie_as.c | 32 +++++-
swfdec/swfdec_text_field_movie_as.c | 12 +-
swfdec/swfdec_text_layout.c | 20 +--
test/image/BitmapData-creation-5.swf |binary
test/image/BitmapData-creation-5.swf.png |binary
test/image/BitmapData-creation-6.swf |binary
test/image/BitmapData-creation-6.swf.png |binary
test/image/BitmapData-creation-7.swf |binary
test/image/BitmapData-creation-7.swf.png |binary
test/image/BitmapData-creation-8.swf |binary
test/image/BitmapData-creation-8.swf.png |binary
test/image/BitmapData-creation.as | 33 ++++++
test/image/Makefile.am | 18 +++
test/image/setPixel-5.swf |binary
test/image/setPixel-5.swf.png |binary
test/image/setPixel-6.swf |binary
test/image/setPixel-6.swf.png |binary
test/image/setPixel-7.swf |binary
test/image/setPixel-7.swf.png |binary
test/image/setPixel-8.swf |binary
test/image/setPixel-8.swf.png |binary
test/image/setPixel.as | 17 +++
test/trace/Makefile.am | 9 +
test/trace/attachBitmap-5.swf |binary
test/trace/attachBitmap-5.swf.trace | 5
test/trace/attachBitmap-6.swf |binary
test/trace/attachBitmap-6.swf.trace | 5
test/trace/attachBitmap-7.swf |binary
test/trace/attachBitmap-7.swf.trace | 5
test/trace/attachBitmap-8.swf |binary
test/trace/attachBitmap-8.swf.trace | 5
test/trace/attachBitmap.as | 14 ++
44 files changed, 547 insertions(+), 67 deletions(-)
New commits:
commit 8dd4fe9de8f96e2b363c8908457b67a0a0bba350
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Jul 25 17:51:10 2008 +0200
implement BitmapData.getPixel and BitmapData.getPixel32
They still round wrong though. Feel free to RE the algorithm.
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index b66e353..52bafd1 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -219,22 +219,42 @@ swfdec_bitmap_data_set_transparent (SwfdecAsContext *cx,
}
#define SWFDEC_COLOR_MULTIPLY(color) SWFDEC_COLOR_COMBINE ( \
- SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_RED (color) / 255, \
- SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_GREEN (color) / 255, \
- SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_BLUE (color) / 255, \
- SWFDEC_COLOR_ALPHA (color))
-#define SWFDEC_COLOR_UNMULTIPLY(color) SWFDEC_COLOR_COMBINE ( \
- SWFDEC_COLOR_RED (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
- SWFDEC_COLOR_GREEN (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
- SWFDEC_COLOR_BLUE (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
+ (SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_RED (color) + 128) / 255, \
+ (SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_GREEN (color) + 128) / 255, \
+ (SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_BLUE (color) + 128) / 255, \
SWFDEC_COLOR_ALPHA (color))
+/* FIXME: This algorithm rounds wrong, no idea how though */
+#define SWFDEC_COLOR_UNMULTIPLY(color) (SWFDEC_COLOR_ALPHA (color) ? (\
+ SWFDEC_COLOR_ALPHA (color) == 0xFF ? color : SWFDEC_COLOR_COMBINE ( \
+ (SWFDEC_COLOR_RED (color) * 255 + SWFDEC_COLOR_ALPHA (color) / 2) / SWFDEC_COLOR_ALPHA (color), \
+ (SWFDEC_COLOR_GREEN (color) * 255 + SWFDEC_COLOR_ALPHA (color) / 2) / SWFDEC_COLOR_ALPHA (color), \
+ (SWFDEC_COLOR_BLUE (color) * 255 + SWFDEC_COLOR_ALPHA (color) / 2) / SWFDEC_COLOR_ALPHA (color), \
+ SWFDEC_COLOR_ALPHA (color))) : 0)
+
SWFDEC_AS_NATIVE (1100, 1, swfdec_bitmap_data_getPixel)
void
swfdec_bitmap_data_getPixel (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SWFDEC_STUB ("BitmapData.getPixel");
+ SwfdecBitmapData *bitmap;
+ guint x, y, color;
+ guint8 *addr;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "ii", &x, &y);
+
+ if (bitmap->surface == NULL ||
+ x >= (guint) cairo_image_surface_get_width (bitmap->surface) ||
+ y >= (guint) cairo_image_surface_get_height (bitmap->surface))
+ return;
+
+ addr = cairo_image_surface_get_data (bitmap->surface);
+ addr += cairo_image_surface_get_stride (bitmap->surface) * y;
+ addr += 4 * x;
+ color = *(SwfdecColor *) addr;
+ color = SWFDEC_COLOR_UNMULTIPLY (color);
+ color &= SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0);
+ SWFDEC_AS_VALUE_SET_INT (ret, color);
}
SWFDEC_AS_NATIVE (1100, 2, swfdec_bitmap_data_setPixel)
@@ -326,7 +346,23 @@ void
swfdec_bitmap_data_getPixel32 (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SWFDEC_STUB ("BitmapData.getPixel32");
+ SwfdecBitmapData *bitmap;
+ guint x, y, color;
+ guint8 *addr;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "ii", &x, &y);
+
+ if (bitmap->surface == NULL ||
+ x >= (guint) cairo_image_surface_get_width (bitmap->surface) ||
+ y >= (guint) cairo_image_surface_get_height (bitmap->surface))
+ return;
+
+ addr = cairo_image_surface_get_data (bitmap->surface);
+ addr += cairo_image_surface_get_stride (bitmap->surface) * y;
+ addr += 4 * x;
+ color = *(SwfdecColor *) addr;
+ color = SWFDEC_COLOR_UNMULTIPLY (color);
+ SWFDEC_AS_VALUE_SET_INT (ret, color);
}
SWFDEC_AS_NATIVE (1100, 11, swfdec_bitmap_data_setPixel32)
commit 5c816430d1f3726145b6142d49aa3e1df25e74ec
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Jul 25 13:55:12 2008 +0200
add a testcase for BitmapData.setPixel(32)
it also looks nice!
diff --git a/test/image/Makefile.am b/test/image/Makefile.am
index 8ba0ce9..2ff7e97 100644
--- a/test/image/Makefile.am
+++ b/test/image/Makefile.am
@@ -405,6 +405,15 @@ EXTRA_DIST = \
setMask-matrices-8.swf \
setMask-matrices-8.swf.png \
setMask-matrices.as \
+ setPixel-5.swf \
+ setPixel-5.swf.png \
+ setPixel-6.swf \
+ setPixel-6.swf.png \
+ setPixel-7.swf \
+ setPixel-7.swf.png \
+ setPixel-8.swf \
+ setPixel-8.swf.png \
+ setPixel.as \
swfdec.jpg \
text-field-align-5.swf \
text-field-align-5.swf.png \
diff --git a/test/image/setPixel-5.swf b/test/image/setPixel-5.swf
new file mode 100644
index 0000000..15775f6
Binary files /dev/null and b/test/image/setPixel-5.swf differ
diff --git a/test/image/setPixel-5.swf.png b/test/image/setPixel-5.swf.png
new file mode 100644
index 0000000..4343922
Binary files /dev/null and b/test/image/setPixel-5.swf.png differ
diff --git a/test/image/setPixel-6.swf b/test/image/setPixel-6.swf
new file mode 100644
index 0000000..8203f16
Binary files /dev/null and b/test/image/setPixel-6.swf differ
diff --git a/test/image/setPixel-6.swf.png b/test/image/setPixel-6.swf.png
new file mode 100644
index 0000000..7a38d80
Binary files /dev/null and b/test/image/setPixel-6.swf.png differ
diff --git a/test/image/setPixel-7.swf b/test/image/setPixel-7.swf
new file mode 100644
index 0000000..80dcb98
Binary files /dev/null and b/test/image/setPixel-7.swf differ
diff --git a/test/image/setPixel-7.swf.png b/test/image/setPixel-7.swf.png
new file mode 100644
index 0000000..d95a5a2
Binary files /dev/null and b/test/image/setPixel-7.swf.png differ
diff --git a/test/image/setPixel-8.swf b/test/image/setPixel-8.swf
new file mode 100644
index 0000000..5f9e56a
Binary files /dev/null and b/test/image/setPixel-8.swf differ
diff --git a/test/image/setPixel-8.swf.png b/test/image/setPixel-8.swf.png
new file mode 100644
index 0000000..0b3aedf
Binary files /dev/null and b/test/image/setPixel-8.swf.png differ
diff --git a/test/image/setPixel.as b/test/image/setPixel.as
new file mode 100644
index 0000000..3075a3c
--- /dev/null
+++ b/test/image/setPixel.as
@@ -0,0 +1,17 @@
+// makeswf -v 7 -s 200x150 -r 1 -o setPixel.swf setPixel.as
+
+bg = new flash.display.BitmapData (200, 150, true, 0x80808080);
+for (x = 0; x < bg.width; x++) {
+ for (y = 0; y < bg.height; y++) {
+ bg.setPixel (x, y, 255 - int (256 * x / bg.width));
+ }
+}
+this.attachBitmap (bg, 0);
+
+fg = new flash.display.BitmapData (_width, _height, true, 0);
+for (x = 0; x < fg.width; x++) {
+ for (y = 0; y < fg.height; y++) {
+ fg.setPixel32 (x, y, 0x1010000 * int (256 * y / fg.height) | 0x100 * int (256 * x / fg.width));
+ }
+}
+this.attachBitmap (fg, 1);
commit 5e7ab2637e8da8e655989ebae1c6875c72293289
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Jul 25 13:53:44 2008 +0200
make setPixel(32) set the data directly
This ensures conformance with what Adobe's player does
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index f9a6627..b66e353 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -218,7 +218,17 @@ swfdec_bitmap_data_set_transparent (SwfdecAsContext *cx,
SWFDEC_STUB ("BitmapData.transparent (set)");
}
-// normal
+#define SWFDEC_COLOR_MULTIPLY(color) SWFDEC_COLOR_COMBINE ( \
+ SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_RED (color) / 255, \
+ SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_GREEN (color) / 255, \
+ SWFDEC_COLOR_ALPHA (color) * SWFDEC_COLOR_BLUE (color) / 255, \
+ SWFDEC_COLOR_ALPHA (color))
+#define SWFDEC_COLOR_UNMULTIPLY(color) SWFDEC_COLOR_COMBINE ( \
+ SWFDEC_COLOR_RED (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
+ SWFDEC_COLOR_GREEN (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
+ SWFDEC_COLOR_BLUE (color) * 255 / SWFDEC_COLOR_ALPHA (color), \
+ SWFDEC_COLOR_ALPHA (color))
+
SWFDEC_AS_NATIVE (1100, 1, swfdec_bitmap_data_getPixel)
void
swfdec_bitmap_data_getPixel (SwfdecAsContext *cx, SwfdecAsObject *object,
@@ -234,7 +244,8 @@ swfdec_bitmap_data_setPixel (SwfdecAsContext *cx, SwfdecAsObject *object,
{
SwfdecBitmapData *bitmap;
guint x, y, color;
- cairo_t *cr;
+ SwfdecColor old;
+ guint8 *addr;
SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "iii", &x, &y, &color);
@@ -243,11 +254,14 @@ swfdec_bitmap_data_setPixel (SwfdecAsContext *cx, SwfdecAsObject *object,
y >= (guint) cairo_image_surface_get_height (bitmap->surface))
return;
- cr = cairo_create (bitmap->surface);
- swfdec_color_set_source (cr, SWFDEC_COLOR_OPAQUE (color));
- cairo_rectangle (cr, x, y, 1, 1);
- cairo_fill (cr);
- cairo_destroy (cr);
+ addr = cairo_image_surface_get_data (bitmap->surface);
+ addr += cairo_image_surface_get_stride (bitmap->surface) * y;
+ addr += 4 * x;
+ old = *(SwfdecColor *) addr;
+ old |= SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0);
+ color = old & SWFDEC_COLOR_OPAQUE (color);
+ *(SwfdecColor *) addr = SWFDEC_COLOR_MULTIPLY (color);
+ cairo_surface_mark_dirty_rectangle (bitmap->surface, x, y, 1, 1);
swfdec_bitmap_data_invalidate (bitmap, x, y, 1, 1);
}
@@ -322,7 +336,7 @@ swfdec_bitmap_data_setPixel32 (SwfdecAsContext *cx, SwfdecAsObject *object,
{
SwfdecBitmapData *bitmap;
guint x, y, color;
- cairo_t *cr;
+ guint8 *addr;
SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "iii", &x, &y, &color);
@@ -331,11 +345,11 @@ swfdec_bitmap_data_setPixel32 (SwfdecAsContext *cx, SwfdecAsObject *object,
y >= (guint) cairo_image_surface_get_height (bitmap->surface))
return;
- cr = cairo_create (bitmap->surface);
- swfdec_color_set_source (cr, color);
- cairo_rectangle (cr, x, y, 1, 1);
- cairo_fill (cr);
- cairo_destroy (cr);
+ addr = cairo_image_surface_get_data (bitmap->surface);
+ addr += cairo_image_surface_get_stride (bitmap->surface) * y;
+ addr += 4 * x;
+ *(SwfdecColor *) addr = SWFDEC_COLOR_MULTIPLY ((SwfdecColor) color);
+ cairo_surface_mark_dirty_rectangle (bitmap->surface, x, y, 1, 1);
swfdec_bitmap_data_invalidate (bitmap, x, y, 1, 1);
}
commit 91913461dbc97059ca7914629982901488c00aef
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Jul 25 10:57:03 2008 +0200
rename SWFDEC_COLOR_[RGB] macros to SWFDEC_COLOR_(RED|GREEN|BLUE)
diff --git a/swfdec/swfdec_bots.c b/swfdec/swfdec_bots.c
index b18aa78..b5d8177 100644
--- a/swfdec/swfdec_bots.c
+++ b/swfdec/swfdec_bots.c
@@ -432,9 +432,9 @@ swfdec_bots_put_rgb (SwfdecBots *bots, SwfdecColor color)
{
g_return_if_fail (bots != NULL);
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_R (color));
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_G (color));
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_B (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_RED (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_GREEN (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_BLUE (color));
}
void
@@ -442,9 +442,9 @@ swfdec_bots_put_rgba (SwfdecBots *bots, SwfdecColor color)
{
g_return_if_fail (bots != NULL);
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_R (color));
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_G (color));
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_B (color));
- swfdec_bots_put_u8 (bots, SWFDEC_COLOR_A (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_RED (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_GREEN (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_BLUE (color));
+ swfdec_bots_put_u8 (bots, SWFDEC_COLOR_ALPHA (color));
}
diff --git a/swfdec/swfdec_color.c b/swfdec/swfdec_color.c
index 625cf70..cb4ba75 100644
--- a/swfdec/swfdec_color.c
+++ b/swfdec/swfdec_color.c
@@ -40,10 +40,10 @@ swfdec_color_apply_morph (SwfdecColor start, SwfdecColor end, guint ratio)
return end;
start_ratio = 65535 - ratio;
end_ratio = ratio;
- r = (SWFDEC_COLOR_R (start) * start_ratio + SWFDEC_COLOR_R (end) * end_ratio) / 65535;
- g = (SWFDEC_COLOR_G (start) * start_ratio + SWFDEC_COLOR_G (end) * end_ratio) / 65535;
- b = (SWFDEC_COLOR_B (start) * start_ratio + SWFDEC_COLOR_B (end) * end_ratio) / 65535;
- a = (SWFDEC_COLOR_A (start) * start_ratio + SWFDEC_COLOR_A (end) * end_ratio) / 65535;
+ r = (SWFDEC_COLOR_RED (start) * start_ratio + SWFDEC_COLOR_RED (end) * end_ratio) / 65535;
+ g = (SWFDEC_COLOR_GREEN (start) * start_ratio + SWFDEC_COLOR_GREEN (end) * end_ratio) / 65535;
+ b = (SWFDEC_COLOR_BLUE (start) * start_ratio + SWFDEC_COLOR_BLUE (end) * end_ratio) / 65535;
+ a = (SWFDEC_COLOR_ALPHA (start) * start_ratio + SWFDEC_COLOR_ALPHA (end) * end_ratio) / 65535;
return SWFDEC_COLOR_COMBINE (r, g, b, a);
}
@@ -52,8 +52,8 @@ void
swfdec_color_set_source (cairo_t *cr, SwfdecColor color)
{
cairo_set_source_rgba (cr,
- SWFDEC_COLOR_R (color) / 255.0, SWFDEC_COLOR_G (color) / 255.0,
- SWFDEC_COLOR_B (color) / 255.0, SWFDEC_COLOR_A (color) / 255.0);
+ SWFDEC_COLOR_RED (color) / 255.0, SWFDEC_COLOR_GREEN (color) / 255.0,
+ SWFDEC_COLOR_BLUE (color) / 255.0, SWFDEC_COLOR_ALPHA (color) / 255.0);
}
SwfdecColor
@@ -65,16 +65,16 @@ swfdec_color_apply_transform_premultiplied (SwfdecColor in,
if (trans->mask)
return SWFDEC_COLOR_COMBINE (0, 0, 0, 255);
- aold = SWFDEC_COLOR_A (in);
+ aold = SWFDEC_COLOR_ALPHA (in);
if (aold == 0)
return 0;
a = (aold * trans->aa >> 8) + trans->ab;
a = CLAMP (a, 0, 255);
- r = SWFDEC_COLOR_R (in);
- g = SWFDEC_COLOR_G (in);
- b = SWFDEC_COLOR_B (in);
+ r = SWFDEC_COLOR_RED (in);
+ g = SWFDEC_COLOR_GREEN (in);
+ b = SWFDEC_COLOR_BLUE (in);
r = (r * trans->ra * a / aold >> 8) + trans->rb * a / 255;
r = CLAMP (r, 0, a);
g = (g * trans->ga * a / aold >> 8) + trans->gb * a / 255;
@@ -93,10 +93,10 @@ swfdec_color_apply_transform (SwfdecColor in, const SwfdecColorTransform * trans
if (trans->mask)
return SWFDEC_COLOR_COMBINE (0, 0, 0, 255);
- r = SWFDEC_COLOR_R (in);
- g = SWFDEC_COLOR_G (in);
- b = SWFDEC_COLOR_B (in);
- a = SWFDEC_COLOR_A (in);
+ r = SWFDEC_COLOR_RED (in);
+ g = SWFDEC_COLOR_GREEN (in);
+ b = SWFDEC_COLOR_BLUE (in);
+ a = SWFDEC_COLOR_ALPHA (in);
SWFDEC_LOG ("in rgba %d,%d,%d,%d", r, g, b, a);
@@ -159,13 +159,13 @@ swfdec_color_transform_init_color (SwfdecColorTransform *trans, SwfdecColor colo
{
trans->mask = FALSE;
trans->ra = 0;
- trans->rb = SWFDEC_COLOR_R (color);
+ trans->rb = SWFDEC_COLOR_RED (color);
trans->ga = 0;
- trans->gb = SWFDEC_COLOR_G (color);
+ trans->gb = SWFDEC_COLOR_GREEN (color);
trans->ba = 0;
- trans->bb = SWFDEC_COLOR_B (color);
+ trans->bb = SWFDEC_COLOR_BLUE (color);
trans->aa = 0;
- trans->ab = SWFDEC_COLOR_A (color);
+ trans->ab = SWFDEC_COLOR_ALPHA (color);
}
gboolean
diff --git a/swfdec/swfdec_color.h b/swfdec/swfdec_color.h
index 597dcae..6ec5842 100644
--- a/swfdec/swfdec_color.h
+++ b/swfdec/swfdec_color.h
@@ -48,10 +48,10 @@ struct _SwfdecColorTransform {
#define SWFDEC_COLOR_COMBINE(r,g,b,a) ((SwfdecColor) (((a)<<24) | ((r)<<16) | ((g)<<8) | (b)))
#define SWFDEC_COLOR_OPAQUE(color) ((SwfdecColor) ((color) | SWFDEC_COLOR_COMBINE (0, 0, 0, 0xFF)))
-#define SWFDEC_COLOR_A(x) (((x)>>24)&0xff)
-#define SWFDEC_COLOR_R(x) (((x)>>16)&0xff)
-#define SWFDEC_COLOR_G(x) (((x)>>8)&0xff)
-#define SWFDEC_COLOR_B(x) ((x)&0xff)
+#define SWFDEC_COLOR_ALPHA(x) (((x)>>24)&0xff)
+#define SWFDEC_COLOR_RED(x) (((x)>>16)&0xff)
+#define SWFDEC_COLOR_GREEN(x) (((x)>>8)&0xff)
+#define SWFDEC_COLOR_BLUE(x) ((x)&0xff)
#define SWFDEC_COLOR_WHITE SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF)
diff --git a/swfdec/swfdec_gradient_pattern.c b/swfdec/swfdec_gradient_pattern.c
index da4661a..b449d3f 100644
--- a/swfdec/swfdec_gradient_pattern.c
+++ b/swfdec/swfdec_gradient_pattern.c
@@ -100,8 +100,8 @@ swfdec_gradient_pattern_get_pattern (SwfdecPattern *pat, SwfdecRenderer *rendere
ratio = MAX (ratio, gradient->gradient[i].ratio);
offset = ratio / 255.0;
cairo_pattern_add_color_stop_rgba (pattern, offset,
- SWFDEC_COLOR_R(color) / 255.0, SWFDEC_COLOR_G(color) / 255.0,
- SWFDEC_COLOR_B(color) / 255.0, SWFDEC_COLOR_A(color) / 255.0);
+ SWFDEC_COLOR_RED (color) / 255.0, SWFDEC_COLOR_GREEN (color) / 255.0,
+ SWFDEC_COLOR_BLUE (color) / 255.0, SWFDEC_COLOR_ALPHA (color) / 255.0);
if (++ratio > 255)
break;
}
diff --git a/swfdec/swfdec_image.c b/swfdec/swfdec_image.c
index f7745fd..5c79c68 100644
--- a/swfdec/swfdec_image.c
+++ b/swfdec/swfdec_image.c
@@ -706,7 +706,7 @@ swfdec_image_create_surface_transformed (SwfdecImage *image, SwfdecRenderer *ren
for (i = 0; i < n; i++) {
tdata[i] = swfdec_color_apply_transform_premultiplied (sdata[i], trans);
/* optimization: check for alpha channel to speed up compositing */
- has_alpha |= SWFDEC_COLOR_A (tdata[i]) != 0xFF;
+ has_alpha |= SWFDEC_COLOR_ALPHA (tdata[i]) != 0xFF;
}
cairo_surface_destroy (source);
surface = swfdec_image_create_surface_for_data (renderer, (guchar *) tdata,
diff --git a/swfdec/swfdec_pattern.c b/swfdec/swfdec_pattern.c
index 8ec67f3..9a3b280 100644
--- a/swfdec/swfdec_pattern.c
+++ b/swfdec/swfdec_pattern.c
@@ -152,8 +152,8 @@ swfdec_color_pattern_get_pattern (SwfdecPattern *pat, SwfdecRenderer *renderer,
color = swfdec_color_apply_transform (color, trans);
return cairo_pattern_create_rgba (
- SWFDEC_COLOR_R (color) / 255.0, SWFDEC_COLOR_G (color) / 255.0,
- SWFDEC_COLOR_B (color) / 255.0, SWFDEC_COLOR_A (color) / 255.0);
+ SWFDEC_COLOR_RED (color) / 255.0, SWFDEC_COLOR_GREEN (color) / 255.0,
+ SWFDEC_COLOR_BLUE (color) / 255.0, SWFDEC_COLOR_ALPHA (color) / 255.0);
}
static void
diff --git a/swfdec/swfdec_text_field_movie_as.c b/swfdec/swfdec_text_field_movie_as.c
index 77ecab6..75a5ea9 100644
--- a/swfdec/swfdec_text_field_movie_as.c
+++ b/swfdec/swfdec_text_field_movie_as.c
@@ -495,9 +495,9 @@ swfdec_text_field_movie_get_backgroundColor (SwfdecAsContext *cx,
SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
SWFDEC_AS_VALUE_SET_NUMBER (ret,
- SWFDEC_COLOR_R (text->background_color) << 16 |
- SWFDEC_COLOR_G (text->background_color) << 8 |
- SWFDEC_COLOR_B (text->background_color));
+ SWFDEC_COLOR_RED (text->background_color) << 16 |
+ SWFDEC_COLOR_GREEN (text->background_color) << 8 |
+ SWFDEC_COLOR_BLUE (text->background_color));
}
static void
@@ -559,9 +559,9 @@ swfdec_text_field_movie_get_borderColor (SwfdecAsContext *cx,
SWFDEC_AS_VALUE_SET_NUMBER (ret,
- SWFDEC_COLOR_R (text->border_color) << 16 |
- SWFDEC_COLOR_G (text->border_color) << 8 |
- SWFDEC_COLOR_B (text->border_color));
+ SWFDEC_COLOR_RED (text->border_color) << 16 |
+ SWFDEC_COLOR_GREEN (text->border_color) << 8 |
+ SWFDEC_COLOR_BLUE (text->border_color));
}
static void
diff --git a/swfdec/swfdec_text_layout.c b/swfdec/swfdec_text_layout.c
index 405f1cf..ea7c934 100644
--- a/swfdec/swfdec_text_layout.c
+++ b/swfdec/swfdec_text_layout.c
@@ -42,8 +42,8 @@ swfdec_text_attribute_apply_bold (SwfdecTextLayout *layout, const SwfdecTextAttr
static PangoAttribute *
swfdec_text_attribute_create_color (SwfdecTextLayout *layout, const SwfdecTextAttributes *attr)
{
- return pango_attr_foreground_new (SWFDEC_COLOR_R (attr->color) * 255,
- SWFDEC_COLOR_G (attr->color) * 255, SWFDEC_COLOR_B (attr->color) * 255);
+ return pango_attr_foreground_new (SWFDEC_COLOR_RED (attr->color) * 255,
+ SWFDEC_COLOR_GREEN (attr->color) * 255, SWFDEC_COLOR_BLUE (attr->color) * 255);
}
static void
@@ -873,25 +873,25 @@ swfdec_text_layout_modify_attributes (SwfdecTextLayout *layout,
color = swfdec_color_apply_transform (color, ctrans);
/* We differentiate three ranges: before selection, in selection and after selection */
if (cur_start < sel_start) {
- PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_R (color) * 0x101,
- SWFDEC_COLOR_G (color) * 0x101, SWFDEC_COLOR_B (color) * 0x101);
+ PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_RED (color) * 0x101,
+ SWFDEC_COLOR_GREEN (color) * 0x101, SWFDEC_COLOR_BLUE (color) * 0x101);
fg->start_index = cur_start;
fg->end_index = MIN (cur_end, sel_start);
pango_attr_list_change (new, fg);
}
if (sel_start < cur_end && sel_end > cur_start) {
- PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_R (focus) * 0x101,
- SWFDEC_COLOR_G (focus) * 0x101, SWFDEC_COLOR_B (focus) * 0x101);
- PangoAttribute *bg = pango_attr_background_new (SWFDEC_COLOR_R (color) * 0x101,
- SWFDEC_COLOR_G (color) * 0x101, SWFDEC_COLOR_B (color) * 0x101);
+ PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_RED (focus) * 0x101,
+ SWFDEC_COLOR_GREEN (focus) * 0x101, SWFDEC_COLOR_BLUE (focus) * 0x101);
+ PangoAttribute *bg = pango_attr_background_new (SWFDEC_COLOR_RED (color) * 0x101,
+ SWFDEC_COLOR_GREEN (color) * 0x101, SWFDEC_COLOR_BLUE (color) * 0x101);
fg->start_index = bg->start_index = MAX (cur_start, sel_start);
fg->end_index = bg->end_index = MIN (cur_end, sel_end);
pango_attr_list_change (new, fg);
pango_attr_list_change (new, bg);
}
if (cur_end > sel_end) {
- PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_R (color) * 0x101,
- SWFDEC_COLOR_G (color) * 0x101, SWFDEC_COLOR_B (color) * 0x101);
+ PangoAttribute *fg = pango_attr_foreground_new (SWFDEC_COLOR_RED (color) * 0x101,
+ SWFDEC_COLOR_GREEN (color) * 0x101, SWFDEC_COLOR_BLUE (color) * 0x101);
fg->start_index = MAX (sel_end, cur_start);
fg->end_index = cur_end;
pango_attr_list_change (new, fg);
commit ec03f84ce2313c33b34a174bd93f77c8cb1e9140
Author: Benjamin Otte <otte at gnome.org>
Date: Fri Jul 25 10:47:53 2008 +0200
use height for height, not width
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index 473060a..f9a6627 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -134,7 +134,7 @@ swfdec_bitmap_data_get_height (SwfdecAsContext *cx, SwfdecAsObject *object,
SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "");
SWFDEC_AS_VALUE_SET_INT (ret, bitmap->surface ?
- cairo_image_surface_get_width (bitmap->surface) : -1);
+ cairo_image_surface_get_height (bitmap->surface) : -1);
}
SWFDEC_AS_NATIVE (1100, 103, swfdec_bitmap_data_set_height)
commit 7e099f635c7ee9061c589a624374231606ac049d
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 23:13:06 2008 +0200
implement BitmapData.setPixel and BitmapData.setPixel32
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index ab96a17..473060a 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -232,7 +232,23 @@ void
swfdec_bitmap_data_setPixel (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SWFDEC_STUB ("BitmapData.setPixel");
+ SwfdecBitmapData *bitmap;
+ guint x, y, color;
+ cairo_t *cr;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "iii", &x, &y, &color);
+
+ if (bitmap->surface == NULL ||
+ x >= (guint) cairo_image_surface_get_width (bitmap->surface) ||
+ y >= (guint) cairo_image_surface_get_height (bitmap->surface))
+ return;
+
+ cr = cairo_create (bitmap->surface);
+ swfdec_color_set_source (cr, SWFDEC_COLOR_OPAQUE (color));
+ cairo_rectangle (cr, x, y, 1, 1);
+ cairo_fill (cr);
+ cairo_destroy (cr);
+ swfdec_bitmap_data_invalidate (bitmap, x, y, 1, 1);
}
SWFDEC_AS_NATIVE (1100, 3, swfdec_bitmap_data_fillRect)
@@ -304,7 +320,23 @@ void
swfdec_bitmap_data_setPixel32 (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
{
- SWFDEC_STUB ("BitmapData.setPixel32");
+ SwfdecBitmapData *bitmap;
+ guint x, y, color;
+ cairo_t *cr;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_BITMAP_DATA, &bitmap, "iii", &x, &y, &color);
+
+ if (bitmap->surface == NULL ||
+ x >= (guint) cairo_image_surface_get_width (bitmap->surface) ||
+ y >= (guint) cairo_image_surface_get_height (bitmap->surface))
+ return;
+
+ cr = cairo_create (bitmap->surface);
+ swfdec_color_set_source (cr, color);
+ cairo_rectangle (cr, x, y, 1, 1);
+ cairo_fill (cr);
+ cairo_destroy (cr);
+ swfdec_bitmap_data_invalidate (bitmap, x, y, 1, 1);
}
SWFDEC_AS_NATIVE (1100, 12, swfdec_bitmap_data_floodFill)
commit e99087fa676bfa5c9ddf4508d1af75b17b369efe
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 23:05:03 2008 +0200
connect to the bitmap data's "invalidate" signal
diff --git a/swfdec/swfdec_bitmap_movie.c b/swfdec/swfdec_bitmap_movie.c
index 0d80d08..a117feb 100644
--- a/swfdec/swfdec_bitmap_movie.c
+++ b/swfdec/swfdec_bitmap_movie.c
@@ -107,11 +107,26 @@ swfdec_bitmap_movie_mark (SwfdecGcObject *object)
}
static void
+swfdec_bitmap_movie_dispose (GObject *object)
+{
+ SwfdecBitmapMovie *bitmap = SWFDEC_BITMAP_MOVIE (object);
+
+ g_signal_handlers_disconnect_by_func (bitmap->bitmap,
+ swfdec_movie_invalidate_last, bitmap);
+ g_object_unref (bitmap->bitmap);
+
+ G_OBJECT_CLASS (swfdec_bitmap_movie_parent_class)->dispose (object);
+}
+
+static void
swfdec_bitmap_movie_class_init (SwfdecBitmapMovieClass * g_class)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (g_class);
SwfdecGcObjectClass *gc_class = SWFDEC_GC_OBJECT_CLASS (g_class);
SwfdecMovieClass *movie_class = SWFDEC_MOVIE_CLASS (g_class);
+ object_class->dispose = swfdec_bitmap_movie_dispose;
+
gc_class->mark = swfdec_bitmap_movie_mark;
movie_class->update_extents = swfdec_bitmap_movie_update_extents;
@@ -130,13 +145,18 @@ swfdec_bitmap_movie_new (SwfdecMovie *parent, SwfdecBitmapData *bitmap, int dept
{
SwfdecBitmapMovie *movie;
- g_return_val_if_fail (SWFDEC_IS_MOVIE (parent));
- g_return_val_if_fail (SWFDEC_IS_BITMAP_DATA (bitmap));
+ g_return_val_if_fail (SWFDEC_IS_MOVIE (parent), NULL);
+ g_return_val_if_fail (SWFDEC_IS_BITMAP_DATA (bitmap), NULL);
movie = g_object_new (SWFDEC_TYPE_BITMAP_MOVIE,
"context", swfdec_gc_object_get_context (parent), "depth", depth,
"parent", parent, "resource", parent->resource, NULL);
movie->bitmap = bitmap;
+ /* we ref the bitmap here to enforce the order for destruction, which makes our signals work */
+ g_object_ref (bitmap);
+ /* FIXME: be smarter in what we invalidate, use the rectangle */
+ g_signal_connect_swapped (movie->bitmap, "invalidate",
+ G_CALLBACK (swfdec_movie_invalidate_last), movie);
return SWFDEC_MOVIE (movie);
}
commit 9da9607300f99077123d097f102ef8446aae7770
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 23:04:11 2008 +0200
invalidate the full image, not just parts of it
diff --git a/swfdec/swfdec_bitmap_movie.c b/swfdec/swfdec_bitmap_movie.c
index bde4926..0d80d08 100644
--- a/swfdec/swfdec_bitmap_movie.c
+++ b/swfdec/swfdec_bitmap_movie.c
@@ -82,8 +82,8 @@ swfdec_bitmap_movie_invalidate (SwfdecMovie *movie, const cairo_matrix_t *matrix
if (bitmap->bitmap->surface == NULL)
return;
- rect.x1 = cairo_image_surface_get_width (bitmap->bitmap->surface);
- rect.y1 = cairo_image_surface_get_height (bitmap->bitmap->surface);
+ rect.x1 = cairo_image_surface_get_width (bitmap->bitmap->surface) * SWFDEC_TWIPS_SCALE_FACTOR;
+ rect.y1 = cairo_image_surface_get_height (bitmap->bitmap->surface) * SWFDEC_TWIPS_SCALE_FACTOR;
swfdec_rect_transform (&rect, &rect, matrix);
swfdec_player_invalidate (SWFDEC_PLAYER (swfdec_gc_object_get_context (movie)), &rect);
commit 55333e28a0b9f47ca6c629bd6ab0aff90959f267
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 21:54:39 2008 +0200
add a swfdec_bitmap_movie_new() function
diff --git a/swfdec/swfdec_bitmap_movie.c b/swfdec/swfdec_bitmap_movie.c
index feb6ee6..bde4926 100644
--- a/swfdec/swfdec_bitmap_movie.c
+++ b/swfdec/swfdec_bitmap_movie.c
@@ -125,3 +125,18 @@ swfdec_bitmap_movie_init (SwfdecBitmapMovie * bitmap_movie)
{
}
+SwfdecMovie *
+swfdec_bitmap_movie_new (SwfdecMovie *parent, SwfdecBitmapData *bitmap, int depth)
+{
+ SwfdecBitmapMovie *movie;
+
+ g_return_val_if_fail (SWFDEC_IS_MOVIE (parent));
+ g_return_val_if_fail (SWFDEC_IS_BITMAP_DATA (bitmap));
+
+ movie = g_object_new (SWFDEC_TYPE_BITMAP_MOVIE,
+ "context", swfdec_gc_object_get_context (parent), "depth", depth,
+ "parent", parent, "resource", parent->resource, NULL);
+ movie->bitmap = bitmap;
+
+ return SWFDEC_MOVIE (movie);
+}
diff --git a/swfdec/swfdec_bitmap_movie.h b/swfdec/swfdec_bitmap_movie.h
index e9aa782..1d0395a 100644
--- a/swfdec/swfdec_bitmap_movie.h
+++ b/swfdec/swfdec_bitmap_movie.h
@@ -48,6 +48,10 @@ struct _SwfdecBitmapMovieClass {
GType swfdec_bitmap_movie_get_type (void);
+SwfdecMovie * swfdec_bitmap_movie_new (SwfdecMovie * parent,
+ SwfdecBitmapData * bitmap,
+ int depth);
+
G_END_DECLS
#endif
diff --git a/swfdec/swfdec_sprite_movie_as.c b/swfdec/swfdec_sprite_movie_as.c
index 0c639f8..95f38b7 100644
--- a/swfdec/swfdec_sprite_movie_as.c
+++ b/swfdec/swfdec_sprite_movie_as.c
@@ -367,9 +367,7 @@ swfdec_sprite_movie_attachBitmap (SwfdecAsContext *cx, SwfdecAsObject *object,
if (movie)
swfdec_movie_remove (movie);
- movie = g_object_new (SWFDEC_TYPE_BITMAP_MOVIE, "context", cx, "depth", depth,
- "parent", parent, "resource", parent->resource, NULL);
- SWFDEC_BITMAP_MOVIE (movie)->bitmap = bitmap;
+ swfdec_bitmap_movie_new (parent, bitmap, depth);
SWFDEC_LOG ("created new BitmapMovie to parent %s at depth %d",
parent->name, depth);
}
commit 278034d349ae3a570c4b855d51b7214373b6fda8
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 21:36:49 2008 +0200
make sure BitmapData objects look fine
diff --git a/test/image/BitmapData-creation-5.swf b/test/image/BitmapData-creation-5.swf
new file mode 100644
index 0000000..8b69815
Binary files /dev/null and b/test/image/BitmapData-creation-5.swf differ
diff --git a/test/image/BitmapData-creation-5.swf.png b/test/image/BitmapData-creation-5.swf.png
new file mode 100644
index 0000000..f5ad83c
Binary files /dev/null and b/test/image/BitmapData-creation-5.swf.png differ
diff --git a/test/image/BitmapData-creation-6.swf b/test/image/BitmapData-creation-6.swf
new file mode 100644
index 0000000..ec56c68
Binary files /dev/null and b/test/image/BitmapData-creation-6.swf differ
diff --git a/test/image/BitmapData-creation-6.swf.png b/test/image/BitmapData-creation-6.swf.png
new file mode 100644
index 0000000..0bc4739
Binary files /dev/null and b/test/image/BitmapData-creation-6.swf.png differ
diff --git a/test/image/BitmapData-creation-7.swf b/test/image/BitmapData-creation-7.swf
new file mode 100644
index 0000000..86f0282
Binary files /dev/null and b/test/image/BitmapData-creation-7.swf differ
diff --git a/test/image/BitmapData-creation-7.swf.png b/test/image/BitmapData-creation-7.swf.png
new file mode 100644
index 0000000..85d2493
Binary files /dev/null and b/test/image/BitmapData-creation-7.swf.png differ
diff --git a/test/image/BitmapData-creation-8.swf b/test/image/BitmapData-creation-8.swf
new file mode 100644
index 0000000..9fa2b47
Binary files /dev/null and b/test/image/BitmapData-creation-8.swf differ
diff --git a/test/image/BitmapData-creation-8.swf.png b/test/image/BitmapData-creation-8.swf.png
new file mode 100644
index 0000000..72b7694
Binary files /dev/null and b/test/image/BitmapData-creation-8.swf.png differ
diff --git a/test/image/BitmapData-creation.as b/test/image/BitmapData-creation.as
new file mode 100644
index 0000000..a992abe
--- /dev/null
+++ b/test/image/BitmapData-creation.as
@@ -0,0 +1,33 @@
+// makeswf -v 7 -s 200x150 -r 1 -o BitmapData-creation.swf BitmapData-creation.as
+
+test = function (color)
+{
+ var d = getNextHighestDepth();
+ var x = createEmptyMovieClip ("a" + d, d);
+ var bd = new flash.display.BitmapData (10, 10, false, color);
+ x.attachBitmap (bd, 0);
+ x._x = d % 20 * 10;
+ x._y = int (d / 20) * 10;
+
+ d = getNextHighestDepth();
+ x = createEmptyMovieClip ("a" + d, d);
+ bd = new flash.display.BitmapData (10, 10, true, color);
+ x.attachBitmap (bd, 0);
+ x._x = d % 20 * 10;
+ x._y = int (d / 20) * 10;
+};
+
+test (0);
+test (0xFF);
+test (0xFF0000FF);
+test (0xFF0000);
+test (0xFFFF0000);
+test (0x1FF008000);
+test (-1);
+test ();
+
+#include "values.as"
+for (i = 0; i < values.length; i++) {
+ test (values[i]);
+}
+
diff --git a/test/image/Makefile.am b/test/image/Makefile.am
index a4f3ab7..8ba0ce9 100644
--- a/test/image/Makefile.am
+++ b/test/image/Makefile.am
@@ -2,6 +2,15 @@ check-local: ../swfdec-test
../swfdec-test --script $(srcdir)/default.sts $(srcdir)/*.swf
EXTRA_DIST = \
+ BitmapData-creation-5.swf \
+ BitmapData-creation-5.swf.png \
+ BitmapData-creation-6.swf \
+ BitmapData-creation-6.swf.png \
+ BitmapData-creation-7.swf \
+ BitmapData-creation-7.swf.png \
+ BitmapData-creation-8.swf \
+ BitmapData-creation-8.swf.png \
+ BitmapData-creation.as \
README \
background-5.swf \
background-5.swf.png \
commit 19ca3ad9d9843e136681cdd9c9c2ddc4ee676d3c
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 21:24:39 2008 +0200
add a test for MovieClip.attachBitmap
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 3ec7539..b78d994 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -362,6 +362,15 @@ EXTRA_DIST = \
atan2-8.swf \
atan2-8.swf.trace \
atan2.as \
+ attachBitmap-5.swf \
+ attachBitmap-5.swf.trace \
+ attachBitmap-6.swf \
+ attachBitmap-6.swf.trace \
+ attachBitmap-7.swf \
+ attachBitmap-7.swf.trace \
+ attachBitmap-8.swf \
+ attachBitmap-8.swf.trace \
+ attachBitmap.as \
attachMovie-height-5.swf \
attachMovie-height-5.swf.trace \
attachMovie-height-6.swf \
diff --git a/test/trace/attachBitmap-5.swf b/test/trace/attachBitmap-5.swf
new file mode 100644
index 0000000..b434fbd
Binary files /dev/null and b/test/trace/attachBitmap-5.swf differ
diff --git a/test/trace/attachBitmap-5.swf.trace b/test/trace/attachBitmap-5.swf.trace
new file mode 100644
index 0000000..d9080ef
--- /dev/null
+++ b/test/trace/attachBitmap-5.swf.trace
@@ -0,0 +1,5 @@
+undefined
+undefined
+undefined
+undefined
+undefined
diff --git a/test/trace/attachBitmap-6.swf b/test/trace/attachBitmap-6.swf
new file mode 100644
index 0000000..20e2338
Binary files /dev/null and b/test/trace/attachBitmap-6.swf differ
diff --git a/test/trace/attachBitmap-6.swf.trace b/test/trace/attachBitmap-6.swf.trace
new file mode 100644
index 0000000..b2993a7
--- /dev/null
+++ b/test/trace/attachBitmap-6.swf.trace
@@ -0,0 +1,5 @@
+_level0.a.a
+_level0.a.a
+undefined
+0
+0
diff --git a/test/trace/attachBitmap-7.swf b/test/trace/attachBitmap-7.swf
new file mode 100644
index 0000000..6705114
Binary files /dev/null and b/test/trace/attachBitmap-7.swf differ
diff --git a/test/trace/attachBitmap-7.swf.trace b/test/trace/attachBitmap-7.swf.trace
new file mode 100644
index 0000000..d4e69cf
--- /dev/null
+++ b/test/trace/attachBitmap-7.swf.trace
@@ -0,0 +1,5 @@
+_level0.a.a
+_level0.a.a
+_level0.a.a
+0
+0
diff --git a/test/trace/attachBitmap-8.swf b/test/trace/attachBitmap-8.swf
new file mode 100644
index 0000000..b92b8ef
Binary files /dev/null and b/test/trace/attachBitmap-8.swf differ
diff --git a/test/trace/attachBitmap-8.swf.trace b/test/trace/attachBitmap-8.swf.trace
new file mode 100644
index 0000000..f5f1fe8
--- /dev/null
+++ b/test/trace/attachBitmap-8.swf.trace
@@ -0,0 +1,5 @@
+_level0.a.a
+undefined
+_level0.a
+100
+100
diff --git a/test/trace/attachBitmap.as b/test/trace/attachBitmap.as
new file mode 100644
index 0000000..6d267da
--- /dev/null
+++ b/test/trace/attachBitmap.as
@@ -0,0 +1,14 @@
+// makeswf -v 7 -s 200x150 -r 1 -o attachBitmap.swf attachBitmap.as
+
+createEmptyMovieClip ("a", 0);
+a.createEmptyMovieClip ("a", 0);
+red = new flash.display.BitmapData (100, 100, false, 0xFF0000);
+trace (a.a);
+a.attachBitmap (red, 0);
+trace (a.a);
+trace (a.getInstanceAtDepth (0));
+
+trace (a._width);
+trace (a._height);
+
+getURL ("fscommand:quit", "");
commit 1b2137258fe12f9f458a17ed4eb6c604dae1e600
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 20:49:34 2008 +0200
add a custom movie type for use with MovieClip.attachBitmap
diff --git a/swfdec/Makefile.am b/swfdec/Makefile.am
index f8dbc00..6253fde 100644
--- a/swfdec/Makefile.am
+++ b/swfdec/Makefile.am
@@ -46,6 +46,7 @@ libswfdec_source_files = \
swfdec_bevel_filter.c \
swfdec_bitmap_data.c \
swfdec_bitmap_filter.c \
+ swfdec_bitmap_movie.c \
swfdec_bits.c \
swfdec_blur_filter.c \
swfdec_bots.c \
@@ -248,6 +249,7 @@ noinst_HEADERS = \
swfdec_audio_stream.h \
swfdec_audio_swf_stream.h \
swfdec_bitmap_data.h \
+ swfdec_bitmap_movie.h \
swfdec_bits.h \
swfdec_bots.h \
swfdec_button.h \
diff --git a/swfdec/swfdec_bitmap_movie.c b/swfdec/swfdec_bitmap_movie.c
new file mode 100644
index 0000000..feb6ee6
--- /dev/null
+++ b/swfdec/swfdec_bitmap_movie.c
@@ -0,0 +1,127 @@
+/* Swfdec
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_bitmap_movie.h"
+#include "swfdec_debug.h"
+#include "swfdec_player_internal.h"
+
+G_DEFINE_TYPE (SwfdecBitmapMovie, swfdec_bitmap_movie, SWFDEC_TYPE_MOVIE)
+
+static void
+swfdec_bitmap_movie_update_extents (SwfdecMovie *movie,
+ SwfdecRect *extents)
+{
+ SwfdecBitmapMovie *bitmap = SWFDEC_BITMAP_MOVIE (movie);
+ SwfdecRect rect = { 0, 0, 0, 0 };
+
+ if (bitmap->bitmap->surface == NULL)
+ return;
+
+ rect.x1 = cairo_image_surface_get_width (bitmap->bitmap->surface) * SWFDEC_TWIPS_SCALE_FACTOR;
+ rect.y1 = cairo_image_surface_get_height (bitmap->bitmap->surface) * SWFDEC_TWIPS_SCALE_FACTOR;
+
+ swfdec_rect_union (extents, extents, &rect);
+}
+
+static void
+swfdec_bitmap_movie_render (SwfdecMovie *movie, cairo_t *cr,
+ const SwfdecColorTransform *trans)
+{
+ SwfdecBitmapMovie *bitmap = SWFDEC_BITMAP_MOVIE (movie);
+
+ if (bitmap->bitmap->surface == NULL)
+ return;
+
+ cairo_scale (cr, SWFDEC_TWIPS_SCALE_FACTOR, SWFDEC_TWIPS_SCALE_FACTOR);
+ if (swfdec_color_transform_is_mask (trans)) {
+ SWFDEC_FIXME ("does attachBitmap mask?");
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_rectangle (cr, 0, 0,
+ cairo_image_surface_get_width (bitmap->bitmap->surface),
+ cairo_image_surface_get_height (bitmap->bitmap->surface));
+ cairo_fill (cr);
+ } else if (swfdec_color_transform_is_identity (trans)) {
+ cairo_set_source_surface (cr, bitmap->bitmap->surface, 0, 0);
+ cairo_paint (cr);
+ } else if (swfdec_color_transform_is_alpha (trans)) {
+ cairo_set_source_surface (cr, bitmap->bitmap->surface, 0, 0);
+ cairo_paint_with_alpha (cr, trans->aa / 255.0);
+ } else {
+ SWFDEC_FIXME ("properly color-transform bitmap");
+ cairo_set_source_surface (cr, bitmap->bitmap->surface, 0, 0);
+ cairo_paint (cr);
+ }
+}
+
+static void
+swfdec_bitmap_movie_invalidate (SwfdecMovie *movie, const cairo_matrix_t *matrix, gboolean last)
+{
+ SwfdecBitmapMovie *bitmap = SWFDEC_BITMAP_MOVIE (movie);
+ SwfdecRect rect = { 0, 0, 0, 0 };
+
+ if (bitmap->bitmap->surface == NULL)
+ return;
+
+ rect.x1 = cairo_image_surface_get_width (bitmap->bitmap->surface);
+ rect.y1 = cairo_image_surface_get_height (bitmap->bitmap->surface);
+
+ swfdec_rect_transform (&rect, &rect, matrix);
+ swfdec_player_invalidate (SWFDEC_PLAYER (swfdec_gc_object_get_context (movie)), &rect);
+}
+
+static SwfdecMovie *
+swfdec_bitmap_movie_contains (SwfdecMovie *movie, double x, double y,
+ gboolean events)
+{
+ return movie;
+}
+
+static void
+swfdec_bitmap_movie_mark (SwfdecGcObject *object)
+{
+ SwfdecBitmapMovie *bitmap = SWFDEC_BITMAP_MOVIE (object);
+
+ swfdec_gc_object_mark (bitmap->bitmap);
+
+ SWFDEC_GC_OBJECT_CLASS (swfdec_bitmap_movie_parent_class)->mark (object);
+}
+
+static void
+swfdec_bitmap_movie_class_init (SwfdecBitmapMovieClass * g_class)
+{
+ SwfdecGcObjectClass *gc_class = SWFDEC_GC_OBJECT_CLASS (g_class);
+ SwfdecMovieClass *movie_class = SWFDEC_MOVIE_CLASS (g_class);
+
+ gc_class->mark = swfdec_bitmap_movie_mark;
+
+ movie_class->update_extents = swfdec_bitmap_movie_update_extents;
+ movie_class->render = swfdec_bitmap_movie_render;
+ movie_class->invalidate = swfdec_bitmap_movie_invalidate;
+ movie_class->contains = swfdec_bitmap_movie_contains;
+}
+
+static void
+swfdec_bitmap_movie_init (SwfdecBitmapMovie * bitmap_movie)
+{
+}
+
diff --git a/swfdec/swfdec_bitmap_movie.h b/swfdec/swfdec_bitmap_movie.h
new file mode 100644
index 0000000..e9aa782
--- /dev/null
+++ b/swfdec/swfdec_bitmap_movie.h
@@ -0,0 +1,53 @@
+/* Swfdec
+ * Copyright (C) 2008 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef _SWFDEC_BITMAP_MOVIE_H_
+#define _SWFDEC_BITMAP_MOVIE_H_
+
+#include <glib-object.h>
+#include <swfdec/swfdec_bitmap_data.h>
+#include <swfdec/swfdec_movie.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _SwfdecBitmapMovie SwfdecBitmapMovie;
+typedef struct _SwfdecBitmapMovieClass SwfdecBitmapMovieClass;
+
+#define SWFDEC_TYPE_BITMAP_MOVIE (swfdec_bitmap_movie_get_type())
+#define SWFDEC_IS_BITMAP_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_BITMAP_MOVIE))
+#define SWFDEC_IS_BITMAP_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_BITMAP_MOVIE))
+#define SWFDEC_BITMAP_MOVIE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_BITMAP_MOVIE, SwfdecBitmapMovie))
+#define SWFDEC_BITMAP_MOVIE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_BITMAP_MOVIE, SwfdecBitmapMovieClass))
+
+struct _SwfdecBitmapMovie {
+ SwfdecMovie movie;
+
+ SwfdecBitmapData * bitmap; /* the bitmap we are attached to */
+};
+
+struct _SwfdecBitmapMovieClass {
+ SwfdecMovieClass movie_class;
+};
+
+GType swfdec_bitmap_movie_get_type (void);
+
+
+G_END_DECLS
+#endif
diff --git a/swfdec/swfdec_sprite_movie_as.c b/swfdec/swfdec_sprite_movie_as.c
index a2f29fc..0c639f8 100644
--- a/swfdec/swfdec_sprite_movie_as.c
+++ b/swfdec/swfdec_sprite_movie_as.c
@@ -1,7 +1,7 @@
/* Swfdec
* Copyright (C) 2003-2006 David Schleef <ds at schleef.org>
* 2005-2006 Eric Anholt <eric at anholt.net>
- * 2006-2007 Benjamin Otte <otte at gnome.org>
+ * 2006-2008 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
@@ -26,6 +26,8 @@
#include "swfdec_movie.h"
#include "swfdec_as_internal.h"
#include "swfdec_as_strings.h"
+#include "swfdec_bitmap_data.h"
+#include "swfdec_bitmap_movie.h"
#include "swfdec_bits.h"
#include "swfdec_debug.h"
#include "swfdec_decoder.h"
@@ -346,7 +348,30 @@ void
swfdec_sprite_movie_attachBitmap (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
{
- SWFDEC_STUB ("MovieClip.attachBitmap");
+ SwfdecMovie *parent;
+ SwfdecBitmapData *bitmap;
+ const char *snapping;
+ gboolean smoothing;
+ int depth;
+ SwfdecMovie *movie;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_SPRITE_MOVIE, &parent, "oi|sb",
+ &bitmap, &depth, &snapping, &smoothing);
+
+ if (!SWFDEC_IS_BITMAP_DATA (bitmap))
+ return;
+ if (swfdec_depth_classify (depth) == SWFDEC_DEPTH_CLASS_EMPTY)
+ return;
+
+ movie = swfdec_movie_find (parent, depth);
+ if (movie)
+ swfdec_movie_remove (movie);
+
+ movie = g_object_new (SWFDEC_TYPE_BITMAP_MOVIE, "context", cx, "depth", depth,
+ "parent", parent, "resource", parent->resource, NULL);
+ SWFDEC_BITMAP_MOVIE (movie)->bitmap = bitmap;
+ SWFDEC_LOG ("created new BitmapMovie to parent %s at depth %d",
+ parent->name, depth);
}
SWFDEC_AS_NATIVE (900, 26, swfdec_sprite_movie_getRect)
commit c45b9eb894ccc5dad4df7b047100f5ec9d36ebf2
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 20:47:46 2008 +0200
make getInstanceAtDepth() not return unscriptable movies
diff --git a/swfdec/swfdec_sprite_movie_as.c b/swfdec/swfdec_sprite_movie_as.c
index bfd62b0..a2f29fc 100644
--- a/swfdec/swfdec_sprite_movie_as.c
+++ b/swfdec/swfdec_sprite_movie_as.c
@@ -321,8 +321,11 @@ swfdec_sprite_movie_getInstanceAtDepth (SwfdecAsContext *cx,
return;
movie = swfdec_movie_find (movie, depth);
- if (movie != NULL)
+ if (movie != NULL) {
+ if (!swfdec_movie_is_scriptable (movie))
+ movie = movie->parent;
SWFDEC_AS_VALUE_SET_OBJECT (rval, SWFDEC_AS_OBJECT (movie));
+ }
}
SWFDEC_AS_NATIVE (900, 24, swfdec_sprite_movie_getSWFVersion)
commit 95e8eee8fd06c52ed002e3d1b869e40056285cea
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 20:46:40 2008 +0200
export swfdec_movie_is_scriptable()
diff --git a/swfdec/swfdec_movie.c b/swfdec/swfdec_movie.c
index dbab3b8..8d1d0d3 100644
--- a/swfdec/swfdec_movie.c
+++ b/swfdec/swfdec_movie.c
@@ -999,9 +999,23 @@ swfdec_movie_mark (SwfdecGcObject *object)
SWFDEC_GC_OBJECT_CLASS (swfdec_movie_parent_class)->mark (object);
}
-#define swfdec_movie_is_scriptable(mov) \
- ((SWFDEC_IS_ACTOR (mov) || SWFDEC_IS_VIDEO_MOVIE (mov)) && \
- (swfdec_movie_get_version (mov) > 5 || !SWFDEC_IS_TEXT_FIELD_MOVIE (mov)))
+/**
+ * swfdec_movie_is_scriptable:
+ * @movie: a movie
+ *
+ * Checks if the movie may be accessed by scripts. If not, the movie is not
+ * accessible by Actionscript and functions that would return the movie should
+ * instead return its parent.
+ *
+ * Returns: %TRUE if scripts may access this movie, %FALSE if the parent
+ * should be used.
+ **/
+gboolean
+swfdec_movie_is_scriptable (SwfdecMovie *movie)
+{
+ return (SWFDEC_IS_ACTOR (movie) || SWFDEC_IS_VIDEO_MOVIE (movie)) &&
+ (swfdec_movie_get_version (movie) > 5 || !SWFDEC_IS_TEXT_FIELD_MOVIE (movie));
+}
/* FIXME: This function can definitely be implemented easier */
SwfdecMovie *
diff --git a/swfdec/swfdec_movie.h b/swfdec/swfdec_movie.h
index 9e47478..512abf0 100644
--- a/swfdec/swfdec_movie.h
+++ b/swfdec/swfdec_movie.h
@@ -282,6 +282,7 @@ char * swfdec_movie_get_path (SwfdecMovie * movie,
void swfdec_movie_render (SwfdecMovie * movie,
cairo_t * cr,
const SwfdecColorTransform *trans);
+gboolean swfdec_movie_is_scriptable (SwfdecMovie * movie);
SwfdecMovie * swfdec_movie_resolve (SwfdecMovie * movie);
guint swfdec_movie_get_version (SwfdecMovie * movie);
commit 0c99a99379c811d4ae64284261ecf9756da3edf8
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 20:45:54 2008 +0200
make sure we use opaque colors for opaque BitmapData objects
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index 0e59f92..ab96a17 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -426,7 +426,7 @@ swfdec_bitmap_data_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
SwfdecBitmapData *bitmap;
int w, h;
gboolean transparent;
- int color;
+ guint color;
if (!swfdec_as_context_is_constructing (cx))
return;
@@ -446,7 +446,7 @@ swfdec_bitmap_data_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
transparent ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, w, h);
if (color) {
cairo_t *cr = cairo_create (bitmap->surface);
- swfdec_color_set_source (cr, color);
+ swfdec_color_set_source (cr, transparent ? color : SWFDEC_COLOR_OPAQUE (color));
cairo_paint (cr);
cairo_destroy (cr);
}
commit b286c4f0f8ce71244ac0ca2cab40eef8247772ee
Author: Benjamin Otte <otte at gnome.org>
Date: Thu Jul 24 18:36:13 2008 +0200
emit an "invalidate" signal when the contents change
diff --git a/swfdec/swfdec_bitmap_data.c b/swfdec/swfdec_bitmap_data.c
index c5f7b3e..0e59f92 100644
--- a/swfdec/swfdec_bitmap_data.c
+++ b/swfdec/swfdec_bitmap_data.c
@@ -29,18 +29,39 @@
#include "swfdec_as_strings.h"
#include "swfdec_color.h"
#include "swfdec_debug.h"
+#include "swfdec_rectangle.h"
+enum {
+ INVALIDATE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (SwfdecBitmapData, swfdec_bitmap_data, SWFDEC_TYPE_AS_OBJECT)
static void
+swfdec_bitmap_data_invalidate (SwfdecBitmapData *bitmap, guint x, guint y, guint w, guint h)
+{
+ SwfdecRectangle rect = { x, y, w, h };
+
+ g_return_if_fail (w > 0);
+ g_return_if_fail (h > 0);
+
+ g_signal_emit (bitmap, signals[INVALIDATE], 0, &rect);
+}
+
+static void
swfdec_bitmap_data_clear (SwfdecBitmapData *bitmap)
{
+ int w, h;
+
if (bitmap->surface == NULL)
return;
- swfdec_as_context_unuse_mem (swfdec_gc_object_get_context (bitmap), 4 *
- cairo_image_surface_get_width (bitmap->surface) *
- cairo_image_surface_get_height (bitmap->surface));
+ w = cairo_image_surface_get_width (bitmap->surface);
+ h = cairo_image_surface_get_height (bitmap->surface);
+ swfdec_bitmap_data_invalidate (bitmap, 0, 0, w, h);
+ swfdec_as_context_unuse_mem (swfdec_gc_object_get_context (bitmap), 4 * w * h);
cairo_surface_destroy (bitmap->surface);
bitmap->surface = NULL;
}
@@ -61,6 +82,10 @@ swfdec_bitmap_data_class_init (SwfdecBitmapDataClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = swfdec_bitmap_data_dispose;
+
+ signals[INVALIDATE] = g_signal_new ("invalidate", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1, SWFDEC_TYPE_RECTANGLE);
}
static void
More information about the Swfdec-commits
mailing list