mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-28 20:53:54 +02:00
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>
This commit is contained in:
parent
f29cdbe1b5
commit
da0684820a
@ -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;
|
||||
|
@ -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]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user