summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-09-12 21:39:54 +0000
committerMåns Rullgård <mans@mansr.com>2010-09-12 21:39:54 +0000
commit9525243f59f0a13e099612b66f7ba5d5d5293c70 (patch)
treece5e22b8c8b30b51bc82b92d188f05d49947c006 /libavutil
parent4b9ac6dedcbee4d059c04363fafbaad3586c1053 (diff)
pixdesc: use 8-bit accesses when possible in av_read/write_image_line()
This fixes out of bounds accesses for big endian formats and should be a little faster. Originally committed as revision 25110 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/pixdesc.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 98f5a9b1c6..6d618f3302 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -53,9 +53,15 @@ 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;
+ int is_8bit = 0;
+ if (shift + depth <= 8) {
+ p += !!(flags & PIX_FMT_BE);
+ is_8bit = 1;
+ }
while(w--){
- int val = flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
+ int val = is_8bit ? *p :
+ flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
val = (val>>shift) & mask;
if(read_pal_component)
val= data[1][4*val + c];
@@ -89,6 +95,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);
@@ -99,6 +112,7 @@ void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesi
}
p+= step;
}
+ }
}
}