summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-04-07 23:06:34 +0200
committerAlexander Larsson <alexl@redhat.com>2010-04-07 23:06:34 +0200
commit982dab2099434ca9cb00e478cde5569da352719e (patch)
treea1aafa82bd390ba2be2e71b824121d47a27fd8d8
parentde25b3c8ef93a2502d8b3d40282b0bc63e0b1bfa (diff)
Add alpha blending
-rw-r--r--client.html55
-rw-r--r--daemon.c46
2 files changed, 100 insertions, 1 deletions
diff --git a/client.html b/client.html
index 8ec0337..7211bbe 100644
--- a/client.html
+++ b/client.html
@@ -17,6 +17,13 @@ var base64_val = [
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255
]
+function base64_8(str, index) {
+ var v =
+ (base64_val[str.charCodeAt(index)]) +
+ (base64_val[str.charCodeAt(index+1)] << 6);
+ return v;
+}
+
function base64_16(str, index) {
var v =
(base64_val[str.charCodeAt(index)]) +
@@ -156,6 +163,54 @@ function handleLoad(event)
break;
+ /* blend from surface */
+ case 'e':
+ source_id = base64_16(cmd, i);
+ i = i + 3;
+ sx = base64_16(cmd, i);
+ i = i + 3;
+ sy = base64_16(cmd, i);
+ i = i + 3;
+ w = base64_16(cmd, i);
+ i = i + 3;
+ h = base64_16(cmd, i);
+ i = i + 3;
+ dx = base64_16(cmd, i);
+ i = i + 3;
+ dy = base64_16(cmd, i);
+ i = i + 3;
+ current_context.globalCompositeOperation = "source-over"
+ current_context.drawImage(surfaces[source_id], sx, sy, w, h, dx, dy, w, h);
+ current_context.globalCompositeOperation = "copy"
+
+ break;
+
+ /* blend from surface w/ overall alpha */
+ case 'E':
+ source_id = base64_16(cmd, i);
+ i = i + 3;
+ sx = base64_16(cmd, i);
+ i = i + 3;
+ sy = base64_16(cmd, i);
+ i = i + 3;
+ w = base64_16(cmd, i);
+ i = i + 3;
+ h = base64_16(cmd, i);
+ i = i + 3;
+ dx = base64_16(cmd, i);
+ i = i + 3;
+ dy = base64_16(cmd, i);
+ i = i + 3;
+ alpha = base64_8(cmd, i);
+ i = i + 2;
+ current_context.globalAlpha = alpha / 255.0;
+ current_context.globalCompositeOperation = "source-over"
+ current_context.drawImage(surfaces[source_id], sx, sy, w, h, dx, dy, w, h);
+ current_context.globalAlpha = 1.0;
+ current_context.globalCompositeOperation = "copy"
+
+ break;
+
/* fill rect */
case 'r':
x = base64_16(cmd, i);
diff --git a/daemon.c b/daemon.c
index b4e57fa..1b03212 100644
--- a/daemon.c
+++ b/daemon.c
@@ -17,6 +17,13 @@ static const char base64_alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static void
+base64_uint8 (guint8 v, char *c)
+{
+ c[0] = base64_alphabet[(v >> 0) & 0x3f];
+ c[1] = base64_alphabet[(v >> 6) & 0x3];
+}
+
+static void
base64_uint16 (guint32 v, char *c)
{
c[0] = base64_alphabet[(v >> 0) & 0x3f];
@@ -101,6 +108,43 @@ send_copyrect (GOutputStream *out, int sx, int sy, int w, int h, int dx, int dy
}
static void
+send_blend (GOutputStream *out, int source_surface, int sx, int sy, int w, int h, int dx, int dy)
+{
+ char buf[22];
+
+ buf[0] = 'e';
+ base64_uint16(source_surface, &buf[1]);
+ base64_uint16(sx, &buf[4]);
+ base64_uint16(sy, &buf[7]);
+ base64_uint16(w, &buf[10]);
+ base64_uint16(h, &buf[13]);
+ base64_uint16(dx, &buf[16]);
+ base64_uint16(dy, &buf[19]);
+
+ g_output_stream_write_all (out, buf, 22,
+ NULL, NULL, NULL);
+}
+
+static void
+send_blend_alpha (GOutputStream *out, int source_surface, int sx, int sy, int w, int h, int dx, int dy, guint8 overall_alpha)
+{
+ char buf[24];
+
+ buf[0] = 'E';
+ base64_uint16(source_surface, &buf[1]);
+ base64_uint16(sx, &buf[4]);
+ base64_uint16(sy, &buf[7]);
+ base64_uint16(w, &buf[10]);
+ base64_uint16(h, &buf[13]);
+ base64_uint16(dx, &buf[16]);
+ base64_uint16(dy, &buf[19]);
+ base64_uint8(dy, &buf[22]);
+
+ g_output_stream_write_all (out, buf, 24,
+ NULL, NULL, NULL);
+}
+
+static void
send_blit (GOutputStream *out, int source_surface, int sx, int sy, int w, int h, int dx, int dy)
{
char buf[22];
@@ -411,7 +455,7 @@ send_draw_ops (GOutputStream *out)
send_copyrect (cout, 15, 15, 800, 40, 20, 15);
- send_blit (cout, 1, 0, 0, 50, 50, 200, 200);
+ send_blend_alpha (cout, 1, 0, 0, 50, 50, 200 + i * 20, 200 - i * 30, 70);
send_image_rgb (cout, 30, 30,
2, 2, 2, pixel);