forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageConverter.cpp
222 lines (185 loc) · 5.26 KB
/
ImageConverter.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/******************************************************************************
ImageConverter: Base class for image resizing & color model convertion
Copyright (C) 2012-2014 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
******************************************************************************/
#include "QtAV/private/ImageConverter_p.h"
#include "QtAV/private/AVCompat.h"
#include "QtAV/private/factory.h"
#include "QtAV/ImageConverter.h"
namespace QtAV {
FACTORY_DEFINE(ImageConverter)
extern void RegisterImageConverterFF_Man();
extern void RegisterImageConverterIPP_Man();
void ImageConverter_RegisterAll()
{
RegisterImageConverterFF_Man();
#if QTAV_HAVE(IPP)
RegisterImageConverterIPP_Man();
#endif //QTAV_HAVE(IPP)
}
ImageConverter::ImageConverter()
{
}
ImageConverter::ImageConverter(ImageConverterPrivate& d)
: DPTR_INIT(&d)
{
}
ImageConverter::~ImageConverter()
{
}
QByteArray ImageConverter::outData() const
{
return d_func().data_out;
}
bool ImageConverter::check() const
{
DPTR_D(const ImageConverter);
return d.w_in > 0 && d.w_out > 0 && d.h_in > 0 && d.h_out > 0
&& d.fmt_in != QTAV_PIX_FMT_C(NONE) && d.fmt_out != QTAV_PIX_FMT_C(NONE);
}
void ImageConverter::setInSize(int width, int height)
{
DPTR_D(ImageConverter);
if (d.w_in == width && d.h_in == height)
return;
d.w_in = width;
d.h_in = height;
prepareData();
}
void ImageConverter::setOutSize(int width, int height)
{
DPTR_D(ImageConverter);
if (d.w_out == width && d.h_out == height)
return;
d.w_out = width;
d.h_out = height;
prepareData();
}
void ImageConverter::setInFormat(const VideoFormat& format)
{
d_func().fmt_in = format.pixelFormatFFmpeg();
}
void ImageConverter::setInFormat(VideoFormat::PixelFormat format)
{
d_func().fmt_in = VideoFormat::pixelFormatToFFmpeg(format);
}
void ImageConverter::setInFormat(int format)
{
d_func().fmt_in = format;
}
void ImageConverter::setOutFormat(const VideoFormat& format)
{
setOutFormat(format.pixelFormatFFmpeg());
}
void ImageConverter::setOutFormat(VideoFormat::PixelFormat format)
{
setOutFormat(VideoFormat::pixelFormatToFFmpeg(format));
}
void ImageConverter::setOutFormat(int format)
{
DPTR_D(ImageConverter);
if (d.fmt_out == format)
return;
d.fmt_out = format;
prepareData();
}
void ImageConverter::setInterlaced(bool interlaced)
{
d_func().interlaced = interlaced;
}
bool ImageConverter::isInterlaced() const
{
return d_func().interlaced;
}
void ImageConverter::setBrightness(int value)
{
DPTR_D(ImageConverter);
if (d.brightness == value)
return;
d.brightness = value;
setupColorspaceDetails();
}
int ImageConverter::brightness() const
{
return d_func().brightness;
}
void ImageConverter::setContrast(int value)
{
DPTR_D(ImageConverter);
if (d.contrast == value)
return;
d.contrast = value;
setupColorspaceDetails();
}
int ImageConverter::contrast() const
{
return d_func().contrast;
}
void ImageConverter::setSaturation(int value)
{
DPTR_D(ImageConverter);
if (d.saturation == value)
return;
d.saturation = value;
setupColorspaceDetails();
}
int ImageConverter::saturation() const
{
return d_func().saturation;
}
QVector<quint8*> ImageConverter::outPlanes() const
{
DPTR_D(const ImageConverter);
QVector<quint8*> planes(4, 0); //TODO: only real plane count?
planes[0] = d.picture.data[0];
planes[1] = d.picture.data[1];
planes[2] = d.picture.data[2];
planes[3] = d.picture.data[3];
return planes;
}
QVector<int> ImageConverter::outLineSizes() const
{
DPTR_D(const ImageConverter);
QVector<int> lineSizes(4, 0);
lineSizes[0] = d.picture.linesize[0];
lineSizes[1] = d.picture.linesize[1];
lineSizes[2] = d.picture.linesize[2];
lineSizes[3] = d.picture.linesize[3];
return lineSizes;
}
bool ImageConverter::setupColorspaceDetails()
{
return true;
}
bool ImageConverter::prepareData()
{
DPTR_D(ImageConverter);
if (d.fmt_out == QTAV_PIX_FMT_C(NONE) || d.w_out <=0 || d.h_out <= 0)
return false;
int bytes = avpicture_get_size((AVPixelFormat)d.fmt_out, d.w_out, d.h_out);
//if (d.data_out.size() < bytes) {
d.data_out.resize(bytes);
//}
//picture的数据按PIX_FMT格式自动"关联"到 data
avpicture_fill(
&d.picture,
(uint8_t*)d.data_out.constData(),
(AVPixelFormat)d.fmt_out,
d.w_out,
d.h_out
);
return true;
}
} //namespace QtAV