~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidAsharp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**/
2
 
/***************************************************************************
3
 
                          ADM_vidASharp  -  description
4
 
                             -------------------   
5
 
    Port of avisynth one
6
 
 
7
 
 ***************************************************************************/
8
 
/*
9
 
        
10
 
        Copyright (C) 2003 Donald A. Graft
11
 
        Copyright (C) 2002 Marc Fauconneau
12
 
        This program is free software; you can redistribute it and/or modify
13
 
        it under the terms of the GNU General Public License as published by
14
 
        the Free Software Foundation.
15
 
 
16
 
        This program is distributed in the hope that it will be useful,
17
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
        GNU General Public License for more details.
20
 
 
21
 
        You should have received a copy of the GNU General Public License
22
 
        along with this program; if not, write to the Free Software
23
 
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
 
*/
25
 
 
26
 
#include "config.h"
27
 
#include <stdio.h>
28
 
#include <stdlib.h>
29
 
#include <string.h>
30
 
#include <ADM_assert.h>
31
 
 
32
 
#include "config.h"
33
 
#include "fourcc.h"
34
 
#include "avio.hxx"
35
 
#include "avi_vars.h"
36
 
 
37
 
#include "ADM_toolkit/toolkit.hxx"
38
 
#include "ADM_editor/ADM_edit.hxx"
39
 
#include "ADM_video/ADM_genvideo.hxx"
40
 
#include"ADM_video/ADM_vidField.h"
41
 
#include"ADM_video/ADM_cache.h"
42
 
 
43
 
#include "ADM_toolkit/ADM_debugID.h"
44
 
#define MODULE_NAME MODULE_FILTER
45
 
#include "ADM_toolkit/ADM_debug.h"
46
 
 
47
 
#include "ADM_toolkit/ADM_cpuCap.h"
48
 
#include "ADM_filter/video_filters.h"
49
 
 
50
 
#include "ADM_vidASharp_param.h"
51
 
class ASharp : public AVDMGenericVideoStream
52
 
{
53
 
private:
54
 
        
55
 
        VideoCache      *vidCache;
56
 
        ASHARP_PARAM    *_param;
57
 
        int32_t        T,D,B,B2;
58
 
        
59
 
public:    
60
 
 
61
 
                        ASharp(AVDMGenericVideoStream *in,CONFcouple *couples)   ;
62
 
                        ~ASharp();
63
 
 
64
 
 
65
 
                        void update(void);         
66
 
        char            *printConf( void );
67
 
        uint8_t         configure(AVDMGenericVideoStream *in);
68
 
        uint8_t         getCoupledConf( CONFcouple **couples);
69
 
        uint8_t         getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data,uint32_t *flags);
70
 
};
71
 
 
72
 
BUILD_CREATE(asharp_create,ASharp);
73
 
static FILTER_PARAM asharp_param={4,{"t", "b","d", "bf"}};
74
 
 
75
 
 
76
 
SCRIPT_CREATE(asharp_script,ASharp,asharp_param);
77
 
//_______________________________________________
78
 
 
79
 
ASharp::ASharp(AVDMGenericVideoStream *in,CONFcouple *couples)
80
 
 
81
 
{
82
 
        _in=in;         
83
 
        memcpy(&_info,_in->getInfo(),sizeof(_info));    
84
 
        _info.encoding=1;
85
 
        _uncompressed=NULL;             
86
 
        _info.encoding=1;
87
 
 
88
 
 
89
 
        _param=new ASHARP_PARAM;
90
 
       
91
 
        if(couples)
92
 
                {
93
 
                     GET(t);
94
 
                     GET(d);
95
 
                     GET(b);
96
 
                     GET(bf); 
97
 
                }
98
 
                else // Default
99
 
                {
100
 
                        _param->t=2;
101
 
                        _param->d=4;
102
 
                        _param->b=-1;
103
 
                        _param->bf=0;
104
 
                }                              
105
 
                update();
106
 
                vidCache=new VideoCache(5,in);
107
 
}
108
 
//________________________________________________________
109
 
void ASharp::update( void)
110
 
{
111
 
                // parameters floating point to fixed point convertion
112
 
                T = (int)(_param->t*(4<<7));
113
 
                D = (int)(_param->d*(4<<7));
114
 
                B = (int)(256-_param->b*64);
115
 
                B2= (int)(256-_param->b*48);
116
 
 
117
 
                // clipping (recommended for SIMD code)
118
 
 
119
 
                if (T<-(4<<7)) T = -(4<<7); // yes, negatives values are accepted
120
 
                if (D<0) D = 0;
121
 
                if (B<0) B = 0;
122
 
                if (B2<0) B2 = 0;
123
 
 
124
 
                if (T>(32*(4<<7))) T = (32*(4<<7));
125
 
                if (D>(16*(4<<7))) D = (16*(4<<7));
126
 
                if (B>256) B = 256;
127
 
                if (B2>256) B2 = 256;
128
 
 
129
 
}
130
 
//________________________________________________________
131
 
uint8_t ASharp::getCoupledConf( CONFcouple **couples)
132
 
{
133
 
        *couples=NULL;
134
 
        *couples=new CONFcouple(4);
135
 
#define CSET(x)  (*couples)->setCouple((char *)#x,(_param->x))
136
 
               CSET(t);
137
 
               CSET(d);
138
 
               CSET(b);
139
 
               CSET(bf);    
140
 
        return 1;
141
 
}
142
 
//________________________________________________________
143
 
ASharp::~ASharp(void)
144
 
{
145
 
 
146
 
        if(vidCache) delete vidCache;     
147
 
 
148
 
     
149
 
        vidCache=NULL;
150
 
 
151
 
}
152
 
 
153
 
extern uint8_t DIA_getASharp(ASHARP_PARAM *param, AVDMGenericVideoStream *in);
154
 
//________________________________________________________
155
 
uint8_t ASharp::configure(AVDMGenericVideoStream *in)
156
 
{
157
 
uint8_t r=0;
158
 
        _in=in;
159
 
        if( DIA_getASharp(_param, _in))
160
 
        {
161
 
                r=1;
162
 
        }
163
 
        update();
164
 
        return r;
165
 
}
166
 
 
167
 
//________________________________________________________
168
 
char *ASharp::printConf( void )
169
 
{
170
 
        static char buf[50];
171
 
 
172
 
        ADM_assert(_param);
173
 
        sprintf((char *)buf," ASharp (MarcFD)");
174
 
        return buf;
175
 
}
176
 
        
177
 
//________________________________________________________
178
 
uint8_t ASharp::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len,
179
 
                                ADMImage *data,uint32_t *flags)
180
 
{
181
 
ADMImage *src;
182
 
ADMImage *dst;
183
 
 
184
 
        dst=data;
185
 
        if(frame>=_info.nb_frames) return 0;
186
 
        src=vidCache->getImage(frame);
187
 
        dst->duplicate(src);
188
 
        asharp_run_c(     dst->GetWritePtr(PLANAR_Y),
189
 
                        dst->GetPitch(PLANAR_Y), 
190
 
                        _info.height,
191
 
                        _info.width,
192
 
                        T,
193
 
                        D,
194
 
                        B,
195
 
                        B2,
196
 
                        _param->bf);
197
 
 
198
 
        vidCache->unlockAll();
199
 
 
200
 
        return 1;
201
 
}
202
 
 
203
 
 
204
 
 
205
 
 
206
 
void asharp_run_c(      uc* planeptr, int pitch,
207
 
                                        int height, int width, 
208
 
                                        int     T,int D, int B, int B2, bool bf )
209
 
        {
210
 
                uc* lineptr = new uc[width];
211
 
                int p = pitch;
212
 
                int y,x;
213
 
                uc* cfp = planeptr+pitch;
214
 
                uc* lp = lineptr;
215
 
                memcpy(lp,planeptr,width);
216
 
                for (y=1;y<height-1;y++) {
217
 
                        int last = cfp[0];
218
 
                        for (x=0;x<width-1;x++) {
219
 
 
220
 
                                int avg = 0;
221
 
                                int dev = 0;
222
 
                                int T2;
223
 
                                int diff;
224
 
                                int tmp;
225
 
 
226
 
                                avg += lp[x-1];
227
 
                                avg += lp[x  ];
228
 
                                avg += lp[x+1];
229
 
                                avg += last;
230
 
                                avg += cfp[x    ];
231
 
                                avg += cfp[x  +1];
232
 
                                avg += cfp[x+p-1];
233
 
                                avg += cfp[x+p  ];
234
 
                                avg += cfp[x+p+1];
235
 
 
236
 
                                avg *= (65535/9);
237
 
                                avg >>= 16;
238
 
 
239
 
                                #define CHECK(A) \
240
 
                                if (abs(A-cfp[x])>dev) dev = abs(A-cfp[x]);
241
 
                                
242
 
                                if (bf) {
243
 
 
244
 
                                if (y%8>0) {
245
 
                                        if (x%8>0) CHECK(lp[x-1])
246
 
                                        CHECK(lp[x  ])
247
 
                                        if (x%8<7) CHECK(lp[x+1])
248
 
                                }
249
 
                                if (x%8>0) CHECK(last)
250
 
                                if (x%8<7) CHECK(cfp[x  +1])
251
 
                                if (y%8<7) {
252
 
                                        if (x%8>0) CHECK(cfp[x+p-1])
253
 
                                        CHECK(cfp[x+p  ])
254
 
                                        if (x%8<7) CHECK(cfp[x+p+1])
255
 
                                }
256
 
 
257
 
                                } else {
258
 
                                        CHECK(lp[x-p-1])
259
 
                                        CHECK(lp[x-p  ])
260
 
                                        CHECK(lp[x-p+1])
261
 
                                        CHECK(last)
262
 
                                        CHECK(cfp[x  +1])
263
 
                                        CHECK(cfp[x+p-1])
264
 
                                        CHECK(cfp[x+p  ])
265
 
                                        CHECK(cfp[x+p+1])
266
 
                                }
267
 
 
268
 
                                T2 = T;
269
 
                                diff = cfp[x]-avg;
270
 
                                int D2 = D;
271
 
 
272
 
                                if (x%8==6) D2=(D2*B2)>>8;
273
 
                                if (x%8==7) D2=(D2*B)>>8;
274
 
                                if (x%8==0) D2=(D2*B)>>8;
275
 
                                if (x%8==1) D2=(D2*B2)>>8;
276
 
                                if (y%8==6) D2=(D2*B2)>>8;
277
 
                                if (y%8==7) D2=(D2*B)>>8;
278
 
                                if (y%8==0) D2=(D2*B)>>8;
279
 
                                if (y%8==1) D2=(D2*B2)>>8;
280
 
 
281
 
                                int Da = -32+(D>>7);
282
 
                                if (D>0) T2 = ((((dev<<7)*D2)>>16)+Da)<<4;
283
 
 
284
 
                                if (T2>T) T2=T;
285
 
                                if (T2<-32) T2=-32;
286
 
 
287
 
                                tmp = (((diff<<7)*T2)>>16)+cfp[x];
288
 
 
289
 
                                if (tmp < 0) tmp = 0;
290
 
                                if (tmp > 255) tmp = 255;
291
 
                                lp[x-1] = last;
292
 
                                last = cfp[x];
293
 
                                cfp[x] = tmp;
294
 
                        }
295
 
                        lp[x] = cfp[x];
296
 
                        cfp += pitch;
297
 
                }
298
 
        delete[] lineptr;
299
 
300
 
//**********************************