1
/***************************************************************************
2
ADM_vidFastConvolution.cpp - description
4
begin : Sat Nov 23 2002
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
***************************************************************************/
24
#include "ADM_toolkit/toolkit.hxx"
25
#include "ADM_editor/ADM_edit.hxx"
26
#include "ADM_video/ADM_genvideo.hxx"
27
#include "ADM_video/ADM_genvideo.hxx"
29
#include"ADM_filter/video_filters.h"
30
#include "ADM_userInterfaces/ADM_commonUI/DIA_factory.h"
31
#include "ADM_vidConvolution.hxx"
32
#include <ADM_assert.h>
35
BUILD_CREATE(mean_create,AVDMFastVideoMean);
36
BUILD_CREATE(sharpen_create,AVDMFastVideoSharpen);
37
BUILD_CREATE(Gaussian_create,AVDMFastVideoGauss);
38
BUILD_CREATE(median_create,AVDMFastVideoMedian);
40
static FILTER_PARAM convParam={2,{"luma","chroma"}};
42
SCRIPT_CREATE(mean_script,AVDMFastVideoMean,convParam);
43
SCRIPT_CREATE(sharpen_script,AVDMFastVideoSharpen,convParam);
44
SCRIPT_CREATE(gaussian_script,AVDMFastVideoGauss,convParam);
45
SCRIPT_CREATE(median_script,AVDMFastVideoMedian,convParam);
48
uint8_t AVDMFastVideoConvolution::getCoupledConf( CONFcouple **couples)
53
*couples=new CONFcouple(2);
55
#define CSET(x) (*couples)->setCouple((char *)#x,(_param->x))
62
//_______________________________________________________________
64
AVDMFastVideoConvolution::AVDMFastVideoConvolution(
65
AVDMGenericVideoStream *in,CONFcouple *couples)
70
memcpy(&_info,_in->getInfo(),sizeof(_info));
71
_uncompressed=new ADMImage(_in->getInfo()->width,_in->getInfo()->height);
72
ADM_assert(_uncompressed);
76
_param=NEW( CONV_PARAM);
79
printf("\n Creating from null\n");
83
_param=NEW(CONV_PARAM);
90
AVDMFastVideoConvolution::~AVDMFastVideoConvolution()
99
// Basically ask a uncompressed frame from editor and ask
100
// GUI to decompress it .
103
uint8_t AVDMFastVideoConvolution::getFrameNumberNoAlloc(uint32_t frame,
108
//uint8_t *dst,*dstu,*dstv,*srcu,*srcv;
109
uint8_t *x1,*x2,*x3,*o1;
110
uint32_t stride,page;
112
if(frame>= _info.nb_frames) return 0;
113
ADM_assert(_uncompressed);
115
page=(stride*_info.height)>>2;
119
// read uncompressed frame
120
if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0;
124
memcpy(YPLANE(data),YPLANE(_uncompressed),page*4);
128
o1=YPLANE(data)+stride;
129
x1=YPLANE(_uncompressed);
133
// first and last line
134
memcpy(YPLANE(data),YPLANE(_uncompressed),stride);
135
memcpy(YPLANE(data)+page*4-stride,YPLANE(_uncompressed)+page*4-stride,stride);
137
for(int32_t y=1;y<(int32_t)_info.height-1;y++)
139
doLine(x1,x2,x3,o1,stride);
149
memcpy(UPLANE(data),UPLANE(_uncompressed),page);
150
memcpy(VPLANE(data),VPLANE(_uncompressed),page);
156
o1=UPLANE(data)+stride;
157
x1=UPLANE(_uncompressed);
160
// first and last line
161
memcpy(UPLANE(data),UPLANE(_uncompressed),stride);
162
memcpy(UPLANE(data)+page-stride,UPLANE(_uncompressed)+page-stride,stride);
164
for(int32_t y=1;y<(int32_t)(_info.height>>1)-1;y++)
166
doLine(x1,x2,x3,o1,stride);
174
o1=VPLANE(data)+stride;
175
x1=VPLANE(_uncompressed);
178
// first and last line
179
memcpy(VPLANE(data),VPLANE(_uncompressed),stride);
180
memcpy(VPLANE(data)+page-stride,VPLANE(_uncompressed)+page-stride,stride);
182
for(int32_t y=1;y<(int32_t)(_info.height>>1)-1;y++)
184
doLine(x1,x2,x3,o1,stride);
191
data->copyInfo(_uncompressed);
195
// Run the convolution kernel on a whole line
196
// to speed up things (cache effect + locality of datas)
198
//----------------------------------------------------------------
199
//----------------------------------------------------------------
200
//-----------------------MEAN---------------------
201
//----------------------------------------------------------------
202
//----------------------------------------------------------------
204
char *AVDMFastVideoMean::printConf(void)
206
static char str[]="Mean(fast)";
210
uint8_t AVDMFastVideoMean::doLine(uint8_t *pred,
222
a2=*pred++;a3=*pred++;
224
c2=*next++;c3=*next++;
242
o=a1+a2+a3+b1+b2+b3+c1+c2+c3;
252
//----------------------------------------------------------------
253
//----------------------------------------------------------------
254
//-----------------------GAUSS---------------------
255
//----------------------------------------------------------------
256
//----------------------------------------------------------------
261
char *AVDMFastVideoGauss::printConf(void)
263
static char str[]="Gauss(fast)";
267
uint8_t AVDMFastVideoGauss::doLine(uint8_t *pred,
282
a2=*pred++;a3=*pred++;
284
c2=*next++;c3=*next++;
306
#define MORE(x,coef) if(abs(x-v)<=threshold) {o+=x*coef;r+=coef;}
321
o=6*a1+10*a2+6*a3+10*b1+16*b2+10*b3+6*c1+10*c2+6*c3;
331
//----------------------------------------------------------------
332
//----------------------------------------------------------------
333
//-----------------------SHARPEN---------------------
334
//----------------------------------------------------------------
335
//----------------------------------------------------------------
340
char *AVDMFastVideoSharpen::printConf(void)
342
static char str[]="Sharpen(fast)";
346
uint8_t AVDMFastVideoSharpen::doLine(uint8_t *pred,
358
a2=*pred++;a3=*pred++;
360
c2=*next++;c3=*next++;
381
//o=-a1+-2*a2+-a3+-2*b1+16*b2+-2*b3+-1*c1+-2*c2+-1*c3;
396
//----------------------------------------------------------------
397
//----------------------------------------------------------------
398
//-----------------------Median---------------------
399
//----------------------------------------------------------------
400
//----------------------------------------------------------------
405
char *AVDMFastVideoMedian::printConf(void)
407
static char str[]="Median(fast)";
411
uint8_t AVDMFastVideoMedian::doLine(uint8_t *pred,
420
uint8_t c1,c2,c3; //,i;
424
static uint8_t tab[9];
425
a2=*pred++;a3=*pred++;
427
c2=*next++;c3=*next++;
444
#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }
445
#define PIX_SWAP(a,b) { temp=(a);(a)=(b);(b)=temp; }
447
uint8_t *p=(uint8_t *)tab;
449
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
450
PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[4]) ; PIX_SORT(p[6], p[7]) ;
451
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
452
PIX_SORT(p[0], p[3]) ; PIX_SORT(p[5], p[8]) ; PIX_SORT(p[4], p[7]) ;
453
PIX_SORT(p[3], p[6]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[2], p[5]) ;
454
PIX_SORT(p[4], p[7]) ; PIX_SORT(p[4], p[2]) ; PIX_SORT(p[6], p[4]) ;
455
PIX_SORT(p[4], p[2]) ;
463
uint8_t AVDMFastVideoConvolution::configure(AVDMGenericVideoStream * instream)
466
//return DIA_getLumaChroma(&(_param->luma),&(_param->chroma)) ;
467
diaElemToggle luma(&(_param->luma),QT_TR_NOOP("_Process luma"),QT_TR_NOOP("Process luma plane"));
468
diaElemToggle chroma(&(_param->chroma),QT_TR_NOOP("P_rocess chroma"));
470
diaElem *elems[2]={&luma,&chroma};
472
return diaFactoryRun(QT_TR_NOOP("Fast Convolution"),2,elems);