-
Notifications
You must be signed in to change notification settings - Fork 10
/
GreyScaleVideoFilter.cpp
50 lines (40 loc) · 1.16 KB
/
GreyScaleVideoFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "GreyScaleVideoFilter.h"
#include "VideoFrame.h"
#include "QVideoFrameToQImage.h"
#include "QImageScanLines.h"
GreyScaleVideoFilter::GreyScaleVideoFilter( QObject* parent )
: QAbstractVideoFilter( parent )
{
}
QVideoFilterRunnable* GreyScaleVideoFilter::createFilterRunnable()
{
return new GreyScaleVideoFilterRunnable();
}
GreyScaleVideoFilterRunnable::GreyScaleVideoFilterRunnable()
{
}
QVideoFrame GreyScaleVideoFilterRunnable::run( QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags )
{
Q_UNUSED( flags )
if ( !input )
{
return QVideoFrame();
}
QImage image = QVideoFrameToQImage( *input );
QImageScanLines scanLines( &image, input, surfaceFormat );
int width = scanLines.width();
int height = scanLines.height();
for ( int y = 0; y < height; y++ )
{
uchar* pixel = scanLines.scanLine( y );
for ( int x = 0; x < width; x++ )
{
uchar& B = pixel[ 0 ];
uchar& G = pixel[ 1 ];
uchar& R = pixel[ 2 ];
B = G = R = static_cast< uchar >( qGray( R, G, B ) );
pixel += 4;
}
}
return image;
}