Browse code

Merge remote branch 'qatar/master'

* qatar/master:
swscale: properly inline bits/endianness in yuv2yuvX16inC().
(We didnt pull the bug) swscale: fix clipping of 9/10bit YUV420P.
Add av_clip_uintp2() function
(our patch / duplicate) dfa: fix buffer overflow checks to avoid integer overflows.
(our patch / duplicate) movenc: always write esds descriptor length using 4 bytes.
(our patch / duplicate) ffmpeg: use parse_number_and_die() when it makes sense
(No thanks) ffmpeg: get rid of the 'q' key schizofrenia

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/05/14 09:19:23
Showing 3 changed files
... ...
@@ -1329,9 +1329,7 @@ static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *m
1329 1329
         filter_level += s->lf_delta.mode[mb->mode];
1330 1330
     }
1331 1331
 
1332
-/* Like av_clip for inputs 0 and max, where max is equal to (2^n-1) */
1333
-#define POW2CLIP(x,max) (((x) & ~max) ? (-(x))>>31 & max : (x));
1334
-    filter_level = POW2CLIP(filter_level, 63);
1332
+    filter_level = av_clip_uintp2(filter_level, 6);
1335 1333
 
1336 1334
     interior_limit = filter_level;
1337 1335
     if (s->filter.sharpness) {
... ...
@@ -172,6 +172,18 @@ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
172 172
 }
173 173
 
174 174
 /**
175
+ * Clip a signed integer to an unsigned power of two range.
176
+ * @param  a value to clip
177
+ * @param  p bit position to clip at
178
+ * @return clipped value
179
+ */
180
+static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
181
+{
182
+    if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1);
183
+    else                   return  a;
184
+}
185
+
186
+/**
175 187
  * Clip a float value into the amin-amax range.
176 188
  * @param a value to clip
177 189
  * @param amin minimum value of the clip range
... ...
@@ -364,6 +376,9 @@ static av_always_inline av_const int av_popcount_c(uint32_t x)
364 364
 #ifndef av_clipl_int32
365 365
 #   define av_clipl_int32   av_clipl_int32_c
366 366
 #endif
367
+#ifndef av_clip_uintp2
368
+#   define av_clip_uintp2   av_clip_uintp2_c
369
+#endif
367 370
 #ifndef av_clipf
368 371
 #   define av_clipf         av_clipf_c
369 372
 #endif
... ...
@@ -367,6 +367,20 @@ static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, co
367 367
     //FIXME Optimize (just quickly written not optimized..)
368 368
     int i;
369 369
 
370
+#define output_pixel(pos, val) \
371
+    if (big_endian) { \
372
+        if (output_bits == 16) { \
373
+            AV_WB16(pos, av_clip_uint16(val >> shift)); \
374
+        } else { \
375
+            AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \
376
+        } \
377
+    } else { \
378
+        if (output_bits == 16) { \
379
+            AV_WL16(pos, av_clip_uint16(val >> shift)); \
380
+        } else { \
381
+            AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \
382
+        } \
383
+    }
370 384
     for (i = 0; i < dstW; i++) {
371 385
         int val = 1 << 10;
372 386
         int j;
... ...
@@ -374,11 +388,7 @@ static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, co
374 374
         for (j = 0; j < lumFilterSize; j++)
375 375
             val += lumSrc[j][i] * lumFilter[j];
376 376
 
377
-        if (big_endian) {
378
-            AV_WB16(&dest[i], av_clip_uint16(val >> 11));
379
-        } else {
380
-            AV_WL16(&dest[i], av_clip_uint16(val >> 11));
381
-        }
377
+        output_pixel(&dest[i], val);
382 378
     }
383 379
 
384 380
     if (uDest) {
... ...
@@ -392,13 +402,8 @@ static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, co
392 392
                 v += chrSrc[j][i + VOFW] * chrFilter[j];
393 393
             }
394 394
 
395
-            if (big_endian) {
396
-                AV_WB16(&uDest[i], av_clip_uint16(u >> 11));
397
-                AV_WB16(&vDest[i], av_clip_uint16(v >> 11));
398
-            } else {
399
-                AV_WL16(&uDest[i], av_clip_uint16(u >> 11));
400
-                AV_WL16(&vDest[i], av_clip_uint16(v >> 11));
401
-            }
395
+            output_pixel(&uDest[i], u);
396
+            output_pixel(&vDest[i], v);
402 397
         }
403 398
     }
404 399
 
... ...
@@ -410,11 +415,7 @@ static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, co
410 410
             for (j = 0; j < lumFilterSize; j++)
411 411
                 val += alpSrc[j][i] * lumFilter[j];
412 412
 
413
-            if (big_endian) {
414
-                AV_WB16(&aDest[i], av_clip_uint16(val >> 11));
415
-            } else {
416
-                AV_WL16(&aDest[i], av_clip_uint16(val >> 11));
417
-            }
413
+            output_pixel(&aDest[i], val);
418 414
         }
419 415
     }
420 416
 }