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

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidStabilize.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
 
                          ADM_vidStabilize.cpp  -  description
3
 
                             -------------------
4
 
    begin                : Mon Oct 7 2002
5
 
    copyright            : (C) 2002 by mean
6
 
    email                : fixounet@free.fr
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
#include <stdio.h>
18
 
#include <stdlib.h>
19
 
#include <string.h>
20
 
#include <ADM_assert.h>
21
 
#include <math.h>
22
 
 
23
 
#include "config.h"
24
 
#include "fourcc.h"
25
 
#include "avio.hxx"
26
 
#include "config.h"
27
 
#include "avi_vars.h"
28
 
#ifdef HAVE_ENCODER
29
 
 
30
 
 
31
 
#include "ADM_toolkit/toolkit.hxx"
32
 
#include "ADM_editor/ADM_edit.hxx"
33
 
#include "ADM_video/ADM_genvideo.hxx"
34
 
#include "ADM_video/ADM_vidStabilize.h"
35
 
#include "ADM_filter/video_filters.h"
36
 
 
37
 
 
38
 
static FILTER_PARAM stabParam={1,{"param"}};
39
 
 
40
 
 
41
 
SCRIPT_CREATE(stabilize_script,ADMVideoStabilize,stabParam);
42
 
extern uint8_t distMatrix[256][256];
43
 
extern uint32_t fixMul[16];
44
 
 
45
 
BUILD_CREATE(stabilize_create,ADMVideoStabilize);
46
 
 
47
 
 
48
 
 
49
 
char    *ADMVideoStabilize::printConf(void)
50
 
{
51
 
  static char buf[50];
52
 
 
53
 
        sprintf((char *)buf," Stabilize :%ld",*_param);
54
 
        return buf;
55
 
}
56
 
uint8_t  GUI_getIntegerValue(int *valye, int min, int max, char *title);
57
 
uint8_t ADMVideoStabilize::configure(AVDMGenericVideoStream *instream)
58
 
{
59
 
int i;
60
 
                        _in=instream;
61
 
                        i=(int)*_param;
62
 
                        if(GUI_getIntegerValue(&i,1,255,"Stabilize Threshold"))
63
 
                        {
64
 
                                        *_param=(uint32_t)i;
65
 
                                        return 1;
66
 
                        }
67
 
                        return 0;
68
 
                    
69
 
        
70
 
}
71
 
//--------------------------------------------------------      
72
 
ADMVideoStabilize::ADMVideoStabilize(AVDMGenericVideoStream *in,CONFcouple *couples)
73
 
{
74
 
  //uint32_t frame;
75
 
  _uncompressed=NULL;
76
 
  _in=in;
77
 
  memcpy(&_info,in->getInfo(),sizeof(_info)); 
78
 
 
79
 
  _info.encoding=1;
80
 
  if(couples)
81
 
  {
82
 
                        _param=NEW(uint32_t);
83
 
                        ADM_assert(couples->getCouple((char *)"param",_param));
84
 
        }
85
 
        else
86
 
        {
87
 
                        _param=NEW( uint32_t);
88
 
                        *_param=30;
89
 
        }
90
 
        vidCache=new VideoCache(5,_in);
91
 
 
92
 
}
93
 
ADMVideoStabilize::~ADMVideoStabilize()
94
 
{
95
 
 
96
 
        DELETE(_param);
97
 
        if(vidCache) delete vidCache;
98
 
        vidCache=NULL;
99
 
}
100
 
 
101
 
 
102
 
uint8_t ADMVideoStabilize::getCoupledConf( CONFcouple **couples)
103
 
{
104
 
 
105
 
                        ADM_assert(_param);
106
 
                        *couples=new CONFcouple(1);
107
 
                        (*couples)->setCouple((char *)"param",*_param);
108
 
 
109
 
                        return 1;
110
 
 
111
 
}
112
 
//                     1
113
 
//              Get in range in 121 + coeff matrix
114
 
//                     1
115
 
//
116
 
// If the value is too far away we ignore it
117
 
// else we blend
118
 
 
119
 
uint8_t ADMVideoStabilize::getFrameNumberNoAlloc(uint32_t frame,
120
 
                                uint32_t *len,
121
 
                                ADMImage *data,
122
 
                                uint32_t *flags)
123
 
{
124
 
UNUSED_ARG(flags);
125
 
uint32_t uvlen;
126
 
uint32_t dlen,dflags;
127
 
 
128
 
ADMImage        *_next;
129
 
ADMImage        *_previous;     
130
 
ADMImage        *_current;
131
 
                
132
 
                uvlen=    _info.width*_info.height;
133
 
                *len=uvlen+(uvlen>>1);
134
 
                if(frame> _info.nb_frames-1) return 0;
135
 
                _current=vidCache->getImage(frame);
136
 
                if(!_current) return 0;
137
 
                data->copyInfo(_current);
138
 
                if(!frame || (frame==_info.nb_frames-1))
139
 
                {
140
 
 
141
 
                        data->duplicate(_current);
142
 
                        vidCache->unlockAll();
143
 
                        return 1;
144
 
                }        
145
 
                _previous=vidCache->getImage(frame-1);          
146
 
                if(!_previous)
147
 
                {
148
 
                        vidCache->unlockAll();
149
 
                        return 0;
150
 
                }
151
 
                _next=vidCache->getImage(frame+1);
152
 
                if(!_next)
153
 
                {
154
 
                        vidCache->unlockAll();
155
 
                        return 0;
156
 
                }
157
 
                
158
 
           // for u & v , no action -> copy it as is
159
 
           memcpy(UPLANE(data),UPLANE(_current),uvlen>>2);
160
 
           memcpy(VPLANE(data),VPLANE(_current),uvlen>>2);
161
 
 
162
 
           uint8_t *inprev,*innext,*incur,*zout;
163
 
              
164
 
              inprev=YPLANE(_previous)+1+_info.width;
165
 
              innext=YPLANE(_next)+1+_info.width;
166
 
              incur =YPLANE(_current)+1+_info.width;
167
 
              
168
 
              zout=YPLANE(data)+_info.width+1;
169
 
              
170
 
             
171
 
              uint8_t *nl,*pl,*nc,*pc;
172
 
              
173
 
              uint16_t c,coeff;
174
 
              uint32_t x;
175
 
              for(uint32_t y= _info.height-1;y>1;y--)
176
 
                {
177
 
                        nl=incur+_info.width;
178
 
                        pl=incur-_info.width;
179
 
                        nc=incur+1;
180
 
                        pc=incur-1;                
181
 
                                                                   
182
 
                        for(x= _info.width-1;x>1;x--)
183
 
                        {
184
 
                                c=*incur*4;;
185
 
                                coeff=4;
186
 
#define PONDERATE(x,p) if(distMatrix[*incur][x]<*_param)                              \
187
 
{ c+=x;coeff++;}
188
 
                                                                                                                                PONDERATE(*innext,1);
189
 
                                PONDERATE(*inprev,1);
190
 
                                PONDERATE(*(pc),1);
191
 
                                PONDERATE(*(nc),1);
192
 
                                PONDERATE(*(nl),1);
193
 
                                PONDERATE(*(pl),1);
194
 
                                                                                                        //*zout=(uint8_t)floor(0.49+(c/coeff));
195
 
                                                                                                                                ADM_assert(coeff);
196
 
                                ADM_assert(coeff<16);
197
 
                                *zout=(c*fixMul[coeff])>>16;
198
 
                                zout++;
199
 
                                incur++;
200
 
                                innext++;
201
 
                                inprev++;       
202
 
                                nl++;pl++;nc++;pc++;      
203
 
                        }
204
 
                        zout+=2;
205
 
                        incur+=2;
206
 
                        innext+=2;
207
 
                        inprev+=2;
208
 
                }
209
 
                vidCache->unlockAll();
210
 
                return 1;       
211
 
}
212
 
 
213
 
 
214
 
#endif