Mercurial > mplayer.hg
annotate libmpcodecs/vf_denoise3d.c @ 33259:04dc3e55cd90
Increase the maximum value of the DVB timeout to 240 seconds.
Some devices may need more time for the initial tune (e.g. firmware loading).
Let the user specify higher timeout value if there is need to.
The default remains 30 seconds.
author | iive |
---|---|
date | Sun, 01 May 2011 18:07:59 +0000 |
parents | 7af3e6f901fd |
children |
rev | line source |
---|---|
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
1 /* |
26727 | 2 * Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org> |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
20 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
21 #include <stdio.h> |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
22 #include <stdlib.h> |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
23 #include <string.h> |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
24 #include <inttypes.h> |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
25 #include <math.h> |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
26 |
17012 | 27 #include "mp_msg.h" |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
28 #include "img_format.h" |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
29 #include "mp_image.h" |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
30 #include "vf.h" |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
31 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
32 #define PARAM1_DEFAULT 4.0 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
33 #define PARAM2_DEFAULT 3.0 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
34 #define PARAM3_DEFAULT 6.0 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
35 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
36 //===========================================================================// |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
37 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
38 struct vf_priv_s { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
39 int Coefs[4][512]; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
40 unsigned char *Line; |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
41 mp_image_t *pmpi; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
42 }; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
43 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
44 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
45 /***************************************************************************/ |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
46 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
47 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
48 static int config(struct vf_instance *vf, |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
49 int width, int height, int d_width, int d_height, |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
50 unsigned int flags, unsigned int outfmt){ |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
51 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
52 free(vf->priv->Line); |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
53 vf->priv->Line = malloc(width); |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
54 vf->priv->pmpi=NULL; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
55 // vf->default_caps &= !VFCAP_ACCEPT_STRIDE; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
56 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
57 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
58 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
59 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
60 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
61 static void uninit(struct vf_instance *vf) |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
62 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
63 free(vf->priv->Line); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
64 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
65 |
9365 | 66 #define LowPass(Prev, Curr, Coef) (Curr + Coef[Prev - Curr]) |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
67 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
68 static void deNoise(unsigned char *Frame, // mpi->planes[x] |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
69 unsigned char *FramePrev, // pmpi->planes[x] |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
70 unsigned char *FrameDest, // dmpi->planes[x] |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
71 unsigned char *LineAnt, // vf->priv->Line (width bytes) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
72 int W, int H, int sStride, int pStride, int dStride, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
73 int *Horizontal, int *Vertical, int *Temporal) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
74 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
75 int X, Y; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
76 int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
77 unsigned char PixelAnt; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
78 |
16684 | 79 /* First pixel has no left nor top neighbor. Only previous frame */ |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
80 LineAnt[0] = PixelAnt = Frame[0]; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
81 FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
82 |
16684 | 83 /* Fist line has no top neighbor. Only left one for each pixel and |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
84 * last frame */ |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
85 for (X = 1; X < W; X++) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
86 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
87 PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
88 LineAnt[X] = PixelAnt; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
89 FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
90 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
91 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
92 for (Y = 1; Y < H; Y++) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
93 { |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
94 sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
95 /* First pixel on each line doesn't have previous pixel */ |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
96 PixelAnt = Frame[sLineOffs]; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
97 LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
98 FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
99 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
100 for (X = 1; X < W; X++) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
101 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
102 /* The rest are normal */ |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
103 PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
104 LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
105 FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
106 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
107 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
108 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
109 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
110 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
111 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
112 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
113 int cw= mpi->w >> mpi->chroma_x_shift; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
114 int ch= mpi->h >> mpi->chroma_y_shift; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
115 int W = mpi->w, H = mpi->h; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
116 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
117 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
118 MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE | |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
119 MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
120 mpi->w,mpi->h); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
121 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
122 if(!dmpi) return 0; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
123 if (!vf->priv->pmpi) vf->priv->pmpi=mpi; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
124 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
125 deNoise(mpi->planes[0], vf->priv->pmpi->planes[0], dmpi->planes[0], |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
126 vf->priv->Line, W, H, |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
127 mpi->stride[0], vf->priv->pmpi->stride[0], dmpi->stride[0], |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
128 vf->priv->Coefs[0] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
129 vf->priv->Coefs[0] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
130 vf->priv->Coefs[1] + 256); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
131 deNoise(mpi->planes[1], vf->priv->pmpi->planes[1], dmpi->planes[1], |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
132 vf->priv->Line, cw, ch, |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
133 mpi->stride[1], vf->priv->pmpi->stride[1], dmpi->stride[1], |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
134 vf->priv->Coefs[2] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
135 vf->priv->Coefs[2] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
136 vf->priv->Coefs[3] + 256); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
137 deNoise(mpi->planes[2], vf->priv->pmpi->planes[2], dmpi->planes[2], |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
138 vf->priv->Line, cw, ch, |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
139 mpi->stride[2], vf->priv->pmpi->stride[2], dmpi->stride[2], |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
140 vf->priv->Coefs[2] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
141 vf->priv->Coefs[2] + 256, |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
142 vf->priv->Coefs[3] + 256); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
143 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
144 vf->priv->pmpi=dmpi; // save reference image |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
145 return vf_next_put_image(vf,dmpi, pts); |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
146 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
147 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
148 //===========================================================================// |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
149 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
150 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
151 switch(fmt) |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
152 { |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
153 case IMGFMT_YV12: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
154 case IMGFMT_I420: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
155 case IMGFMT_IYUV: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
156 case IMGFMT_YVU9: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
157 case IMGFMT_444P: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
158 case IMGFMT_422P: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
159 case IMGFMT_411P: |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
160 return vf_next_query_format(vf, fmt); |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
161 } |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
162 return 0; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
163 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
164 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
165 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
166 #define ABS(A) ( (A) > 0 ? (A) : -(A) ) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
167 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
168 static void PrecalcCoefs(int *Ct, double Dist25) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
169 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
170 int i; |
9365 | 171 double Gamma, Simil, C; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
172 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
173 Gamma = log(0.25) / log(1.0 - Dist25/255.0); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
174 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
175 for (i = -256; i <= 255; i++) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
176 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
177 Simil = 1.0 - ABS(i) / 255.0; |
9365 | 178 // Ct[256+i] = lround(pow(Simil, Gamma) * (double)i); |
179 C = pow(Simil, Gamma) * (double)i; | |
180 Ct[256+i] = (C<0) ? (C-0.5) : (C+0.5); | |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
181 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
182 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
183 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
184 |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
29087
diff
changeset
|
185 static int vf_open(vf_instance_t *vf, char *args){ |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
186 double LumSpac, LumTmp, ChromSpac, ChromTmp; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
187 double Param1, Param2, Param3; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
188 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
189 vf->config=config; |
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
190 vf->put_image=put_image; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
191 vf->query_format=query_format; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
192 vf->uninit=uninit; |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
193 vf->priv=malloc(sizeof(struct vf_priv_s)); |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
194 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
195 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
196 if (args) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
197 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
198 switch(sscanf(args, "%lf:%lf:%lf", |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
199 &Param1, &Param2, &Param3 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
200 )) |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
201 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
202 case 0: |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
203 LumSpac = PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
204 LumTmp = PARAM3_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
205 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
206 ChromSpac = PARAM2_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
207 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
208 break; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
209 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
210 case 1: |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
211 LumSpac = Param1; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
212 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
213 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
214 ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
215 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
216 break; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
217 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
218 case 2: |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
219 LumSpac = Param1; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
220 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
221 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
222 ChromSpac = Param2; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
223 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
224 break; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
225 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
226 case 3: |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
227 LumSpac = Param1; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
228 LumTmp = Param3; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
229 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
230 ChromSpac = Param2; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
231 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
232 break; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
233 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
234 default: |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
235 LumSpac = PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
236 LumTmp = PARAM3_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
237 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
238 ChromSpac = PARAM2_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
239 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
240 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
241 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
242 else |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
243 { |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
244 LumSpac = PARAM1_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
245 LumTmp = PARAM3_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
246 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
247 ChromSpac = PARAM2_DEFAULT; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
248 ChromTmp = LumTmp * ChromSpac / LumSpac; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
249 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
250 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
251 PrecalcCoefs(vf->priv->Coefs[0], LumSpac); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
252 PrecalcCoefs(vf->priv->Coefs[1], LumTmp); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
253 PrecalcCoefs(vf->priv->Coefs[2], ChromSpac); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
254 PrecalcCoefs(vf->priv->Coefs[3], ChromTmp); |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
255 |
32702
7af3e6f901fd
Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents:
32537
diff
changeset
|
256 return 1; |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
257 } |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
258 |
25221 | 259 const vf_info_t vf_info_denoise3d = { |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
260 "3D Denoiser (variable lowpass filter)", |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
261 "denoise3d", |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
262 "Daniel Moreno", |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
263 "", |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
29087
diff
changeset
|
264 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9439
diff
changeset
|
265 NULL |
9179
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
266 }; |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
267 |
e93a0dd3ed56
new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff
changeset
|
268 //===========================================================================// |