[gst-cvs] gst-plugins-good: videobox: Correctly clamp frame/background alphas to [0, 255] before writing them

Sebastian Dröge slomo at kemper.freedesktop.org
Mon Apr 12 02:27:44 PDT 2010


Module: gst-plugins-good
Branch: master
Commit: 9da4f2906f6e95e34e8929c8acc04098d1e3d3fa
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-good/commit/?id=9da4f2906f6e95e34e8929c8acc04098d1e3d3fa

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Mon Apr 12 11:25:59 2010 +0200

videobox: Correctly clamp frame/background alphas to [0,255] before writing them

---

 gst/videobox/gstvideobox.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gst/videobox/gstvideobox.c b/gst/videobox/gstvideobox.c
index 84839bb..291fe5a 100644
--- a/gst/videobox/gstvideobox.c
+++ b/gst/videobox/gstvideobox.c
@@ -135,6 +135,8 @@ fill_ayuv (GstVideoBoxFill fill_type, guint b_alpha, GstVideoFormat format,
 {
   guint32 empty_pixel;
 
+  b_alpha = CLAMP (b_alpha, 0, 255);
+
   if (sdtv)
     empty_pixel = GUINT32_FROM_BE ((b_alpha << 24) |
         (yuv_sdtv_colors_Y[fill_type] << 16) |
@@ -602,6 +604,9 @@ copy_i420_ayuv (guint i_alpha, GstVideoFormat dest_format, guint8 * dest,
   hY = h;
   hUV = (h + 1) / 2;
 
+
+  i_alpha = CLAMP (i_alpha, 0, 255);
+
   if (src_sdtv != dest_sdtv) {
     gint matrix[12];
     gint y1, y2, y3, y4;
@@ -788,6 +793,8 @@ fill_rgb32 (GstVideoBoxFill fill_type, guint b_alpha, GstVideoFormat format,
 
   _argb_order (format, p, &alpha);
 
+  b_alpha = CLAMP (b_alpha, 0, 255);
+
   empty_pixel = GUINT32_FROM_BE ((b_alpha << (p[0] * 8)) |
       (rgb_colors_R[fill_type] << (p[1] * 8)) |
       (rgb_colors_G[fill_type] << (p[2] * 8)) |
@@ -860,9 +867,11 @@ copy_rgb32 (guint i_alpha, GstVideoFormat dest_format, guint8 * dest,
     }
   } else if (out_alpha && !packed_in) {
     w *= 4;
+    i_alpha = CLAMP (i_alpha, 0, 255);
+
     for (i = 0; i < h; i++) {
       for (j = 0; j < w; j += 4) {
-        dest[j + p_out[0]] = i_alpha & 0xff;
+        dest[j + p_out[0]] = i_alpha;
         dest[j + p_out[1]] = src[j + p_in[1]];
         dest[j + p_out[2]] = src[j + p_in[2]];
         dest[j + p_out[3]] = src[j + p_in[3]];
@@ -871,9 +880,11 @@ copy_rgb32 (guint i_alpha, GstVideoFormat dest_format, guint8 * dest,
       src += src_stride;
     }
   } else if (out_alpha && packed_in) {
+    i_alpha = CLAMP (i_alpha, 0, 255);
+
     for (i = 0; i < h; i++) {
       for (j = 0; j < w; j++) {
-        dest[4 * j + p_out[0]] = i_alpha & 0xff;
+        dest[4 * j + p_out[0]] = i_alpha;
         dest[4 * j + p_out[1]] = src[in_bpp * j + p_in[1]];
         dest[4 * j + p_out[2]] = src[in_bpp * j + p_in[2]];
         dest[4 * j + p_out[3]] = src[in_bpp * j + p_in[3]];
@@ -960,9 +971,11 @@ copy_rgb32_ayuv (guint i_alpha, GstVideoFormat dest_format, guint8 * dest,
     }
   } else if (!packed_in) {
     w *= 4;
+    i_alpha = CLAMP (i_alpha, 0, 255);
+
     for (i = 0; i < h; i++) {
       for (j = 0; j < w; j += 4) {
-        a = i_alpha & 0xff;
+        a = i_alpha;
         r = src[j + p_in[1]];
         g = src[j + p_in[2]];
         b = src[j + p_in[3]];
@@ -980,9 +993,11 @@ copy_rgb32_ayuv (guint i_alpha, GstVideoFormat dest_format, guint8 * dest,
       src += src_stride;
     }
   } else {
+    i_alpha = CLAMP (i_alpha, 0, 255);
+
     for (i = 0; i < h; i++) {
       for (j = 0; j < w; j++) {
-        a = i_alpha & 0xff;
+        a = i_alpha;
         r = src[in_bpp * j + p_in[1]];
         g = src[in_bpp * j + p_in[2]];
         b = src[in_bpp * j + p_in[3]];





More information about the Gstreamer-commits mailing list