From 2d101863dc6975f05a7ce95adb58da087f248cf7 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Sat, 28 May 2011 14:36:51 +0300 Subject: [PATCH] basescope: add more shading effects https://bugzilla.gnome.org/show_bug.cgi?id=651536 --- gst/scopes/gstbasescope.c | 159 ++++++++++++++++++++++++++++++++++++++ gst/scopes/gstbasescope.h | 6 +- 2 files changed, 164 insertions(+), 1 deletion(-) diff --git a/gst/scopes/gstbasescope.c b/gst/scopes/gstbasescope.c index b1315c6b87..30d5bda169 100644 --- a/gst/scopes/gstbasescope.c +++ b/gst/scopes/gstbasescope.c @@ -75,6 +75,11 @@ gst_base_scope_shader_get_type (void) {GST_BASE_SCOPE_SHADER_FADE, "Fade", "fade"}, {GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_UP, "Fade and move up", "fade-and-move-up"}, + {GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_DOWN, "Fade and move down", + "fade-and-move-down"}, + {GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_HORIZ_OUT, + "Fade and move horizontaly out", + "fade-and-move-horiz-out"}, {0, NULL, NULL}, }; @@ -168,6 +173,154 @@ shader_fade_and_move_up (GstBaseScope * scope, const guint8 * s, guint8 * d) #endif } +static void +shader_fade_and_move_down (GstBaseScope * scope, const guint8 * s, guint8 * d) +{ + guint i, j, bpf = scope->bpf; + guint bpl = 4 * scope->width; + guint r = (scope->shade_amount >> 16) & 0xff; + guint g = (scope->shade_amount >> 8) & 0xff; + guint b = (scope->shade_amount >> 0) & 0xff; + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + for (i = 0; i < bpl;) { + d[i] = (s[i] > b) ? s[i] - b : 0; + i++; + d[i] = (s[i] > g) ? s[i] - g : 0; + i++; + d[i] = (s[i] > r) ? s[i] - r : 0; + i++; + d[i++] = 0; + } + for (j = bpl, i = 0; j < bpf;) { + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = 0; + i++; + } +#else + for (i = 0; i < bpl;) { + d[i++] = 0; + d[i] = (s[i] > r) ? s[i] - r : 0; + i++; + d[i] = (s[i] > g) ? s[i] - g : 0; + i++; + d[i] = (s[i] > b) ? s[i] - b : 0; + i++; + } + for (j = bpl, i = 0; j < bpf;) { + d[j++] = 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + } +#endif +} + +static void +shader_fade_and_move_horiz_out (GstBaseScope * scope, const guint8 * s, + guint8 * d) +{ + guint i, j, bpf = scope->bpf / 2; + guint bpl = 4 * scope->width; + guint r = (scope->shade_amount >> 16) & 0xff; + guint g = (scope->shade_amount >> 8) & 0xff; + guint b = (scope->shade_amount >> 0) & 0xff; + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + /* middle up */ + for (j = 0, i = bpl; i < bpf;) { + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = 0; + i++; + } + for (i = 0; i < bpl; i += 4) { + d[j] = (s[j] > b) ? s[j] - b : 0; + j++; + d[j] = (s[j] > g) ? s[j] - g : 0; + j++; + d[j] = (s[j] > r) ? s[j] - r : 0; + j++; + d[j++] = 0; + } + /* middle down */ + for (i = bpf; i < bpf + bpl;) { + d[i] = (s[i] > b) ? s[i] - b : 0; + i++; + d[i] = (s[i] > g) ? s[i] - g : 0; + i++; + d[i] = (s[i] > r) ? s[i] - r : 0; + i++; + d[i++] = 0; + } + for (j = bpf + bpl, i = bpf; j < bpf + bpf;) { + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = 0; + i++; + } +#else + /* middle up */ + for (j = 0, i = bpl; i < bpf;) { + d[j++] = 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + } + for (i = 0; i < bpl; i += 4) { + d[j++] = 0; + d[j] = (s[j] > r) ? s[j] - r : 0; + j++; + d[j] = (s[j] > g) ? s[j] - g : 0; + j++; + d[j] = (s[j] > b) ? s[j] - b : 0; + j++; + } + /* middle down */ + for (i = bpf; i < bpf + bpl;) { + d[i++] = 0; + d[i] = (s[i] > r) ? s[i] - r : 0; + i++; + d[i] = (s[i] > g) ? s[i] - g : 0; + i++; + d[i] = (s[i] > b) ? s[i] - b : 0; + i++; + } + for (j = bpf + bpl, i = bpf; j < bpf + bpf;) { + d[j++] = 0; + i++; + d[j++] = (s[i] > r) ? s[i] - r : 0; + i++; + d[j++] = (s[i] > g) ? s[i] - g : 0; + i++; + d[j++] = (s[i] > b) ? s[i] - b : 0; + i++; + } +#endif +} + + static void gst_base_scope_change_shader (GstBaseScope * scope) { @@ -181,6 +334,12 @@ gst_base_scope_change_shader (GstBaseScope * scope) case GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_UP: scope->shader = shader_fade_and_move_up; break; + case GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_DOWN: + scope->shader = shader_fade_and_move_down; + break; + case GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_HORIZ_OUT: + scope->shader = shader_fade_and_move_horiz_out; + break; default: GST_ERROR ("invalid shader function"); scope->shader = NULL; diff --git a/gst/scopes/gstbasescope.h b/gst/scopes/gstbasescope.h index 251f849162..b37c361840 100644 --- a/gst/scopes/gstbasescope.h +++ b/gst/scopes/gstbasescope.h @@ -44,13 +44,17 @@ typedef void (*GstBaseScopeShaderFunc)(GstBaseScope *scope, const guint8 *s, gui * @GST_BASE_SCOPE_SHADER_NONE: no shading * @GST_BASE_SCOPE_SHADER_FADE: plain fading * @GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_UP: fade and move up + * @GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_DOWN: fade and move down + * @GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_HORIZ_OUT: fade and move horizontaly out * * Different types of supported background shading functions. */ typedef enum { GST_BASE_SCOPE_SHADER_NONE, GST_BASE_SCOPE_SHADER_FADE, - GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_UP + GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_UP, + GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_DOWN, + GST_BASE_SCOPE_SHADER_FADE_AND_MOVE_HORIZ_OUT } GstBaseScopeShader; struct _GstBaseScope -- 2.34.1