forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageConverter.h
118 lines (105 loc) · 4.53 KB
/
ImageConverter.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/******************************************************************************
ImageConverter: Base class for image resizing & color model convertion
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_IMAGECONVERTER_H
#define QTAV_IMAGECONVERTER_H
#include <QtAV/QtAV_Global.h>
#include <QtAV/VideoFormat.h>
#include <QtCore/QVector>
namespace QtAV {
typedef int ImageConverterId;
class ImageConverterPrivate;
class ImageConverter //export is not needed
{
DPTR_DECLARE_PRIVATE(ImageConverter)
public:
ImageConverter();
virtual ~ImageConverter();
QByteArray outData() const;
// return false if i/o format not supported, or size is not valid.
// TODO: use isSupported(i/o format);
virtual bool check() const;
void setInSize(int width, int height);
void setOutSize(int width, int height);
void setInFormat(const VideoFormat& format);
void setInFormat(VideoFormat::PixelFormat format);
void setInFormat(int format);
void setOutFormat(const VideoFormat& format);
void setOutFormat(VideoFormat::PixelFormat format);
void setOutFormat(int formate);
// default is full range.
void setInRange(ColorRange range);
ColorRange inRange() const;
// default is full range
void setOutRange(ColorRange range);
ColorRange outRange() const;
/*!
* brightness, contrast, saturation: -100~100
* If value changes, setup sws
*/
void setBrightness(int value);
int brightness() const;
void setContrast(int value);
int contrast() const;
void setSaturation(int value);
int saturation() const;
QVector<quint8*> outPlanes() const;
QVector<int> outLineSizes() const;
virtual bool convert(const quint8 *const src[], const int srcStride[]);
virtual bool convert(const quint8 *const src[], const int srcStride[], quint8 *const dst[], const int dstStride[]) = 0;
public:
template<class C> static bool Register(ImageConverterId id, const char* name) { return Register(id, create<C>, name);}
static ImageConverter* create(ImageConverterId id);
static ImageConverter* create(const char* name);
/*!
* \brief next
* \param id NULL to get the first id address
* \return address of id or NULL if not found/end
*/
static ImageConverterId* next(ImageConverterId* id = 0);
static const char* name(ImageConverterId id);
static ImageConverterId id(const char* name);
private:
template<class C> static ImageConverter* create() { return new C();}
typedef ImageConverter* (*ImageConverterCreator)();
static bool Register(ImageConverterId id, ImageConverterCreator, const char *name);
protected:
ImageConverter(ImageConverterPrivate& d);
//Allocate memory for out data. Called in setOutFormat()
virtual bool prepareData(); //Allocate memory for out data
DPTR_DECLARE(ImageConverter)
};
class ImageConverterFFPrivate;
/*!
* \brief The ImageConverterFF class
* based on libswscale
*/
class ImageConverterFF Q_DECL_FINAL: public ImageConverter //Q_AV_EXPORT is not needed
{
DPTR_DECLARE_PRIVATE(ImageConverterFF)
public:
ImageConverterFF();
bool check() const Q_DECL_OVERRIDE;
// FIXME: why match to the pure virtual one if not declare here?
bool convert(const quint8 *const src[], const int srcStride[]) Q_DECL_OVERRIDE { return ImageConverter::convert(src, srcStride);}
bool convert(const quint8 *const src[], const int srcStride[], quint8 *const dst[], const int dstStride[]) Q_DECL_OVERRIDE;
};
typedef ImageConverterFF ImageConverterSWS;
//ImageConverter* c = ImageConverter::create(ImageConverterId_FF);
extern ImageConverterId ImageConverterId_FF;
extern ImageConverterId ImageConverterId_IPP;
} //namespace QtAV
#endif // QTAV_IMAGECONVERTER_H