diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-20 03:50:43 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-20 04:06:04 +0100 |
commit | da0684820a58ce42a5a2953cbce417e06a54be8f (patch) | |
tree | c2d468b28cc427bf5f37ab4074d028494ee4cdce | |
parent | f29cdbe1b59a0d997733b507041e15ec68cef00c (diff) | |
download | ffmpeg-da0684820a58ce42a5a2953cbce417e06a54be8f.tar.gz |
avcodec/dsputil/huffyuv: move diff int16 and add int16 to dsputil
This also fixes masking the bits
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/dsputil.c | 41 | ||||
-rw-r--r-- | libavcodec/dsputil.h | 2 | ||||
-rw-r--r-- | libavcodec/huffyuvdec.c | 15 | ||||
-rw-r--r-- | libavcodec/huffyuvenc.c | 11 |
4 files changed, 45 insertions, 24 deletions
diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index 0e9e34798e..8533e5382c 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -1888,6 +1888,45 @@ static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, dst[i+0] = src1[i+0]-src2[i+0]; } +static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){ + long i; + unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL; + unsigned long pw_msb = pw_lsb + 0x0001000100010001ULL; + for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) { + long a = *(long*)(src+i); + long b = *(long*)(dst+i); + *(long*)(dst+i) = ((a&pw_lsb) + (b&pw_lsb)) ^ ((a^b)&pw_msb); + } + for(; i<w; i++) + dst[i] = (dst[i] + src[i]) & mask; +} + +static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){ + long i; +#if !HAVE_FAST_UNALIGNED + if((long)src2 & (sizeof(long)-1)){ + for(i=0; i+7<w; i+=8){ + dst[i+0] = (src1[i+0]-src2[i+0]) & mask; + dst[i+1] = (src1[i+1]-src2[i+1]) & mask; + dst[i+2] = (src1[i+2]-src2[i+2]) & mask; + dst[i+3] = (src1[i+3]-src2[i+3]) & mask; + } + }else +#endif + { + unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL; + unsigned long pw_msb = pw_lsb + 0x0001000100010001ULL; + + for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) { + long a = *(long*)(src1+i); + long b = *(long*)(src2+i); + *(long*)(dst+i) = ((a|pw_msb) - (b&pw_lsb)) ^ ((a^b^pw_msb)&pw_msb); + } + } + for (; i<w; i++) + dst[i] = (src1[i] - src2[i]) & mask; +} + static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){ int i; uint8_t l, lt; @@ -2773,6 +2812,8 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) c->add_bytes= add_bytes_c; c->diff_bytes= diff_bytes_c; + c->add_int16 = add_int16_c; + c->diff_int16= diff_int16_c; c->add_hfyu_median_prediction= add_hfyu_median_prediction_c; c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c; c->add_hfyu_left_prediction = add_hfyu_left_prediction_c; diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index 0897c560b4..7ad96f6cd7 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -193,6 +193,8 @@ typedef struct DSPContext { /* huffyuv specific */ void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); void (*diff_bytes)(uint8_t *dst/*align 16*/, const uint8_t *src1/*align 16*/, const uint8_t *src2/*align 1*/,int w); + void (*add_int16)(uint16_t *dst/*align 16*/, const uint16_t *src/*align 16*/, unsigned mask, int w); + void (*diff_int16)(uint16_t *dst/*align 16*/, const uint16_t *src1/*align 16*/, const uint16_t *src2/*align 1*/, unsigned mask, int w); /** * subtract huffyuv's variant of median prediction * note, this might read from src1[-1], src2[-1] diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index ced22f620a..aafa9e4abb 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -708,20 +708,7 @@ static void add_bytes(HYuvContext *s, uint8_t *dst, uint8_t *src, int w) if (s->bps <= 8) { s->dsp.add_bytes(dst, src, w); } else { - //FIXME optimize - const uint16_t *src16 = (const uint16_t *)src; - uint16_t *dst16 = ( uint16_t *)dst; - long i; - unsigned long msb = 0x1000100010001ULL << (s->bps-1); - unsigned long lsb = msb - 0x1000100010001ULL; - unsigned long mask = lsb + msb; - for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) { - long a = *(long*)(src16+i); - long b = *(long*)(dst16+i); - *(long*)(dst16+i) = ((a&lsb) + (b&lsb)) ^ ((a^b)&msb); - } - for(; i<w; i++) - dst16[i] = (dst16[i] + src16[i]) & mask; + s->dsp.add_int16((uint16_t*)dst, (const uint16_t*)src, s->n - 1, w); } } diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index 5fb7d0cea7..2bc95b59e8 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -38,19 +38,10 @@ static inline void diff_bytes(HYuvContext *s, uint8_t *dst, const uint8_t *src0, const uint8_t *src1, int w) { - int i; if (s->bps <= 8) { s->dsp.diff_bytes(dst, src0, src1, w); } else { - const uint16_t *src016 = (const uint16_t *)src0; - const uint16_t *src116 = (const uint16_t *)src1; - uint16_t *dst16 = ( uint16_t *)dst; - - for (i = 0; i < w; i++) { - dst16[i] = src016[i] - src116[i]; - } - - //FIXME optimize + s->dsp.diff_int16((uint16_t *)dst, (const uint16_t *)src0, (const uint16_t *)src1, s->n - 1, w); } } |