annotate libmpcodecs/vf_hqdn3d.c @ 13982:5109aee318f4

Sync with 1.808: v4l2 norm setting
author gpoirier
date Fri, 19 Nov 2004 19:32:16 +0000
parents e9a2af584986
children 5f98b89262c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9441
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
1 /*
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
2 Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
3
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
7 (at your option) any later version.
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
8
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
12 GNU General Public License for more details.
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
13
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
15 along with this program; if not, write to the Free Software
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
17 */
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
18
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
19 #include <stdio.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
20 #include <stdlib.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
21 #include <string.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
22 #include <inttypes.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
23 #include <math.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
24
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
25 #include "../config.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
26 #include "../mp_msg.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
27
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
28 #ifdef HAVE_MALLOC_H
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
29 #include <malloc.h>
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
30 #endif
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
31
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
32 #include "img_format.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
33 #include "mp_image.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
34 #include "vf.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
35 #include "../libvo/fastmemcpy.h"
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
36
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
37 #define PARAM1_DEFAULT 4.0
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
38 #define PARAM2_DEFAULT 3.0
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
39 #define PARAM3_DEFAULT 6.0
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
40
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
41 //===========================================================================//
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
42
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
43 struct vf_priv_s {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
44 int Coefs[4][512*16];
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
45 unsigned int *Line;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
46 unsigned short *Frame[3];
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
47 };
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
48
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
49
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
50 /***************************************************************************/
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
51
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
52 static void uninit(struct vf_instance_s* vf){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
53 if(vf->priv->Line){free(vf->priv->Line);vf->priv->Line=NULL;}
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
54 if(vf->priv->Frame[0]){free(vf->priv->Frame[0]);vf->priv->Frame[0]=NULL;}
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
55 if(vf->priv->Frame[1]){free(vf->priv->Frame[1]);vf->priv->Frame[1]=NULL;}
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
56 if(vf->priv->Frame[2]){free(vf->priv->Frame[2]);vf->priv->Frame[2]=NULL;}
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
57 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
58
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
59 static int config(struct vf_instance_s* vf,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
60 int width, int height, int d_width, int d_height,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
61 unsigned int flags, unsigned int outfmt){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
62
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
63 uninit(vf);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
64 vf->priv->Line = malloc(width*sizeof(int));
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
65
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
66 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
67 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
68
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
69 static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
70 // int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
71 int dMul= PrevMul-CurrMul;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
72 int d=((dMul+0x10007FF)/(65536/16));
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
73 return CurrMul + Coef[d];
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
74 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
75
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
76 static void deNoise(unsigned char *Frame, // mpi->planes[x]
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
77 unsigned char *FrameDest, // dmpi->planes[x]
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
78 unsigned int *LineAnt, // vf->priv->Line (width bytes)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
79 unsigned short **FrameAntPtr,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
80 int W, int H, int sStride, int dStride,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
81 int *Horizontal, int *Vertical, int *Temporal)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
82 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
83 int X, Y;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
84 int sLineOffs = 0, dLineOffs = 0;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
85 unsigned int PixelAnt;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
86 int PixelDst;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
87 unsigned short* FrameAnt=(*FrameAntPtr);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
88
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
89 if(!FrameAnt){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
90 (*FrameAntPtr)=FrameAnt=malloc(W*H*sizeof(unsigned short));
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
91 for (Y = 0; Y < H; Y++){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
92 unsigned short* dst=&FrameAnt[Y*W];
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
93 unsigned char* src=Frame+Y*sStride;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
94 for (X = 0; X < W; X++) dst[X]=src[X]<<8;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
95 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
96 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
97
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
98 /* First pixel has no left nor top neightbour. Only previous frame */
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
99 LineAnt[0] = PixelAnt = Frame[0]<<16;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
100 PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
101 FrameAnt[0] = ((PixelDst+0x1000007F)/256);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
102 FrameDest[0]= ((PixelDst+0x10007FFF)/65536);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
103
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
104 /* Fist line has no top neightbour. Only left one for each pixel and
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
105 * last frame */
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
106 for (X = 1; X < W; X++){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
107 LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
108 PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
109 FrameAnt[X] = ((PixelDst+0x1000007F)/256);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
110 FrameDest[X]= ((PixelDst+0x10007FFF)/65536);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
111 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
112
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
113 for (Y = 1; Y < H; Y++){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
114 unsigned int PixelAnt;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
115 unsigned short* LinePrev=&FrameAnt[Y*W];
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
116 sLineOffs += sStride, dLineOffs += dStride;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
117 /* First pixel on each line doesn't have previous pixel */
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
118 PixelAnt = Frame[sLineOffs]<<16;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
119 LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
120 PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
121 LinePrev[0] = ((PixelDst+0x1000007F)/256);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
122 FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)/65536);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
123
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
124 for (X = 1; X < W; X++){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
125 int PixelDst;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
126 /* The rest are normal */
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
127 PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
128 LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
129 PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
130 LinePrev[X] = ((PixelDst+0x1000007F)/256);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
131 FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)/65536);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
132 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
133 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
134 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
135
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
136
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
137 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
138 int cw= mpi->w >> mpi->chroma_x_shift;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
139 int ch= mpi->h >> mpi->chroma_y_shift;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
140 int W = mpi->w, H = mpi->h;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
141
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
142 mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
143 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
144 mpi->w,mpi->h);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
145
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
146 if(!dmpi) return 0;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
147
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
148 deNoise(mpi->planes[0], dmpi->planes[0],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
149 vf->priv->Line, &vf->priv->Frame[0], W, H,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
150 mpi->stride[0], dmpi->stride[0],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
151 vf->priv->Coefs[0],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
152 vf->priv->Coefs[0],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
153 vf->priv->Coefs[1]);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
154 deNoise(mpi->planes[1], dmpi->planes[1],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
155 vf->priv->Line, &vf->priv->Frame[1], cw, ch,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
156 mpi->stride[1], dmpi->stride[1],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
157 vf->priv->Coefs[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
158 vf->priv->Coefs[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
159 vf->priv->Coefs[3]);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
160 deNoise(mpi->planes[2], dmpi->planes[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
161 vf->priv->Line, &vf->priv->Frame[2], cw, ch,
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
162 mpi->stride[2], dmpi->stride[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
163 vf->priv->Coefs[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
164 vf->priv->Coefs[2],
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
165 vf->priv->Coefs[3]);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
166
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
167 return vf_next_put_image(vf,dmpi);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
168 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
169
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
170 //===========================================================================//
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
171
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
172 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
173 switch(fmt)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
174 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
175 case IMGFMT_YV12:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
176 case IMGFMT_I420:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
177 case IMGFMT_IYUV:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
178 case IMGFMT_YVU9:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
179 case IMGFMT_444P:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
180 case IMGFMT_422P:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
181 case IMGFMT_411P:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
182 return vf_next_query_format(vf, fmt);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
183 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
184 return 0;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
185 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
186
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
187
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
188 #define ABS(A) ( (A) > 0 ? (A) : -(A) )
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
189
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
190 static void PrecalcCoefs(int *Ct, double Dist25)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
191 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
192 int i;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
193 double Gamma, Simil, C;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
194
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
195 Gamma = log(0.25) / log(1.0 - Dist25/255.0 - 0.00001);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
196
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
197 for (i = -256*16; i < 256*16; i++)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
198 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
199 Simil = 1.0 - ABS(i) / (16*255.0);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
200 C = pow(Simil, Gamma) * 65536.0 * (double)i / 16.0;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
201 Ct[16*256+i] = (C<0) ? (C-0.5) : (C+0.5);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
202 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
203 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
204
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
205
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
206 static int open(vf_instance_t *vf, char* args){
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
207 double LumSpac, LumTmp, ChromSpac, ChromTmp;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
208 double Param1, Param2, Param3, Param4;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
209
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
210 vf->config=config;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
211 vf->put_image=put_image;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
212 vf->query_format=query_format;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
213 vf->uninit=uninit;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
214 vf->priv=malloc(sizeof(struct vf_priv_s));
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
215 memset(vf->priv, 0, sizeof(struct vf_priv_s));
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
216
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
217 if (args)
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
218 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
219 switch(sscanf(args, "%lf:%lf:%lf:%lf",
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
220 &Param1, &Param2, &Param3, &Param4
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
221 ))
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
222 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
223 case 0:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
224 LumSpac = PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
225 LumTmp = PARAM3_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
226
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
227 ChromSpac = PARAM2_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
228 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
229 break;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
230
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
231 case 1:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
232 LumSpac = Param1;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
233 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
234
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
235 ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
236 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
237 break;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
238
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
239 case 2:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
240 LumSpac = Param1;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
241 LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
242
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
243 ChromSpac = Param2;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
244 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
245 break;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
246
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
247 case 3:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
248 LumSpac = Param1;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
249 LumTmp = Param3;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
250
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
251 ChromSpac = Param2;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
252 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
253 break;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
254
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
255 case 4:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
256 LumSpac = Param1;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
257 LumTmp = Param3;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
258
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
259 ChromSpac = Param2;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
260 ChromTmp = Param4;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
261 break;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
262
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
263 default:
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
264 LumSpac = PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
265 LumTmp = PARAM3_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
266
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
267 ChromSpac = PARAM2_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
268 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
269 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
270 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
271 else
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
272 {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
273 LumSpac = PARAM1_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
274 LumTmp = PARAM3_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
275
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
276 ChromSpac = PARAM2_DEFAULT;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
277 ChromTmp = LumTmp * ChromSpac / LumSpac;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
278 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
279
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
280 PrecalcCoefs(vf->priv->Coefs[0], LumSpac);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
281 PrecalcCoefs(vf->priv->Coefs[1], LumTmp);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
282 PrecalcCoefs(vf->priv->Coefs[2], ChromSpac);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
283 PrecalcCoefs(vf->priv->Coefs[3], ChromTmp);
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
284
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
285 return 1;
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
286 }
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
287
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
288 vf_info_t vf_info_hqdn3d = {
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
289 "High Quality 3D Denoiser",
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
290 "hqdn3d",
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
291 "Daniel Moreno & A'rpi",
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
292 "",
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9441
diff changeset
293 open,
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9441
diff changeset
294 NULL
9441
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
295 };
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
296
85fa92f14e99 vf_hqdn3d: High-Quality version of the denoise3d filter
arpi
parents:
diff changeset
297 //===========================================================================//