annotate libmpcodecs/vf_denoise3d.c @ 9188:da162a0d9ae9

10l found by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
author michael
date Sat, 01 Feb 2003 00:48:33 +0000
parents df871e1c105d
children f1c4e01a584a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9179
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
1 /*
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
2 Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
3
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
7 (at your option) any later version.
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
8
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
12 GNU General Public License for more details.
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
13
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
15 along with this program; if not, write to the Free Software
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
17 */
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
18
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
19 #include <stdio.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
20 #include <stdlib.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
21 #include <string.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
22 #include <inttypes.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
23 #include <math.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
24
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
25 #include "../config.h"
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
26 #include "../mp_msg.h"
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
27
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
28 #ifdef HAVE_MALLOC_H
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
29 #include <malloc.h>
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
30 #endif
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 #include "img_format.h"
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
33 #include "mp_image.h"
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
34 #include "vf.h"
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
35 #include "../libvo/fastmemcpy.h"
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 #define PARAM1_DEFAULT 4.0
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
38 #define PARAM2_DEFAULT 3.0
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
39 #define PARAM3_DEFAULT 6.0
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
40
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
41 //===========================================================================//
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 struct vf_priv_s {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
44 int Coefs[4][512];
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
45 unsigned char *Line;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
46 mp_image_t *pmpi;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
47 };
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
48
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
49
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
50 /***************************************************************************/
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
51
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
52
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
53 static int config(struct vf_instance_s* vf,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
54 int width, int height, int d_width, int d_height,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
55 unsigned int flags, unsigned int outfmt){
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
56
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
57 if(vf->priv->Line) free(vf->priv->Line);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
58 vf->priv->Line = malloc(width);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
59 vf->priv->pmpi=NULL;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
60 // vf->default_caps &= !VFCAP_ACCEPT_STRIDE;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
61
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
62 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
63 }
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
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
66 void uninit(struct vf_instance_s* vf)
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 free(vf->priv->Line);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
69 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
70
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
71
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
72 #define LowPass(Prev, Curr, Coef) (((Prev)*Coef[Prev - Curr] + (Curr)*(65536-(Coef[Prev - Curr]))) / 65536)
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
73
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
74 static void deNoise(unsigned char *Frame, // mpi->planes[x]
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
75 unsigned char *FramePrev, // pmpi->planes[x]
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
76 unsigned char *FrameDest, // dmpi->planes[x]
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
77 unsigned char *LineAnt, // vf->priv->Line (width bytes)
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
78 int W, int H, int sStride, int pStride, int dStride,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
79 int *Horizontal, int *Vertical, int *Temporal)
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
80 {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
81 int X, Y;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
82 int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
83 unsigned char PixelAnt;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
84
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
85 /* First pixel has no left nor top neightbour. Only previous frame */
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
86 LineAnt[0] = PixelAnt = Frame[0];
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
87 FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
88
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
89 /* Fist line has no top neightbour. Only left one for each pixel and
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
90 * last frame */
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
91 for (X = 1; X < W; X++)
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
92 {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
93 PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
94 LineAnt[X] = PixelAnt;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
95 FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
96 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
97
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
98 for (Y = 1; Y < H; Y++)
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 sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
101 /* First pixel on each line doesn't have previous pixel */
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
102 PixelAnt = Frame[sLineOffs];
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
103 LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
104 FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
105
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
106 for (X = 1; X < W; X++)
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 /* The rest are normal */
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
109 PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
110 LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
111 FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
112 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
113 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
114 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
115
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
116
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
117
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
118 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
119 int cw= mpi->w >> mpi->chroma_x_shift;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
120 int ch= mpi->h >> mpi->chroma_y_shift;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
121 int W = mpi->w, H = mpi->h;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
122
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
123 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
124 MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
125 mpi->w,mpi->h);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
126
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
127 if(!dmpi) return 0;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
128 if (!vf->priv->pmpi) vf->priv->pmpi=mpi;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
129
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
130 deNoise(mpi->planes[0], vf->priv->pmpi->planes[0], dmpi->planes[0],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
131 vf->priv->Line, W, H,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
132 mpi->stride[0], vf->priv->pmpi->stride[0], dmpi->stride[0],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
133 vf->priv->Coefs[0] + 256,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
134 vf->priv->Coefs[0] + 256,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
135 vf->priv->Coefs[1] + 256);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
136 deNoise(mpi->planes[1], vf->priv->pmpi->planes[1], dmpi->planes[1],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
137 vf->priv->Line, cw, ch,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
138 mpi->stride[1], vf->priv->pmpi->stride[1], dmpi->stride[1],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
139 vf->priv->Coefs[2] + 256,
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[3] + 256);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
142 deNoise(mpi->planes[2], vf->priv->pmpi->planes[2], dmpi->planes[2],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
143 vf->priv->Line, cw, ch,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
144 mpi->stride[2], vf->priv->pmpi->stride[2], dmpi->stride[2],
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
145 vf->priv->Coefs[2] + 256,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
146 vf->priv->Coefs[2] + 256,
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
147 vf->priv->Coefs[3] + 256);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
148
9182
arpi
parents: 9179
diff changeset
149 vf->priv->pmpi=dmpi; // save reference image
9179
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
150 return vf_next_put_image(vf,dmpi);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
151 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
152
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
153 //===========================================================================//
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
154
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
155 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
156 switch(fmt)
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
157 {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
158 case IMGFMT_YV12:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
159 case IMGFMT_I420:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
160 case IMGFMT_IYUV:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
161 case IMGFMT_YVU9:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
162 case IMGFMT_444P:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
163 case IMGFMT_422P:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
164 case IMGFMT_411P:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
165 return vf_next_query_format(vf, fmt);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
166 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
167 return 0;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
168 }
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
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
171 #define ABS(A) ( (A) > 0 ? (A) : -(A) )
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 static void PrecalcCoefs(int *Ct, double Dist25)
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 int i;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
176 double Gamma, Simil;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
177
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
178 Gamma = log(0.25) / log(1.0 - Dist25/255.0);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
179
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
180 for (i = -256; i <= 255; i++)
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 Simil = 1.0 - ABS(i) / 255.0;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
183 Ct[256+i] = pow(Simil, Gamma) * 65536;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
184 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
185 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
186
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
187
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
188 static int open(vf_instance_t *vf, char* args){
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
189 double LumSpac, LumTmp, ChromSpac, ChromTmp;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
190 double Param1, Param2, Param3;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
191
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
192 vf->config=config;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
193 vf->put_image=put_image;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
194 vf->query_format=query_format;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
195 vf->uninit=uninit;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
196 vf->priv=malloc(sizeof(struct vf_priv_s));
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
197 memset(vf->priv, 0, sizeof(struct vf_priv_s));
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
198
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
199 if (args)
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 switch(sscanf(args, "%lf:%lf:%lf",
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
202 &Param1, &Param2, &Param3
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
203 ))
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
204 {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
205 case 0:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
206 LumSpac = PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
207 LumTmp = PARAM3_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
208
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
209 ChromSpac = PARAM2_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
210 ChromTmp = LumTmp * ChromSpac / LumSpac;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
211 break;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
212
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
213 case 1:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
214 LumSpac = Param1;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
215 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
216
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
217 ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
218 ChromTmp = LumTmp * ChromSpac / LumSpac;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
219 break;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
220
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
221 case 2:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
222 LumSpac = Param1;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
223 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
224
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
225 ChromSpac = Param2;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
226 ChromTmp = LumTmp * ChromSpac / LumSpac;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
227 break;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
228
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
229 case 3:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
230 LumSpac = Param1;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
231 LumTmp = Param3;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
232
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
233 ChromSpac = Param2;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
234 ChromTmp = LumTmp * ChromSpac / LumSpac;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
235 break;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
236
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
237 default:
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
238 LumSpac = PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
239 LumTmp = PARAM3_DEFAULT;
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 ChromSpac = PARAM2_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
242 ChromTmp = LumTmp * ChromSpac / LumSpac;
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 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
245 else
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 LumSpac = PARAM1_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
248 LumTmp = PARAM3_DEFAULT;
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 ChromSpac = PARAM2_DEFAULT;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
251 ChromTmp = LumTmp * ChromSpac / LumSpac;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
252 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
253
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
254 PrecalcCoefs(vf->priv->Coefs[0], LumSpac);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
255 PrecalcCoefs(vf->priv->Coefs[1], LumTmp);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
256 PrecalcCoefs(vf->priv->Coefs[2], ChromSpac);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
257 PrecalcCoefs(vf->priv->Coefs[3], ChromTmp);
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
258
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
259 return 1;
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
260 }
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
261
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
262 vf_info_t vf_info_denoise3d = {
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
263 "3D Denoiser (variable lowpass filter)",
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
264 "denoise3d",
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
265 "Daniel Moreno",
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 open
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
268 };
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
269
e93a0dd3ed56 new video filter: denoise3d - temporal&spatial noise reduction
arpi
parents:
diff changeset
270 //===========================================================================//