1
/***************************************************************************
2
ADM_vidStabilize.cpp - description
5
copyright : (C) 2002 by mean
6
email : fixounet@free.fr
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
20
#include <ADM_assert.h>
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"
38
static FILTER_PARAM stabParam={1,{"param"}};
41
SCRIPT_CREATE(stabilize_script,ADMVideoStabilize,stabParam);
42
extern uint8_t distMatrix[256][256];
43
extern uint32_t fixMul[16];
45
BUILD_CREATE(stabilize_create,ADMVideoStabilize);
49
char *ADMVideoStabilize::printConf(void)
53
sprintf((char *)buf," Stabilize :%ld",*_param);
56
uint8_t GUI_getIntegerValue(int *valye, int min, int max, char *title);
57
uint8_t ADMVideoStabilize::configure(AVDMGenericVideoStream *instream)
62
if(GUI_getIntegerValue(&i,1,255,"Stabilize Threshold"))
71
//--------------------------------------------------------
72
ADMVideoStabilize::ADMVideoStabilize(AVDMGenericVideoStream *in,CONFcouple *couples)
77
memcpy(&_info,in->getInfo(),sizeof(_info));
83
ADM_assert(couples->getCouple((char *)"param",_param));
87
_param=NEW( uint32_t);
90
vidCache=new VideoCache(5,_in);
93
ADMVideoStabilize::~ADMVideoStabilize()
97
if(vidCache) delete vidCache;
102
uint8_t ADMVideoStabilize::getCoupledConf( CONFcouple **couples)
106
*couples=new CONFcouple(1);
107
(*couples)->setCouple((char *)"param",*_param);
113
// Get in range in 121 + coeff matrix
116
// If the value is too far away we ignore it
119
uint8_t ADMVideoStabilize::getFrameNumberNoAlloc(uint32_t frame,
126
uint32_t dlen,dflags;
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))
141
data->duplicate(_current);
142
vidCache->unlockAll();
145
_previous=vidCache->getImage(frame-1);
148
vidCache->unlockAll();
151
_next=vidCache->getImage(frame+1);
154
vidCache->unlockAll();
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);
162
uint8_t *inprev,*innext,*incur,*zout;
164
inprev=YPLANE(_previous)+1+_info.width;
165
innext=YPLANE(_next)+1+_info.width;
166
incur =YPLANE(_current)+1+_info.width;
168
zout=YPLANE(data)+_info.width+1;
171
uint8_t *nl,*pl,*nc,*pc;
175
for(uint32_t y= _info.height-1;y>1;y--)
177
nl=incur+_info.width;
178
pl=incur-_info.width;
182
for(x= _info.width-1;x>1;x--)
186
#define PONDERATE(x,p) if(distMatrix[*incur][x]<*_param) \
188
PONDERATE(*innext,1);
189
PONDERATE(*inprev,1);
194
//*zout=(uint8_t)floor(0.49+(c/coeff));
196
ADM_assert(coeff<16);
197
*zout=(c*fixMul[coeff])>>16;
209
vidCache->unlockAll();