2002-06-14 01:14:56 +00:00
|
|
|
/*
|
2008-05-13 10:16:20 +00:00
|
|
|
* Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
|
|
|
#include "mpvcore/cpudetect.h"
|
2002-06-14 01:14:56 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2002-06-14 01:14:56 +00:00
|
|
|
#include "vf.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/memcpy_pic.h"
|
2010-04-20 04:33:00 +00:00
|
|
|
#include "libavutil/mem.h"
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
#define MAX_NOISE 4096
|
|
|
|
#define MAX_SHIFT 1024
|
|
|
|
#define MAX_RES (MAX_NOISE-MAX_SHIFT)
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift);
|
2002-08-11 09:46:50 +00:00
|
|
|
static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift);
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
static void (*lineNoise)(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift)= lineNoise_C;
|
2002-08-11 09:46:50 +00:00
|
|
|
static void (*lineNoiseAvg)(uint8_t *dst, uint8_t *src, int len, int8_t **shift)= lineNoiseAvg_C;
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
typedef struct FilterParam{
|
|
|
|
int strength;
|
|
|
|
int uniform;
|
|
|
|
int temporal;
|
2002-06-16 13:54:36 +00:00
|
|
|
int quality;
|
2002-08-11 09:46:50 +00:00
|
|
|
int averaged;
|
2002-08-13 17:53:32 +00:00
|
|
|
int pattern;
|
2002-08-11 09:46:50 +00:00
|
|
|
int shiftptr;
|
2002-06-14 01:14:56 +00:00
|
|
|
int8_t *noise;
|
2002-08-11 09:52:23 +00:00
|
|
|
int8_t *prev_shift[MAX_RES][3];
|
2002-06-14 01:14:56 +00:00
|
|
|
}FilterParam;
|
|
|
|
|
|
|
|
struct vf_priv_s {
|
|
|
|
FilterParam lumaParam;
|
|
|
|
FilterParam chromaParam;
|
2002-06-16 13:45:52 +00:00
|
|
|
unsigned int outfmt;
|
2002-06-14 01:14:56 +00:00
|
|
|
};
|
|
|
|
|
2006-04-03 06:25:30 +00:00
|
|
|
static int nonTempRandShift_init;
|
|
|
|
static int nonTempRandShift[MAX_RES];
|
2002-06-14 01:14:56 +00:00
|
|
|
|
2002-08-13 17:53:32 +00:00
|
|
|
static int patt[4] = {
|
|
|
|
-1,0,1,0
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0)))
|
2002-06-14 01:14:56 +00:00
|
|
|
static int8_t *initNoise(FilterParam *fp){
|
|
|
|
int strength= fp->strength;
|
|
|
|
int uniform= fp->uniform;
|
2002-08-11 09:46:50 +00:00
|
|
|
int averaged= fp->averaged;
|
2002-08-13 17:53:32 +00:00
|
|
|
int pattern= fp->pattern;
|
2010-04-20 04:33:00 +00:00
|
|
|
int8_t *noise= av_malloc(MAX_NOISE*sizeof(int8_t));
|
2002-08-11 09:46:50 +00:00
|
|
|
int i, j;
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
srand(123457);
|
|
|
|
|
2002-08-13 17:53:32 +00:00
|
|
|
for(i=0,j=0; i<MAX_NOISE; i++,j++)
|
2002-06-14 01:14:56 +00:00
|
|
|
{
|
2002-08-13 17:53:32 +00:00
|
|
|
if(uniform) {
|
|
|
|
if (averaged) {
|
|
|
|
if (pattern) {
|
|
|
|
noise[i]= (RAND_N(strength) - strength/2)/6
|
|
|
|
+patt[j%4]*strength*0.25/3;
|
|
|
|
} else {
|
|
|
|
noise[i]= (RAND_N(strength) - strength/2)/3;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (pattern) {
|
|
|
|
noise[i]= (RAND_N(strength) - strength/2)/2
|
|
|
|
+ patt[j%4]*strength*0.25;
|
|
|
|
} else {
|
|
|
|
noise[i]= RAND_N(strength) - strength/2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-06-14 01:14:56 +00:00
|
|
|
double x1, x2, w, y1;
|
|
|
|
do {
|
|
|
|
x1 = 2.0 * rand()/(float)RAND_MAX - 1.0;
|
|
|
|
x2 = 2.0 * rand()/(float)RAND_MAX - 1.0;
|
|
|
|
w = x1 * x1 + x2 * x2;
|
|
|
|
} while ( w >= 1.0 );
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
w = sqrt( (-2.0 * log( w ) ) / w );
|
|
|
|
y1= x1 * w;
|
2002-08-11 09:46:50 +00:00
|
|
|
y1*= strength / sqrt(3.0);
|
2002-08-13 17:53:32 +00:00
|
|
|
if (pattern) {
|
|
|
|
y1 /= 2;
|
|
|
|
y1 += patt[j%4]*strength*0.35;
|
|
|
|
}
|
2002-06-14 01:14:56 +00:00
|
|
|
if (y1<-128) y1=-128;
|
|
|
|
else if(y1> 127) y1= 127;
|
2002-08-11 09:46:50 +00:00
|
|
|
if (averaged) y1 /= 3.0;
|
2002-06-14 01:14:56 +00:00
|
|
|
noise[i]= (int)y1;
|
|
|
|
}
|
2002-08-13 17:53:32 +00:00
|
|
|
if (RAND_N(6) == 0) j--;
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-08-11 09:46:50 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_RES; i++)
|
|
|
|
for (j = 0; j < 3; j++)
|
2002-08-11 09:52:23 +00:00
|
|
|
fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1));
|
2002-06-14 01:14:56 +00:00
|
|
|
|
2006-04-03 06:25:30 +00:00
|
|
|
if(!nonTempRandShift_init){
|
2002-06-14 01:14:56 +00:00
|
|
|
for(i=0; i<MAX_RES; i++){
|
|
|
|
nonTempRandShift[i]= rand()&(MAX_SHIFT-1);
|
|
|
|
}
|
2006-04-03 06:25:30 +00:00
|
|
|
nonTempRandShift_init = 1;
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fp->noise= noise;
|
2002-08-11 09:46:50 +00:00
|
|
|
fp->shiftptr= 0;
|
2002-06-14 01:14:56 +00:00
|
|
|
return noise;
|
|
|
|
}
|
|
|
|
|
2002-08-11 09:46:50 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX
|
2002-06-14 01:14:56 +00:00
|
|
|
static inline void lineNoise_MMX(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
|
2009-03-27 20:34:55 +00:00
|
|
|
x86_reg mmx_len= len&(~7);
|
2002-06-14 01:14:56 +00:00
|
|
|
noise+=shift;
|
|
|
|
|
2008-10-16 18:59:27 +00:00
|
|
|
__asm__ volatile(
|
2004-10-21 11:55:20 +00:00
|
|
|
"mov %3, %%"REG_a" \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"pcmpeqb %%mm7, %%mm7 \n\t"
|
|
|
|
"psllw $15, %%mm7 \n\t"
|
|
|
|
"packsswb %%mm7, %%mm7 \n\t"
|
configure: remove check for .align semantics
The check determined whether the argument for .align is in bytes, or
log2(bytes). Apparently it's always in bytes for ELF i386 systems, and
this check is used for x86 inline assembler only. Even if this
assumption should be wrong, it likely won't cause much damage: the
existing code uses it only in the form ".align 4", which means in the
worst case it will try to align to 16 bytes, which doesn't cause any
problems (unless the object file format does not support such a high
alignment).
Update the filters that used this.
Quoting the GNU as manual:
For other systems, including ppc, i386 using a.out format, arm and
strongarm, it is the number of low-order zero bits the location counter
must have after advancement. For example `.align 3' advances the
location counter until it a multiple of 8. If the location counter is
already a multiple of 8, no change is needed.
2013-01-13 13:10:43 +00:00
|
|
|
".align 4 \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"1: \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movq (%0, %%"REG_a"), %%mm0 \n\t"
|
|
|
|
"movq (%1, %%"REG_a"), %%mm1 \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"pxor %%mm7, %%mm0 \n\t"
|
|
|
|
"paddsb %%mm1, %%mm0 \n\t"
|
|
|
|
"pxor %%mm7, %%mm0 \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movq %%mm0, (%2, %%"REG_a") \n\t"
|
|
|
|
"add $8, %%"REG_a" \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
" js 1b \n\t"
|
|
|
|
:: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
|
2004-10-21 11:55:20 +00:00
|
|
|
: "%"REG_a
|
2002-06-14 01:14:56 +00:00
|
|
|
);
|
|
|
|
if(mmx_len!=len)
|
|
|
|
lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//duplicate of previous except movntq
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX2
|
2002-06-14 01:14:56 +00:00
|
|
|
static inline void lineNoise_MMX2(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
|
2009-03-27 20:34:55 +00:00
|
|
|
x86_reg mmx_len= len&(~7);
|
2002-06-14 01:14:56 +00:00
|
|
|
noise+=shift;
|
|
|
|
|
2008-10-16 18:59:27 +00:00
|
|
|
__asm__ volatile(
|
2004-10-21 11:55:20 +00:00
|
|
|
"mov %3, %%"REG_a" \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"pcmpeqb %%mm7, %%mm7 \n\t"
|
|
|
|
"psllw $15, %%mm7 \n\t"
|
|
|
|
"packsswb %%mm7, %%mm7 \n\t"
|
configure: remove check for .align semantics
The check determined whether the argument for .align is in bytes, or
log2(bytes). Apparently it's always in bytes for ELF i386 systems, and
this check is used for x86 inline assembler only. Even if this
assumption should be wrong, it likely won't cause much damage: the
existing code uses it only in the form ".align 4", which means in the
worst case it will try to align to 16 bytes, which doesn't cause any
problems (unless the object file format does not support such a high
alignment).
Update the filters that used this.
Quoting the GNU as manual:
For other systems, including ppc, i386 using a.out format, arm and
strongarm, it is the number of low-order zero bits the location counter
must have after advancement. For example `.align 3' advances the
location counter until it a multiple of 8. If the location counter is
already a multiple of 8, no change is needed.
2013-01-13 13:10:43 +00:00
|
|
|
".align 4 \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"1: \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movq (%0, %%"REG_a"), %%mm0 \n\t"
|
|
|
|
"movq (%1, %%"REG_a"), %%mm1 \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
"pxor %%mm7, %%mm0 \n\t"
|
|
|
|
"paddsb %%mm1, %%mm0 \n\t"
|
|
|
|
"pxor %%mm7, %%mm0 \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movntq %%mm0, (%2, %%"REG_a") \n\t"
|
|
|
|
"add $8, %%"REG_a" \n\t"
|
2002-06-14 01:14:56 +00:00
|
|
|
" js 1b \n\t"
|
|
|
|
:: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
|
2004-10-21 11:55:20 +00:00
|
|
|
: "%"REG_a
|
2002-06-14 01:14:56 +00:00
|
|
|
);
|
|
|
|
if(mmx_len!=len)
|
|
|
|
lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){
|
|
|
|
int i;
|
|
|
|
noise+= shift;
|
|
|
|
for(i=0; i<len; i++)
|
|
|
|
{
|
|
|
|
int v= src[i]+ noise[i];
|
|
|
|
if(v>255) dst[i]=255; //FIXME optimize
|
|
|
|
else if(v<0) dst[i]=0;
|
|
|
|
else dst[i]=v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-11 09:46:50 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX
|
2002-08-11 10:52:22 +00:00
|
|
|
static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
|
2009-03-27 20:34:55 +00:00
|
|
|
x86_reg mmx_len= len&(~7);
|
2002-08-11 10:52:22 +00:00
|
|
|
|
2008-10-16 18:59:27 +00:00
|
|
|
__asm__ volatile(
|
2004-10-21 11:55:20 +00:00
|
|
|
"mov %5, %%"REG_a" \n\t"
|
configure: remove check for .align semantics
The check determined whether the argument for .align is in bytes, or
log2(bytes). Apparently it's always in bytes for ELF i386 systems, and
this check is used for x86 inline assembler only. Even if this
assumption should be wrong, it likely won't cause much damage: the
existing code uses it only in the form ".align 4", which means in the
worst case it will try to align to 16 bytes, which doesn't cause any
problems (unless the object file format does not support such a high
alignment).
Update the filters that used this.
Quoting the GNU as manual:
For other systems, including ppc, i386 using a.out format, arm and
strongarm, it is the number of low-order zero bits the location counter
must have after advancement. For example `.align 3' advances the
location counter until it a multiple of 8. If the location counter is
already a multiple of 8, no change is needed.
2013-01-13 13:10:43 +00:00
|
|
|
".align 4 \n\t"
|
2002-08-11 10:52:22 +00:00
|
|
|
"1: \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movq (%1, %%"REG_a"), %%mm1 \n\t"
|
|
|
|
"movq (%0, %%"REG_a"), %%mm0 \n\t"
|
|
|
|
"paddb (%2, %%"REG_a"), %%mm1 \n\t"
|
|
|
|
"paddb (%3, %%"REG_a"), %%mm1 \n\t"
|
2002-08-11 10:52:22 +00:00
|
|
|
"movq %%mm0, %%mm2 \n\t"
|
|
|
|
"movq %%mm1, %%mm3 \n\t"
|
|
|
|
"punpcklbw %%mm0, %%mm0 \n\t"
|
|
|
|
"punpckhbw %%mm2, %%mm2 \n\t"
|
|
|
|
"punpcklbw %%mm1, %%mm1 \n\t"
|
|
|
|
"punpckhbw %%mm3, %%mm3 \n\t"
|
|
|
|
"pmulhw %%mm0, %%mm1 \n\t"
|
|
|
|
"pmulhw %%mm2, %%mm3 \n\t"
|
|
|
|
"paddw %%mm1, %%mm1 \n\t"
|
|
|
|
"paddw %%mm3, %%mm3 \n\t"
|
|
|
|
"paddw %%mm0, %%mm1 \n\t"
|
|
|
|
"paddw %%mm2, %%mm3 \n\t"
|
|
|
|
"psrlw $8, %%mm1 \n\t"
|
|
|
|
"psrlw $8, %%mm3 \n\t"
|
|
|
|
"packuswb %%mm3, %%mm1 \n\t"
|
2004-10-21 11:55:20 +00:00
|
|
|
"movq %%mm1, (%4, %%"REG_a") \n\t"
|
|
|
|
"add $8, %%"REG_a" \n\t"
|
2002-08-11 10:52:22 +00:00
|
|
|
" js 1b \n\t"
|
2009-07-06 23:26:13 +00:00
|
|
|
:: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
|
2002-08-11 10:52:22 +00:00
|
|
|
"r" (dst+mmx_len), "g" (-mmx_len)
|
2004-10-21 11:55:20 +00:00
|
|
|
: "%"REG_a
|
2002-08-11 10:52:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if(mmx_len!=len){
|
|
|
|
int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
|
|
|
|
lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-08-11 09:46:50 +00:00
|
|
|
static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){
|
2002-08-11 10:12:15 +00:00
|
|
|
int i;
|
|
|
|
int8_t *src2= (int8_t*)src;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-08-11 09:46:50 +00:00
|
|
|
for(i=0; i<len; i++)
|
|
|
|
{
|
2002-08-11 10:12:15 +00:00
|
|
|
const int n= shift[0][i] + shift[1][i] + shift[2][i];
|
|
|
|
dst[i]= src2[i]+((n*src2[i])>>7);
|
2002-08-11 09:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
static void noise(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp){
|
|
|
|
int8_t *noise= fp->noise;
|
|
|
|
int y;
|
|
|
|
int shift=0;
|
|
|
|
|
|
|
|
if(!noise)
|
|
|
|
{
|
2002-06-16 13:45:52 +00:00
|
|
|
if(src==dst) return;
|
|
|
|
|
2012-11-09 00:31:49 +00:00
|
|
|
if(dstStride==srcStride) memcpy(dst, src, srcStride*height);
|
2002-06-14 01:14:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for(y=0; y<height; y++)
|
|
|
|
{
|
2012-11-09 00:31:49 +00:00
|
|
|
memcpy(dst, src, width);
|
2002-06-14 01:14:56 +00:00
|
|
|
dst+= dstStride;
|
2002-06-16 13:54:36 +00:00
|
|
|
src+= srcStride;
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
if(fp->temporal) shift= rand()&(MAX_SHIFT -1);
|
|
|
|
else shift= nonTempRandShift[y];
|
|
|
|
|
2002-06-16 13:54:36 +00:00
|
|
|
if(fp->quality==0) shift&= ~7;
|
2002-08-11 09:46:50 +00:00
|
|
|
if (fp->averaged) {
|
2002-08-11 09:52:23 +00:00
|
|
|
lineNoiseAvg(dst, src, width, fp->prev_shift[y]);
|
|
|
|
fp->prev_shift[y][fp->shiftptr] = noise + shift;
|
2002-08-11 09:46:50 +00:00
|
|
|
} else {
|
|
|
|
lineNoise(dst, src, noise, width, shift);
|
|
|
|
}
|
2002-06-14 01:14:56 +00:00
|
|
|
dst+= dstStride;
|
|
|
|
src+= srcStride;
|
|
|
|
}
|
2002-08-11 09:46:50 +00:00
|
|
|
fp->shiftptr++;
|
|
|
|
if (fp->shiftptr == 3) fp->shiftptr = 0;
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2002-06-14 01:14:56 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt){
|
2002-06-16 13:54:36 +00:00
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
|
|
|
}
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
struct mp_image *dmpi = mpi;
|
|
|
|
if (!mp_image_is_writeable(mpi)) {
|
|
|
|
dmpi = vf_alloc_out_image(vf);
|
|
|
|
mp_image_copy_attributes(dmpi, mpi);
|
|
|
|
}
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam);
|
|
|
|
noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
|
|
|
|
noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam);
|
|
|
|
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX
|
2008-10-16 18:59:27 +00:00
|
|
|
if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
|
2002-06-14 01:14:56 +00:00
|
|
|
#endif
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX2
|
2008-10-16 18:59:27 +00:00
|
|
|
if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
|
2002-06-14 01:14:56 +00:00
|
|
|
#endif
|
|
|
|
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
if (dmpi != mpi)
|
|
|
|
talloc_free(mpi);
|
|
|
|
return dmpi;
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static void uninit(struct vf_instance *vf){
|
2002-06-16 13:45:52 +00:00
|
|
|
if(!vf->priv) return;
|
|
|
|
|
2010-11-14 09:12:34 +00:00
|
|
|
av_free(vf->priv->chromaParam.noise);
|
2002-06-16 13:45:52 +00:00
|
|
|
vf->priv->chromaParam.noise= NULL;
|
|
|
|
|
2010-11-14 09:12:34 +00:00
|
|
|
av_free(vf->priv->lumaParam.noise);
|
2002-06-16 13:45:52 +00:00
|
|
|
vf->priv->lumaParam.noise= NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-06-16 13:45:52 +00:00
|
|
|
free(vf->priv);
|
|
|
|
vf->priv=NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt){
|
2002-06-14 01:14:56 +00:00
|
|
|
switch(fmt)
|
|
|
|
{
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
case IMGFMT_420P:
|
2002-06-16 13:45:52 +00:00
|
|
|
return vf_next_query_format(vf,vf->priv->outfmt);
|
2002-06-14 01:14:56 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse(FilterParam *fp, char* args){
|
|
|
|
char *pos;
|
|
|
|
char *max= strchr(args, ':');
|
|
|
|
|
|
|
|
if(!max) max= args + strlen(args);
|
|
|
|
|
|
|
|
fp->strength= atoi(args);
|
|
|
|
pos= strchr(args, 'u');
|
|
|
|
if(pos && pos<max) fp->uniform=1;
|
|
|
|
pos= strchr(args, 't');
|
|
|
|
if(pos && pos<max) fp->temporal=1;
|
2002-06-16 13:54:36 +00:00
|
|
|
pos= strchr(args, 'h');
|
|
|
|
if(pos && pos<max) fp->quality=1;
|
2002-08-13 17:53:32 +00:00
|
|
|
pos= strchr(args, 'p');
|
|
|
|
if(pos && pos<max) fp->pattern=1;
|
2002-08-11 09:46:50 +00:00
|
|
|
pos= strchr(args, 'a');
|
|
|
|
if(pos && pos<max) {
|
|
|
|
fp->temporal=1;
|
|
|
|
fp->averaged=1;
|
|
|
|
}
|
2002-06-14 01:14:56 +00:00
|
|
|
|
|
|
|
if(fp->strength) initNoise(fp);
|
|
|
|
}
|
|
|
|
|
2008-04-26 13:35:40 +00:00
|
|
|
static const unsigned int fmt_list[]={
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
IMGFMT_420P,
|
2002-06-16 13:45:52 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2010-02-21 13:40:49 +00:00
|
|
|
static int vf_open(vf_instance_t *vf, char *args){
|
2002-06-14 01:14:56 +00:00
|
|
|
vf->config=config;
|
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
2012-11-05 13:25:04 +00:00
|
|
|
vf->filter=filter;
|
2002-06-14 01:14:56 +00:00
|
|
|
vf->query_format=query_format;
|
2002-06-16 13:45:52 +00:00
|
|
|
vf->uninit=uninit;
|
2002-06-14 01:14:56 +00:00
|
|
|
vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
|
|
memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
|
|
|
if(args)
|
|
|
|
{
|
|
|
|
char *arg2= strchr(args,':');
|
|
|
|
if(arg2) parse(&vf->priv->chromaParam, arg2+1);
|
|
|
|
parse(&vf->priv->lumaParam, args);
|
|
|
|
}
|
2002-06-16 13:45:52 +00:00
|
|
|
|
|
|
|
// check csp:
|
video: decouple internal pixel formats from FourCCs
mplayer's video chain traditionally used FourCCs for pixel formats. For
example, it used IMGFMT_YV12 for 4:2:0 YUV, which was defined to the
string 'YV12' interpreted as unsigned int. Additionally, it used to
encode information into the numeric values of some formats. The RGB
formats had their bit depth and endian encoded into the least
significant byte. Extended planar formats (420P10 etc.) had chroma
shift, endian, and component bit depth encoded. (This has been removed
in recent commits.)
Replace the FourCC mess with a simple enum. Remove all the redundant
formats like YV12/I420/IYUV. Replace some image format names by
something more intuitive, most importantly IMGFMT_YV12 -> IMGFMT_420P.
Add img_fourcc.h, which contains the old IDs for code that actually uses
FourCCs. Change the way demuxers, that output raw video, identify the
video format: they set either MP_FOURCC_RAWVIDEO or MP_FOURCC_IMGFMT to
request the rawvideo decoder, and sh_video->imgfmt specifies the pixel
format. Like the previous hack, this is supposed to avoid the need for
a complete codecs.cfg entry per format, or other lookup tables. (Note
that the RGB raw video FourCCs mostly rely on ffmpeg's mappings for NUT
raw video, but this is still considered better than adding a raw video
decoder - even if trivial, it would be full of annoying lookup tables.)
The TV code has not been tested.
Some corrective changes regarding endian and other image format flags
creep in.
2012-12-23 19:03:30 +00:00
|
|
|
vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P);
|
2002-06-16 13:45:52 +00:00
|
|
|
if(!vf->priv->outfmt)
|
|
|
|
{
|
|
|
|
uninit(vf);
|
|
|
|
return 0; // no csp match :(
|
|
|
|
}
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX
|
2002-08-11 10:52:22 +00:00
|
|
|
if(gCpuCaps.hasMMX){
|
|
|
|
lineNoise= lineNoise_MMX;
|
|
|
|
lineNoiseAvg= lineNoiseAvg_MMX;
|
|
|
|
}
|
2002-06-14 01:14:56 +00:00
|
|
|
#endif
|
2009-01-16 09:21:21 +00:00
|
|
|
#if HAVE_MMX2
|
2002-06-14 01:14:56 +00:00
|
|
|
if(gCpuCaps.hasMMX2) lineNoise= lineNoise_MMX2;
|
2002-08-11 09:46:50 +00:00
|
|
|
// if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2;
|
2002-06-14 01:14:56 +00:00
|
|
|
#endif
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-12-02 14:57:15 +00:00
|
|
|
const vf_info_t vf_info_noise = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "noise generator",
|
|
|
|
.name = "noise",
|
|
|
|
.open = vf_open,
|
2002-06-14 01:14:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|