[FFmpeg-devel] [PATCH] pixdesc: use 8-bit accesses when possible in av_read/write_image_line()

Mans Rullgard mans
Sun Sep 12 17:59:40 CEST 2010


This fixes out of bounds accesses for big endian formats and should be
a little faster.
---
 libavutil/pixdesc.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index e2bc649..41bf717 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -54,6 +54,17 @@ void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesiz
     } else {
         const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
 
+        if (shift + depth <= 8) {
+            p += !!(flags & PIX_FMT_BE);
+            while(w--) {
+                int val = *p;
+                val = (val>>shift) & mask;
+                if(read_pal_component)
+                    val= data[1][4*val + c];
+                p+= step;
+                *dst++= val;
+            }
+        } else {
         while(w--){
             int val;
             if(flags & PIX_FMT_BE) val= AV_RB16(p);
@@ -64,6 +75,7 @@ void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesiz
             p+= step;
             *dst++= val;
         }
+        }
     }
 }
 
@@ -91,6 +103,13 @@ void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesi
         int shift = comp.shift;
         uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
 
+        if (shift + depth <= 8) {
+            p += !!(flags & PIX_FMT_BE);
+            while (w--) {
+                *p |= (*src++<<shift);
+                p+= step;
+            }
+        } else {
         while (w--) {
             if (flags & PIX_FMT_BE) {
                 uint16_t val = AV_RB16(p) | (*src++<<shift);
@@ -101,6 +120,7 @@ void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesi
             }
             p+= step;
         }
+        }
     }
 }
 
-- 
1.7.2.2




More information about the ffmpeg-devel mailing list