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

« back to all changes in this revision

Viewing changes to avidemux/ADM_videoFilter/ADM_vidWhirl.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_vidWhirl.cpp  -  description
 
4
                             -------------------
 
5
    begin                : Fri Jan 3 2003
 
6
    copyright            : (C) 2003 by mean
 
7
    email                : fixounet@free.fr
 
8
    
 
9
    
 
10
   Whrilpool like effect
 
11
    
 
12
    
 
13
 ***************************************************************************/
 
14
 
 
15
/***************************************************************************
 
16
 *                                                                         *
 
17
 *   This program is free software; you can redistribute it and/or modify  *
 
18
 *   it under the terms of the GNU General Public License as published by  *
 
19
 *   the Free Software Foundation; either version 2 of the License, or     *
 
20
 *   (at your option) any later version.                                   *
 
21
 *                                                                         *
 
22
 ***************************************************************************/
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
#include <math.h>
 
27
#include <ADM_assert.h>
 
28
 
 
29
#include "config.h"
 
30
#include "fourcc.h"
 
31
#include "avio.hxx"
 
32
#include "config.h"
 
33
#include "avi_vars.h"
 
34
 
 
35
//#define LOOP
 
36
#include "admmangle.h"
 
37
 
 
38
#include "ADM_toolkit/toolkit.hxx"
 
39
#include "ADM_editor/ADM_edit.hxx"
 
40
#include "ADM_video/ADM_genvideo.hxx"
 
41
#include "ADM_filter/video_filters.h"
 
42
 
 
43
static void Process(uint8_t *src,uint8_t *data, uint32_t width, uint32_t height,double frac);
 
44
 
 
45
 
 
46
static FILTER_PARAM whirlParam={0,{"ythresholdMask","cthresholdMask"}};
 
47
 
 
48
#define STEP_SIZE 150
 
49
static int COS_CALCED[3600];
 
50
static int SIN_CALCED[3600];
 
51
class  AVDMVideoWhirl:public AVDMGenericVideoStream
 
52
 {
 
53
 
 
54
 protected:
 
55
 
 
56
                                
 
57
                                virtual         char *printConf(void);
 
58
                                                
 
59
 public:
 
60
 
 
61
 
 
62
                                                AVDMVideoWhirl(  AVDMGenericVideoStream *in,CONFcouple *setup);
 
63
                                                AVDMVideoWhirl();
 
64
                        virtual uint8_t         getFrameNumberNoAlloc(uint32_t frame, uint32_t *len,
 
65
                                                                ADMImage *data,uint32_t *flags);
 
66
 
 
67
                        virtual uint8_t         configure( AVDMGenericVideoStream *instream);
 
68
                        
 
69
 }     ;
 
70
 
 
71
SCRIPT_CREATE(whirl_script,AVDMVideoWhirl,whirlParam);
 
72
BUILD_CREATE(whirl_create,AVDMVideoWhirl);
 
73
 
 
74
char *AVDMVideoWhirl::printConf(void)
 
75
{
 
76
        static char buf[50];
 
77
        
 
78
        sprintf((char *)buf," Whril");
 
79
        return buf;
 
80
}
 
81
 
 
82
 
 
83
uint8_t AVDMVideoWhirl::configure( AVDMGenericVideoStream *instream)
 
84
{
 
85
                
 
86
                return 1;
 
87
}                                                                                       
 
88
AVDMVideoWhirl::AVDMVideoWhirl(  AVDMGenericVideoStream *in,CONFcouple *couples)
 
89
                
 
90
 
 
91
{
 
92
        _in=in;
 
93
        memcpy(&_info,_in->getInfo(),sizeof(_info));
 
94
        _uncompressed= new ADMImage(_info.width,_info.height);
 
95
        
 
96
        #define TWOPI (2*3.1415)
 
97
        double angle;
 
98
        for(int i=0;i<3600;i++)
 
99
        {
 
100
                angle=(double)i;
 
101
                angle/=TWOPI;
 
102
                angle/=10.;
 
103
                COS_CALCED[i]=(int)floor(0.49+65536.*cos(angle));
 
104
                SIN_CALCED[i]=(int)floor(0.49+65536.*sin(angle));
 
105
                
 
106
        }
 
107
}
 
108
 
 
109
 
 
110
AVDMVideoWhirl::AVDMVideoWhirl()
 
111
{
 
112
        delete _uncompressed;
 
113
}  
 
114
 
 
115
 
 
116
uint8_t AVDMVideoWhirl::getFrameNumberNoAlloc(uint32_t frame,
 
117
                                uint32_t *len,
 
118
                                ADMImage *data,
 
119
                                uint32_t *flags)
 
120
{
 
121
        
 
122
        uint32_t page=_info.width*_info.height;
 
123
        ADMImage *cur,*prev;
 
124
        double frac;
 
125
                if(frame>= _info.nb_frames) return 0;
 
126
                if(frame>STEP_SIZE)
 
127
                        frac=1;
 
128
                else
 
129
                        frac=(double)frame/(double)STEP_SIZE;
 
130
                if(frame>(_info.nb_frames-1)) return 0;
 
131
                
 
132
                *len=(page*3)>>1;
 
133
                if(!_in->getFrameNumberNoAlloc(frame,len,_uncompressed,flags)) return 0;
 
134
                
 
135
                data->copyInfo(_uncompressed);
 
136
                Process(YPLANE(_uncompressed),YPLANE(data),_info.width,_info.height,frac);
 
137
                Process(UPLANE(_uncompressed),UPLANE(data),_info.width>>1,_info.height>>1,frac);
 
138
                Process(VPLANE(_uncompressed),VPLANE(data),_info.width>>1,_info.height>>1,frac);
 
139
                
 
140
                return 1;
 
141
 
 
142
}
 
143
#define invlen(x) x
 
144
void Process(uint8_t *src,uint8_t *data, uint32_t width, uint32_t height,double frac)
 
145
{
 
146
int     dprime,d;
 
147
int     pointx,pointy;
 
148
int     fx,fy;
 
149
int     alpha,beta;
 
150
 
 
151
uint8_t *wr;
 
152
double angle;
 
153
int     iang;
 
154
 
 
155
        wr=data;
 
156
        frac=10*frac*180./width;
 
157
        for(uint32_t y=0;y<height;y++)
 
158
        {
 
159
        for(uint32_t x=0;x<width;x++)
 
160
        {
 
161
                pointx=x-(width>>1);
 
162
                pointy=y-(height>>1);
 
163
                if(!pointx && !pointy)
 
164
                {
 
165
                        // center continue
 
166
                        *wr++=*(src+((width*height+width)>>1));
 
167
                        continue;
 
168
                }
 
169
                
 
170
                dprime=pointx*pointx+pointy*pointy;
 
171
                dprime=(int)floor(0.49+sqrt(dprime));
 
172
 
 
173
//              dprime=abs(pointx)+abs(pointy);         
 
174
                d=invlen(dprime);
 
175
                // rotate 
 
176
                
 
177
                iang=(int)floor((double)d*frac);
 
178
                iang%=3600;
 
179
                
 
180
                alpha=COS_CALCED[iang];
 
181
                beta=SIN_CALCED[iang];
 
182
                
 
183
                fx=alpha*pointx+beta*pointy;
 
184
                fy=-beta*pointx+alpha*pointy;
 
185
                // expand
 
186
                fx=fx>>16;
 
187
                fy=fy>>16;
 
188
                // put back to original
 
189
                pointx=fx+(width>>1);
 
190
                pointy=fy+(height>>1);
 
191
                
 
192
                // Clamp
 
193
                if(pointx<0) pointx=0;
 
194
                if(pointx>width-1) pointx=width-1;
 
195
                if(pointy<0) pointy=0;
 
196
                if(pointy>height-1) pointy=height-1;
 
197
                
 
198
                *(wr++)=*(src+pointx+width*pointy);
 
199
                
 
200
        
 
201
        }
 
202
        }
 
203
}