2
/***************************************************************************
3
ADM_vidWhirl.cpp - description
6
copyright : (C) 2003 by mean
7
email : fixounet@free.fr
13
***************************************************************************/
15
/***************************************************************************
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. *
22
***************************************************************************/
27
#include <ADM_assert.h>
36
#include "admmangle.h"
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"
43
static void Process(uint8_t *src,uint8_t *data, uint32_t width, uint32_t height,double frac);
46
static FILTER_PARAM whirlParam={0,{"ythresholdMask","cthresholdMask"}};
49
static int COS_CALCED[3600];
50
static int SIN_CALCED[3600];
51
class AVDMVideoWhirl:public AVDMGenericVideoStream
57
virtual char *printConf(void);
62
AVDMVideoWhirl( AVDMGenericVideoStream *in,CONFcouple *setup);
64
virtual uint8_t getFrameNumberNoAlloc(uint32_t frame, uint32_t *len,
65
ADMImage *data,uint32_t *flags);
67
virtual uint8_t configure( AVDMGenericVideoStream *instream);
71
SCRIPT_CREATE(whirl_script,AVDMVideoWhirl,whirlParam);
72
BUILD_CREATE(whirl_create,AVDMVideoWhirl);
74
char *AVDMVideoWhirl::printConf(void)
78
sprintf((char *)buf," Whril");
83
uint8_t AVDMVideoWhirl::configure( AVDMGenericVideoStream *instream)
88
AVDMVideoWhirl::AVDMVideoWhirl( AVDMGenericVideoStream *in,CONFcouple *couples)
93
memcpy(&_info,_in->getInfo(),sizeof(_info));
94
_uncompressed= new ADMImage(_info.width,_info.height);
96
#define TWOPI (2*3.1415)
98
for(int i=0;i<3600;i++)
103
COS_CALCED[i]=(int)floor(0.49+65536.*cos(angle));
104
SIN_CALCED[i]=(int)floor(0.49+65536.*sin(angle));
110
AVDMVideoWhirl::AVDMVideoWhirl()
112
delete _uncompressed;
116
uint8_t AVDMVideoWhirl::getFrameNumberNoAlloc(uint32_t frame,
122
uint32_t page=_info.width*_info.height;
125
if(frame>= _info.nb_frames) return 0;
129
frac=(double)frame/(double)STEP_SIZE;
130
if(frame>(_info.nb_frames-1)) return 0;
133
if(!_in->getFrameNumberNoAlloc(frame,len,_uncompressed,flags)) return 0;
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);
144
void Process(uint8_t *src,uint8_t *data, uint32_t width, uint32_t height,double frac)
156
frac=10*frac*180./width;
157
for(uint32_t y=0;y<height;y++)
159
for(uint32_t x=0;x<width;x++)
162
pointy=y-(height>>1);
163
if(!pointx && !pointy)
166
*wr++=*(src+((width*height+width)>>1));
170
dprime=pointx*pointx+pointy*pointy;
171
dprime=(int)floor(0.49+sqrt(dprime));
173
// dprime=abs(pointx)+abs(pointy);
177
iang=(int)floor((double)d*frac);
180
alpha=COS_CALCED[iang];
181
beta=SIN_CALCED[iang];
183
fx=alpha*pointx+beta*pointy;
184
fy=-beta*pointx+alpha*pointy;
188
// put back to original
189
pointx=fx+(width>>1);
190
pointy=fy+(height>>1);
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;
198
*(wr++)=*(src+pointx+width*pointy);