[FFmpeg-devel] [PATCH 3/5] sws/output: avoid shifts for alpha

Michael Niedermayer michaelni at gmx.at
Sun Apr 14 12:17:20 CEST 2013


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libswscale/output.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 85f93fa..8429efc 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -1021,17 +1021,17 @@ static av_always_inline void
 yuv2rgb_write2(uint8_t *_dest, int i, int Y1, int Y2,
               unsigned A1, unsigned A2,
               int R, int G, int B, int y,
-              enum AVPixelFormat target, int hasAlpha, int isBGR)
+              enum AVPixelFormat target, int hasAlpha, int isBGR, int ABITS)
 {
     //XXX !target is always the RGB variant even for BGR
     if (isBGR && target != AV_PIX_FMT_RGB8)
         FFSWAP(int, R, B);
     if (target == AV_PIX_FMT_ARGB || target == AV_PIX_FMT_ABGR) {
-        _dest[i * 8 + 0] = av_clip_uintp2(A1  , 30) >> 22;
+        _dest[i * 8 + 0] = av_clip_uintp2(A1  , ABITS) >> (ABITS-8);
         _dest[i * 8 + 1] = av_clip_uintp2(R+Y1, 30) >> 22;
         _dest[i * 8 + 2] = av_clip_uintp2(G+Y1, 30) >> 22;
         _dest[i * 8 + 3] = av_clip_uintp2(B+Y1, 30) >> 22;
-        _dest[i * 8 + 4] = av_clip_uintp2(A2  , 30) >> 22;
+        _dest[i * 8 + 4] = av_clip_uintp2(A2  , ABITS) >> (ABITS-8);
         _dest[i * 8 + 5] = av_clip_uintp2(R+Y2, 30) >> 22;
         _dest[i * 8 + 6] = av_clip_uintp2(G+Y2, 30) >> 22;
         _dest[i * 8 + 7] = av_clip_uintp2(B+Y2, 30) >> 22;
@@ -1039,11 +1039,11 @@ yuv2rgb_write2(uint8_t *_dest, int i, int Y1, int Y2,
         _dest[i * 8 + 0] = av_clip_uintp2(R+Y1, 30) >> 22;
         _dest[i * 8 + 1] = av_clip_uintp2(G+Y1, 30) >> 22;
         _dest[i * 8 + 2] = av_clip_uintp2(B+Y1, 30) >> 22;
-        _dest[i * 8 + 3] = av_clip_uintp2(A1  , 30) >> 22;
+        _dest[i * 8 + 3] = av_clip_uintp2(A1  , ABITS) >> (ABITS-8);
         _dest[i * 8 + 4] = av_clip_uintp2(R+Y2, 30) >> 22;
         _dest[i * 8 + 5] = av_clip_uintp2(G+Y2, 30) >> 22;
         _dest[i * 8 + 6] = av_clip_uintp2(B+Y2, 30) >> 22;
-        _dest[i * 8 + 7] = av_clip_uintp2(A2  , 30) >> 22;
+        _dest[i * 8 + 7] = av_clip_uintp2(A2  , ABITS) >> (ABITS-8);
     } else if (target == AV_PIX_FMT_RGB24 || target == AV_PIX_FMT_BGR24) {
         _dest[i * 6 + 0] = av_clip_uintp2(R+Y1, 30) >> 22;
         _dest[i * 6 + 1] = av_clip_uintp2(G+Y1, 30) >> 22;
@@ -1178,8 +1178,6 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
                 A1 += alpSrc[j][i * 2    ] * lumFilter[j];
                 A2 += alpSrc[j][i * 2 + 1] * lumFilter[j];
             }
-            A1 <<= 3;
-            A2 <<= 3;
         }
 
         Y1 -= c->yuv2rgb_y_offset;
@@ -1194,7 +1192,7 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         yuv2rgb_write2(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0,
-                       R, G, B, y, target, hasAlpha, isBGR);
+                       R, G, B, y, target, hasAlpha, isBGR, 27);
     }
     if ((!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list